Skip to content

Commit 3cc9b98

Browse files
committed
test that main does not output exceptions
1 parent d13d930 commit 3cc9b98

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

monticore-test/01.experiments/automaton/src/main/java/automata/AutomataTool.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@
2929
*/
3030
public class AutomataTool extends AutomataToolTOP {
3131

32-
/**
33-
* Main method of the Tool
34-
*
35-
* Arguments expected:
36-
* * input automaton file.
37-
* * the path to store the symbol table
38-
*
39-
* @param args
40-
*/
41-
public static void main(String[] args) {
42-
// delegate main to instantiatable method for better integration,
43-
// reuse, etc.
44-
new AutomataTool().run(args);
45-
}
46-
4732
/**
4833
* Run implements the main method of the Automata tool workflow:
4934
*
@@ -78,6 +63,10 @@ else if (cmd.hasOption("v")) {
7863
//do not continue when help is printed
7964
return;
8065
}
66+
//throw: simulate an internal exception occurring for testing main
67+
else if (cmd.hasOption("throw")) {
68+
throw new RuntimeException("This is a test exception thrown to test");
69+
}
8170

8271
Log.info("Automata DSL Tool", "AutomataTool");
8372

@@ -171,4 +160,11 @@ public void prettyPrint(ASTAutomaton ast, String file) {
171160
Log.println(pp.getResult());
172161
}
173162

163+
@Override
164+
public Options addAdditionalOptions(Options options) {
165+
options.addOption("throw",
166+
"used for simulating an interal exception"
167+
);
168+
return options;
169+
}
174170
}

monticore-test/01.experiments/automaton/src/test/java/AutomataToolTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ public void executeHierarchyPingPong() {
7676

7777
@Test
7878
public void testPrintVersion() {
79-
80-
8179
AutomataTool.main(new String[] {"-v"});
8280
MCAssertions.assertNoFindings();
8381
}
8482

83+
@Test
84+
void testMainDoesNotThrow() {
85+
AutomataTool.main(new String[] {"-throw"});
86+
MCAssertions.assertHasFindingsStartingWith("0xEEEEE");
87+
}
8588
}

0 commit comments

Comments
 (0)