Skip to content

Commit 90df70e

Browse files
committed
PrettyPrinterTester - catch Exceptions
1 parent 86d99b5 commit 90df70e

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

monticore-runtime/src/testFixtures/java/de/monticore/runtime/junit/PrettyPrinterTester.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,23 @@ public abstract class PrettyPrinterTester {
3131
* {@code ast -> MyMill.prettyPrint(ast, true)}
3232
* @param additionalCheck additional check on the pretty printed String
3333
* @param <N> the type of the ASTNode after parsing
34-
* @throws IOException thrown by the parser
3534
*/
3635
public static <N extends ASTNode> void testPrettyPrinter(
3736
String model,
3837
MCConcreteParser parser,
3938
ParseFunction<N> parseFunc,
4039
Function<N, String> prettyPrintFunc,
4140
Predicate<String> additionalCheck
42-
) throws IOException {
41+
) {
4342
// parse the model
44-
Optional<N> astOpt = parseFunc.apply(model);
43+
Optional<N> astOpt;
44+
try {
45+
astOpt = parseFunc.apply(model);
46+
}
47+
catch (IOException e) {
48+
Assertions.fail("Failed to parse input, exception occurred", e);
49+
return;
50+
}
4551
MCAssertions.assertNoFindings();
4652
assertTrue(astOpt.isPresent(), "Failed to parse input");
4753
Assertions.assertFalse(parser.hasErrors(), "Parser has Errors");
@@ -50,7 +56,17 @@ public static <N extends ASTNode> void testPrettyPrinter(
5056
String prettyPrinted = prettyPrintFunc.apply(ast);
5157
MCAssertions.assertNoFindings();
5258
// parse the pretty printed model
53-
Optional<N> prettyPrintedAstOpt = parseFunc.apply(prettyPrinted);
59+
Optional<N> prettyPrintedAstOpt;
60+
try {
61+
prettyPrintedAstOpt = parseFunc.apply(prettyPrinted);
62+
}
63+
catch (IOException e) {
64+
Assertions.fail(
65+
"Failed to parse pretty printed model"
66+
+ ", exception occurred", e
67+
);
68+
return;
69+
}
5470
MCAssertions.assertNoFindings();
5571
Assertions.assertFalse(parser.hasErrors());
5672
assertTrue(prettyPrintedAstOpt.isPresent());
@@ -77,14 +93,13 @@ public static <N extends ASTNode> void testPrettyPrinter(
7793
* @param prettyPrintFunc the actual pretty printing operation, e.g.,
7894
* {@code ast -> MyMill.prettyPrint(ast, true)}
7995
* @param <N> the type of the ASTNode after parsing
80-
* @throws IOException
8196
*/
8297
public static <N extends ASTNode> void testPrettyPrinter(
8398
String model,
8499
MCConcreteParser parser,
85100
ParseFunction<N> parseFunc,
86101
Function<N, String> prettyPrintFunc
87-
) throws IOException {
102+
) {
88103
testPrettyPrinter(model, parser, parseFunc, prettyPrintFunc, m -> true);
89104
}
90105

0 commit comments

Comments
 (0)