Skip to content

Commit 6f13cc5

Browse files
Add regression test for --assume-no-throw-exceptions
This tests the option behaves as desired.
1 parent 2ac5299 commit 6f13cc5

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class MyException extends Exception {}
2+
3+
public class Test {
4+
public static int mayThrow(String branch) throws Throwable {
5+
if (branch == null) {
6+
return -1;
7+
}
8+
if (branch.startsWith("null pointer exception")) {
9+
throw new NullPointerException();
10+
} else if (branch.startsWith("custom exception")) {
11+
throw new MyException();
12+
} else if (branch.startsWith("throwable")) {
13+
throw new Throwable();
14+
} else if (branch.startsWith("return 2")) {
15+
return 2;
16+
} else {
17+
return 1;
18+
}
19+
}
20+
21+
public static void check(String branch) {
22+
try {
23+
int i = mayThrow(branch);
24+
if (i == 2)
25+
assert false;
26+
if (i == 1)
27+
assert false;
28+
} catch (MyException e) {
29+
assert false;
30+
} catch (NullPointerException e) {
31+
assert false;
32+
} catch (Throwable e) {
33+
assert false;
34+
}
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
Test.class
3+
--function Test.check
4+
line 26 assertion at file Test.java line 26 .*: FAILURE
5+
line 28 assertion at file Test.java line 28 .*: FAILURE
6+
line 30 assertion at file Test.java line 30 .*: FAILURE
7+
line 32 assertion at file Test.java line 32 .*: FAILURE
8+
line 34 assertion at file Test.java line 34 .*: FAILURE
9+
--
10+
--
11+
Checks that we get the expected behaviour when --assume-no-exceptions-thrown is
12+
not used. This is to make sure that test.desc is actually testing what we wanted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
Test.class
3+
--function Test.check --assume-no-exceptions-thrown
4+
line 10 assertion at file Test.java line 10 .*: FAILURE
5+
line 12 assertion at file Test.java line 12 .*: FAILURE
6+
line 14 assertion at file Test.java line 14 .*: FAILURE
7+
line 26 assertion at file Test.java line 26 .*: FAILURE
8+
line 28 assertion at file Test.java line 28 .*: FAILURE
9+
line 30 assertion at file Test.java line 30 .*: SUCCESS
10+
line 32 assertion at file Test.java line 32 .*: SUCCESS
11+
line 34 assertion at file Test.java line 34 .*: SUCCESS
12+
--
13+
--
14+
Checks that the `throw` instructions have been replaced by assertions, which
15+
are failing here because they are reachable, and assumptions which prevent
16+
the last three assertions from failing.

0 commit comments

Comments
 (0)