Skip to content

Commit 2643240

Browse files
committed
[cppia] Test for method on exception throwing expr
This doesn't cover the CallHaxe case, however, that only happens when the same class exists in the host and client (i.e. when export_classes.info wasn't used), which makes it difficult to test with our setup.
1 parent a48d222 commit 2643240

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

test/cppia/Client.hx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ class Client
189189
default:
190190
}
191191

192+
switch LocalFunctionExceptions.testObjMethodOnReturn() {
193+
case Error(message):
194+
Common.status = 'Failed test for running object method on returned value: ' + message;
195+
return;
196+
default:
197+
}
198+
199+
switch LocalFunctionExceptions.testClassMethodOnReturn() {
200+
case Error(message):
201+
Common.status = 'Failed test for running class method on returned value: ' + message;
202+
return;
203+
default:
204+
}
205+
192206
final extending = new ClientExtendedExtendedRoot();
193207

194208
extending.addValue();

test/cppia/LocalFunctionExceptions.hx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ enum Status {
33
Error(message:String);
44
}
55

6+
class DummyClass {
7+
public function run() {}
8+
}
9+
610
class LocalFunctionExceptions {
7-
static function staticFunction() {
11+
static function staticFunction():Dynamic {
812
throw 'Thrown from static';
913
}
1014

@@ -65,4 +69,42 @@ class LocalFunctionExceptions {
6569

6670
return Error("No exception caught");
6771
}
72+
73+
public static function testObjMethodOnReturn():Status {
74+
function localFunction() {
75+
(staticFunction() : Dynamic).run();
76+
throw 'Thrown from local';
77+
}
78+
79+
try {
80+
localFunction();
81+
} catch (e:String) {
82+
if (e == 'Thrown from static') {
83+
return Ok;
84+
} else {
85+
return Error("Incorrect exception caught from local function call: " + e);
86+
}
87+
}
88+
89+
return Error("No exception caught");
90+
}
91+
92+
public static function testClassMethodOnReturn():Status {
93+
function localFunction() {
94+
(staticFunction() : DummyClass).run();
95+
throw 'Thrown from local';
96+
}
97+
98+
try {
99+
localFunction();
100+
} catch (e:String) {
101+
if (e == 'Thrown from static') {
102+
return Ok;
103+
} else {
104+
return Error("Incorrect exception caught from local function call: " + e);
105+
}
106+
}
107+
108+
return Error("No exception caught");
109+
}
68110
}

0 commit comments

Comments
 (0)