|
@@ -1,4 +1,4 @@
|
|
|
-package unit;
|
|
|
+package unit;
|
|
|
|
|
|
import haxe.Exception;
|
|
|
import haxe.exceptions.ArgumentException;
|
|
@@ -235,17 +235,16 @@ class TestExceptions extends Test {
|
|
|
public function testExceptionStack() {
|
|
|
var data = [
|
|
|
'_without_ throws' => stacksWithoutThrowLevel1(),
|
|
|
- '_with_ throws' => stacksWithThrowLevel1()
|
|
|
+ '_with_ throws' => stacksWithThrowLevel1(),
|
|
|
+ #if (eval || hl || neko)
|
|
|
+ 'auto wrapped' => stacksAutoWrappedLevel1()
|
|
|
+ #end
|
|
|
];
|
|
|
for(label => stacks in data) {
|
|
|
Assert.isTrue(stacks.length > 1, '$label: wrong stacks.length');
|
|
|
var expected = null;
|
|
|
var lineShift = 0;
|
|
|
for(s in stacks) {
|
|
|
- // TODO: fix hl vs other targets difference with callstacks
|
|
|
- // See https://github.com/HaxeFoundation/haxe/issues/10926
|
|
|
- #if hl @:privateAccess s.asArray().shift(); #end
|
|
|
-
|
|
|
if(expected == null) {
|
|
|
expected = stackItemData(s[0]);
|
|
|
} else {
|
|
@@ -295,6 +294,24 @@ class TestExceptions extends Test {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ #if (eval || hl || neko)
|
|
|
+ function stacksAutoWrappedLevel1() {
|
|
|
+ return stacksAutoWrappedLevel2();
|
|
|
+ }
|
|
|
+
|
|
|
+ function stacksAutoWrappedLevel2():Array<CallStack> {
|
|
|
+ @:pure(false) function wrapNativeError(_) return [];
|
|
|
+
|
|
|
+ var result:Array<CallStack> = [];
|
|
|
+ // It's critical for `testExceptionStack` test to keep the following lines
|
|
|
+ // order with no additional code in between.
|
|
|
+ result.push(try throw new Exception('') catch(e:Exception) e.stack);
|
|
|
+ result.push(try throw "" catch(e:Exception) e.stack);
|
|
|
+ result.push(try wrapNativeError((null:String).length) catch(e:Exception) e.stack);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ #end
|
|
|
+
|
|
|
function stackItemData(item:StackItem):ItemData {
|
|
|
var result:ItemData = {};
|
|
|
switch item {
|
|
@@ -321,6 +338,16 @@ class TestExceptions extends Test {
|
|
|
eq('haxe.Exception', HelperMacros.typeString(try throw new Exception('') catch(e) e));
|
|
|
}
|
|
|
|
|
|
+ function testCatchValueException() {
|
|
|
+ try {
|
|
|
+ throw "";
|
|
|
+ } catch(e:ValueException) {
|
|
|
+ Assert.pass();
|
|
|
+ } catch(e) {
|
|
|
+ Assert.fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function testNotImplemented() {
|
|
|
try {
|
|
|
futureFeature();
|
|
@@ -374,4 +401,4 @@ class TestExceptions extends Test {
|
|
|
}
|
|
|
}
|
|
|
#end
|
|
|
-}
|
|
|
+}
|