Skip to content

Commit

Permalink
#11 Hooks up "interactive" tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhoadley committed Mar 31, 2024
1 parent 26b8398 commit ee56212
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
35 changes: 33 additions & 2 deletions src/test/java/net/logicsquad/pal/PALTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author paulh
*/
public class PALTest {
private static final List<String> INPUTS = List.of(
private static final List<String> NON_INTERACTIVE_INPUTS = List.of(
"BASICS",
"BOOLS",
"INC",
Expand All @@ -43,9 +43,21 @@ public class PALTest {
"SIGd",
"STRINGPARSE");

private static final List<String> INTERACTIVE_INPUTS = List.of(
"FACTITER",
"FACTREC",
"LAB",
"OPR-19",
"OPR-22",
"OPR-23",
"SIGe",
"SIGf",
"SIGg",
"SIGh");

@Test
public void nonInteractiveTests() throws IOException {
for (String input : INPUTS) {
for (String input : NON_INTERACTIVE_INPUTS) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
System.setErr(new PrintStream(baos));
Expand All @@ -59,4 +71,23 @@ public void nonInteractiveTests() throws IOException {
}
return;
}

@Test
public void interactiveTests() throws IOException {
for (String input : INTERACTIVE_INPUTS) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
System.setErr(new PrintStream(baos));
InputStream response = PALTest.class.getResourceAsStream("/interactive/" + input + ".in");
System.setIn(response);
InputStream is = PALTest.class.getResourceAsStream("/interactive/" + input);
PAL pal = new PAL(is);
pal.execute();
baos.flush();
String output = new String(baos.toByteArray());
String expected = new String(PALTest.class.getResourceAsStream("/interactive/" + input + ".ref").readAllBytes(), StandardCharsets.UTF_8);
assertEquals(expected, output);
}
return;
}
}
2 changes: 1 addition & 1 deletion src/test/resources/interactive/SIGe.ref
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pTwo exh: exception 0.
Main exh: exception 0.

Runtime Error:
test/interactive/SIGe:146:Exception #0 never handled!
CODE:146:Exception #0 never handled!
SIG 0 0

Stack dump:
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/interactive/SIGf.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Enter the exception type.

Runtime Error:
test/interactive/SIGf:18:A Program Abort signal was raised.
CODE:18:A Program Abort signal was raised.
SIG 0 1

Stack dump:
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/interactive/SIGg.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pTwo exh: exception 8.
Main exh: exception 8.

Runtime Error:
test/interactive/SIGg:167:Exception #8 never handled!
CODE:167:Exception #8 never handled!
SIG 0 0

Stack dump:
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/interactive/SIGh.ref
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Runtime Error:
test/interactive/SIGh:4:Exception #4 never handled!
CODE:4:Exception #4 never handled!
SIG 0 0

Stack dump:
Expand Down

0 comments on commit ee56212

Please sign in to comment.