From 40746c47e70054733ee4bd086efd2325ec48a74a Mon Sep 17 00:00:00 2001 From: Stephane Epardaud Date: Thu, 5 Sep 2013 13:27:07 +0200 Subject: [PATCH] metamodel: added test for things that throw for ceylon/ceylon.language#226 --- .../java/test/metamodel/runtime.ceylon | 33 +++++++++++++++++++ .../compiler/java/test/metamodel/types.ceylon | 17 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/src/com/redhat/ceylon/compiler/java/test/metamodel/runtime.ceylon b/test/src/com/redhat/ceylon/compiler/java/test/metamodel/runtime.ceylon index 2434db064..001438f56 100644 --- a/test/src/com/redhat/ceylon/compiler/java/test/metamodel/runtime.ceylon +++ b/test/src/com/redhat/ceylon/compiler/java/test/metamodel/runtime.ceylon @@ -62,6 +62,14 @@ void checkConstructors(){ value privateClassType = `PrivateClass`; value privateClassInstance = privateClassType(); assert(privateClassInstance.string == "d"); + + // constructor that throws + try { + `Throws`(true); + assert(false); + }catch(Exception x){ + assert(x.cause is MyException); + } } void checkMemberAttributes(){ @@ -130,6 +138,21 @@ void checkMemberAttributes(){ obj2Bound.set(3); assert(obj2Bound.get() == 3); assert(noParamsInstance.obj2 == 3); + + // getter that throws + Throws t = Throws(false); + try { + `Throws.getter`(t).get(); + assert(false); + }catch(Exception x){ + assert(x.cause is MyException); + } + try { + `Throws.getter`(t).set(1); + assert(false); + }catch(Exception x){ + assert(x.cause is MyException); + } } void checkMemberFunctions(){ @@ -162,6 +185,16 @@ void checkMemberFunctions(){ assert(f7(noParamsInstance)() == 'a'); assert(exists f8 = noParamsType.getMethod("getBoolean")); assert(f8(noParamsInstance)() == true); + + // method that throws + Throws t = Throws(false); + try { + `Throws.method`(t)(); + assert(false); + }catch(Exception x){ + assert(x.cause is MyException); + } + } void checkMemberTypes(){ diff --git a/test/src/com/redhat/ceylon/compiler/java/test/metamodel/types.ceylon b/test/src/com/redhat/ceylon/compiler/java/test/metamodel/types.ceylon index 549d009bf..32858f887 100644 --- a/test/src/com/redhat/ceylon/compiler/java/test/metamodel/types.ceylon +++ b/test/src/com/redhat/ceylon/compiler/java/test/metamodel/types.ceylon @@ -236,3 +236,20 @@ shared abstract class Modifiers(){ shared formal Boolean method(); shared actual default String string = "yup"; } + +shared class MyException() extends Exception("Hello!"){} + +shared class Throws(Boolean t){ + if(t){ + throw MyException(); + } + shared Integer getter { + throw MyException(); + } + assign getter { + throw MyException(); + } + shared Integer method() { + throw MyException(); + } +} \ No newline at end of file