Use resource loader for test files
This commit is contained in:
parent
b67071a7f2
commit
74fba08555
2
pom.xml
2
pom.xml
|
@ -9,9 +9,7 @@
|
|||
<version>1.2.0</version>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<!--<sourceDirectory>src/main/kotlin</sourceDirectory>-->
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
<!--<testSourceDirectory>src/test/kotlin</testSourceDirectory>-->
|
||||
|
||||
<plugins>
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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<String> 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());
|
||||
|
|
Loading…
Reference in New Issue