Skip to content
Draft
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
16 changes: 14 additions & 2 deletions monticore-generator/src/main/resources/_cli/Main.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<#-- (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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das Ganze führt jetzt zu dem Unterschied, dass Errors in der Ausführung mit Exit Code 0 (aka "alles gut") beendet werden.
Wenn wir den Change schon machen -> Rückgabewert zu int Ändern und fail=1/okay=0 zurückgeben?

Copy link
Contributor Author

@SE-FDr SE-FDr Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wie möchtest du den Rückgabewert von main ändern?
Ich würde System.exit eher vermeiden wollen, es sei denn, wir entfernen (lese: passen an) jeden Test, der zurzeit direkt die main Methode testet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in MC Weekly:
Add System.exit, change all the tests that call main to call run instead.

@luepges our gradle plugins should be fine?

);
}
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