From ee5621238c13b0b01a59b84f317cd22b960065b4 Mon Sep 17 00:00:00 2001 From: Paul Hoadley Date: Sun, 31 Mar 2024 21:11:02 +1030 Subject: [PATCH] #11 Hooks up "interactive" tests. --- src/test/java/net/logicsquad/pal/PALTest.java | 35 +++++++++++++++++-- src/test/resources/interactive/SIGe.ref | 2 +- src/test/resources/interactive/SIGf.ref | 2 +- src/test/resources/interactive/SIGg.ref | 2 +- src/test/resources/interactive/SIGh.ref | 2 +- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/logicsquad/pal/PALTest.java b/src/test/java/net/logicsquad/pal/PALTest.java index c2efd89..dc1894b 100644 --- a/src/test/java/net/logicsquad/pal/PALTest.java +++ b/src/test/java/net/logicsquad/pal/PALTest.java @@ -18,7 +18,7 @@ * @author paulh */ public class PALTest { - private static final List INPUTS = List.of( + private static final List NON_INTERACTIVE_INPUTS = List.of( "BASICS", "BOOLS", "INC", @@ -43,9 +43,21 @@ public class PALTest { "SIGd", "STRINGPARSE"); + private static final List 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)); @@ -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; + } } diff --git a/src/test/resources/interactive/SIGe.ref b/src/test/resources/interactive/SIGe.ref index f3ff4a0..6bace3d 100644 --- a/src/test/resources/interactive/SIGe.ref +++ b/src/test/resources/interactive/SIGe.ref @@ -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: diff --git a/src/test/resources/interactive/SIGf.ref b/src/test/resources/interactive/SIGf.ref index fbbceea..ea7f5e6 100644 --- a/src/test/resources/interactive/SIGf.ref +++ b/src/test/resources/interactive/SIGf.ref @@ -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: diff --git a/src/test/resources/interactive/SIGg.ref b/src/test/resources/interactive/SIGg.ref index 4f23ead..25cdea2 100644 --- a/src/test/resources/interactive/SIGg.ref +++ b/src/test/resources/interactive/SIGg.ref @@ -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: diff --git a/src/test/resources/interactive/SIGh.ref b/src/test/resources/interactive/SIGh.ref index f08e622..f3a1816 100644 --- a/src/test/resources/interactive/SIGh.ref +++ b/src/test/resources/interactive/SIGh.ref @@ -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: