From 74fba08555b4117526b6c79222e32de44ccaacda Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sat, 17 Mar 2018 16:18:26 -0400 Subject: [PATCH] Use resource loader for test files --- pom.xml | 2 -- src/test/java/application/MainTest.java | 10 ++++++---- src/test/java/function/builtin/LOADTest.java | 14 +++++++++----- src/test/java/interpreter/LispInterpreterTest.java | 7 ++++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 4d60127..f32c555 100644 --- a/pom.xml +++ b/pom.xml @@ -9,9 +9,7 @@ 1.2.0 - src/main/java - src/test/java diff --git a/src/test/java/application/MainTest.java b/src/test/java/application/MainTest.java index 2d70b38..49a9770 100644 --- a/src/test/java/application/MainTest.java +++ b/src/test/java/application/MainTest.java @@ -26,6 +26,8 @@ import static org.junit.Assert.assertEquals; public class MainTest extends SymbolAndFunctionCleaner { + private static final String FILE = MainTest.class.getResource("file.lisp").getFile(); + private RuntimeEnvironment environment; private CountDownLatch latch; @@ -99,7 +101,7 @@ public class MainTest extends SymbolAndFunctionCleaner { @Test public void runWithBadFile() { - String expectedMessage = "[critical] src/test/resources/application/bad.lisp (No such file or directory)"; + String expectedMessage = "[critical] bad.lisp (No such file or directory)"; exit.expectSystemExitWithStatus(1); exit.checkAssertionAfterwards(() -> { @@ -107,12 +109,12 @@ public class MainTest extends SymbolAndFunctionCleaner { assertEquals("", getSystemOutLog()); }); - runInterpreterWithFile("src/test/resources/application/bad.lisp"); + runInterpreterWithFile("bad.lisp"); } @Test public void runWithFile_PrintsDecoratedLastValueOnly() { - runInterpreterWithFile("src/test/resources/application/file.lisp"); + runInterpreterWithFile(FILE); assertEquals("", getSystemErrLog()); assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog()); @@ -136,7 +138,7 @@ public class MainTest extends SymbolAndFunctionCleaner { @Test public void runMain() { - LispMain.main(new String[] { "src/test/resources/application/file.lisp" }); + LispMain.main(new String[] { FILE }); assertEquals("", getSystemErrLog()); assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog()); diff --git a/src/test/java/function/builtin/LOADTest.java b/src/test/java/function/builtin/LOADTest.java index fb21610..ae67a2b 100644 --- a/src/test/java/function/builtin/LOADTest.java +++ b/src/test/java/function/builtin/LOADTest.java @@ -70,7 +70,8 @@ public class LOADTest extends SymbolAndFunctionCleaner { @Test public void loadGoodFile_ReturnsTAndPrintsNothing() { - String input = "(load \"src/test/resources/function/builtin/load-good.lisp\")"; + String file = LOADTest.class.getResource("load-good.lisp").getFile(); + String input = "(load \"" + file + "\")"; assertT(evaluateString(input)); assertNothingPrinted(); @@ -78,7 +79,8 @@ public class LOADTest extends SymbolAndFunctionCleaner { @Test public void loadBadFile_ReturnsNilAndPrintsError() { - String input = "(load \"src/test/resources/function/builtin/load-bad.lisp\")"; + String file = LOADTest.class.getResource("load-bad.lisp").getFile(); + String input = "(load \"" + file + "\")"; assertNil(evaluateString(input)); assertErrorMessagePrinted(); @@ -94,7 +96,8 @@ public class LOADTest extends SymbolAndFunctionCleaner { @Test public void nestedLoadsInTheSameDirectory() { - String input = "(load \"src/test/resources/function/builtin/nested/nested.lisp\")"; + String file = LOADTest.class.getResource("nested/nested.lisp").getFile(); + String input = "(load \"" + file + "\")"; assertT(evaluateString(input)); assertNothingPrinted(); @@ -102,7 +105,8 @@ public class LOADTest extends SymbolAndFunctionCleaner { @Test public void nestedLoadsInDifferentDirectories() { - String input = "(load \"src/test/resources/function/builtin/nested/one/load-one.lisp\")"; + String file = LOADTest.class.getResource("nested/one/load-one.lisp").getFile(); + String input = "(load \"" + file + "\")"; assertT(evaluateString(input)); assertNothingPrinted(); @@ -125,7 +129,7 @@ public class LOADTest extends SymbolAndFunctionCleaner { @Test public void loadUsesRuntimePath() { - environment.setPath("src/test/resources/function/builtin/nested/one/"); + environment.setPath(LOADTest.class.getResource("nested/one/").getPath()); String input = "(load \"load-one.lisp\")"; assertT(evaluateString(input)); diff --git a/src/test/java/interpreter/LispInterpreterTest.java b/src/test/java/interpreter/LispInterpreterTest.java index b6987ee..0619a27 100644 --- a/src/test/java/interpreter/LispInterpreterTest.java +++ b/src/test/java/interpreter/LispInterpreterTest.java @@ -23,6 +23,7 @@ import static testutil.TestUtilities.createInputStreamFromString; public class LispInterpreterTest { private static final String TERMINATED = "terminated"; + private static final String FILE = LispInterpreterTest.class.getResource("file.lisp").getFile(); private Set indicatorSet; private ByteArrayOutputStream outputStream; @@ -95,7 +96,7 @@ public class LispInterpreterTest { @Test public void buildFileBasedInterpreter() { setCommonFeatures(); - builder.useFile("src/test/interpreter/test-files/file.lisp"); + builder.useFile(FILE); LispInterpreter interpreter = builder.build(); assertTrue(interpreter instanceof FileLispInterpreter); @@ -128,7 +129,7 @@ public class LispInterpreterTest { @Test public void attemptToBuildInterpreterOnBadFile() { setCommonFeatures(); - builder.useFile("src/test/interpreter/test-files/does-not-exist.lisp"); + builder.useFile("does-not-exist.lisp"); builder.build(); assertErrorMessageWritten(); @@ -165,7 +166,7 @@ public class LispInterpreterTest { @Test public void fileBasedInterpreterWorks_PrintsLastValueOnly() { setCommonFeatures(); - builder.useFile("src/test/resources/interpreter/file.lisp"); + builder.useFile(FILE); builder.build().interpret(); assertEquals("PICKLE\n\n", outputStream.toString());