/
exception.qtest
executable file
·64 lines (55 loc) · 1.54 KB
/
exception.qtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires ../../../../qlib/QUnit.qm
%exec-class ExceptionTest
class ExceptionTest inherits QUnit::Test {
private {
hash<ExceptionInfo> ex;
}
constructor() : QUnit::Test("Exception test", "1.0") {
addTestCase("Test simple try/catch block", \testSimpleTryCatch());
addTestCase("Test rethrow", \testRethrow());
addTestCase("misc tests", \miscTests());
set_return_value(main());
}
testSimpleTryCatch() {
try {
throw "testing", "123", "test";
} catch (hash<ExceptionInfo> ex1) {
ex = ex1;
}
assertEq("testing", ex.err);
assertEq("123", ex.desc);
assertEq("test", ex.arg);
assertEq("Qore", ex.lang);
}
testRethrow() {
try {
try {
throw "TEST-ERROR", "this is a test";
} catch () {
rethrow;
}
} catch (hash<ExceptionInfo> ex1) {
ex = ex1;
}
assertEq("TEST-ERROR", ex.err);
assertEq("this is a test", ex.desc);
assertEq("User", ex.type);
assertEq("Qore", ex.lang);
}
miscTests() {
Program p(PO_NEW_STYLE);
assertThrows("PARSE-EXCEPTION", \p.parse(), ("try {} catch (Exception e) {}", ""));
int a = 1;
try {
throw a;
} catch (hash<ExceptionInfo> ex) {
assertEq(1, ex.err);
}
}
}