Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions monticore-generator/src/main/resources/_cli/Main.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<#-- (c) https://github.com/MontiCore/monticore -->
${tc.signature("grammarname")}

${grammarname}Tool tool = new ${grammarname}Tool();
tool.run(args);
try {
${grammarname}Tool tool = new ${grammarname}Tool();
tool.run(args);
}
catch (Exception exception) {
// ensure a sane exit
Log.ensureInitialization();
Log.error("0xEEEEE an internal error occurred"
+ " during the execution of the ${grammarname}Tool."
+ System.lineSeparator() + "This error is unexpected"
+ " and does not indicate an issue with any provided models.",
exception
);
System.exit(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@
*/
public class AutomataTool extends AutomataToolTOP {

/**
* Main method of the Tool
*
* Arguments expected:
* * input automaton file.
* * the path to store the symbol table
*
* @param args
*/
public static void main(String[] args) {
// delegate main to instantiatable method for better integration,
// reuse, etc.
new AutomataTool().run(args);
}

/**
* Run implements the main method of the Automata tool workflow:
*
Expand Down Expand Up @@ -78,6 +63,10 @@ else if (cmd.hasOption("v")) {
//do not continue when help is printed
return;
}
//throw: simulate an internal exception occurring for testing main
else if (cmd.hasOption("throw")) {
throw new RuntimeException("This is a test exception thrown to test");
}

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

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

@Override
public Options addAdditionalOptions(Options options) {
options.addOption("throw",
"used for simulating an interal exception"
);
return options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ public void executeHierarchyPingPong() {

@Test
public void testPrintVersion() {


AutomataTool.main(new String[] {"-v"});
MCAssertions.assertNoFindings();
}

@Test
void testMainDoesNotThrow() {
AutomataTool.main(new String[] {"-throw"});
MCAssertions.assertHasFindingsStartingWith("0xEEEEE");
}
}
Loading