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>
|
<version>1.2.0</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
|
||||||
<!--<sourceDirectory>src/main/kotlin</sourceDirectory>-->
|
<!--<sourceDirectory>src/main/kotlin</sourceDirectory>-->
|
||||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
|
||||||
<!--<testSourceDirectory>src/test/kotlin</testSourceDirectory>-->
|
<!--<testSourceDirectory>src/test/kotlin</testSourceDirectory>-->
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -26,6 +26,8 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class MainTest extends SymbolAndFunctionCleaner {
|
public class MainTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
|
private static final String FILE = MainTest.class.getResource("file.lisp").getFile();
|
||||||
|
|
||||||
private RuntimeEnvironment environment;
|
private RuntimeEnvironment environment;
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
|
||||||
|
@ -99,7 +101,7 @@ public class MainTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runWithBadFile() {
|
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.expectSystemExitWithStatus(1);
|
||||||
exit.checkAssertionAfterwards(() -> {
|
exit.checkAssertionAfterwards(() -> {
|
||||||
|
@ -107,12 +109,12 @@ public class MainTest extends SymbolAndFunctionCleaner {
|
||||||
assertEquals("", getSystemOutLog());
|
assertEquals("", getSystemOutLog());
|
||||||
});
|
});
|
||||||
|
|
||||||
runInterpreterWithFile("src/test/resources/application/bad.lisp");
|
runInterpreterWithFile("bad.lisp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runWithFile_PrintsDecoratedLastValueOnly() {
|
public void runWithFile_PrintsDecoratedLastValueOnly() {
|
||||||
runInterpreterWithFile("src/test/resources/application/file.lisp");
|
runInterpreterWithFile(FILE);
|
||||||
|
|
||||||
assertEquals("", getSystemErrLog());
|
assertEquals("", getSystemErrLog());
|
||||||
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
|
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
|
||||||
|
@ -136,7 +138,7 @@ public class MainTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runMain() {
|
public void runMain() {
|
||||||
LispMain.main(new String[] { "src/test/resources/application/file.lisp" });
|
LispMain.main(new String[] { FILE });
|
||||||
|
|
||||||
assertEquals("", getSystemErrLog());
|
assertEquals("", getSystemErrLog());
|
||||||
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
|
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
|
||||||
|
|
|
@ -70,7 +70,8 @@ public class LOADTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadGoodFile_ReturnsTAndPrintsNothing() {
|
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));
|
assertT(evaluateString(input));
|
||||||
assertNothingPrinted();
|
assertNothingPrinted();
|
||||||
|
@ -78,7 +79,8 @@ public class LOADTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadBadFile_ReturnsNilAndPrintsError() {
|
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));
|
assertNil(evaluateString(input));
|
||||||
assertErrorMessagePrinted();
|
assertErrorMessagePrinted();
|
||||||
|
@ -94,7 +96,8 @@ public class LOADTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nestedLoadsInTheSameDirectory() {
|
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));
|
assertT(evaluateString(input));
|
||||||
assertNothingPrinted();
|
assertNothingPrinted();
|
||||||
|
@ -102,7 +105,8 @@ public class LOADTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nestedLoadsInDifferentDirectories() {
|
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));
|
assertT(evaluateString(input));
|
||||||
assertNothingPrinted();
|
assertNothingPrinted();
|
||||||
|
@ -125,7 +129,7 @@ public class LOADTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadUsesRuntimePath() {
|
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\")";
|
String input = "(load \"load-one.lisp\")";
|
||||||
|
|
||||||
assertT(evaluateString(input));
|
assertT(evaluateString(input));
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static testutil.TestUtilities.createInputStreamFromString;
|
||||||
public class LispInterpreterTest {
|
public class LispInterpreterTest {
|
||||||
|
|
||||||
private static final String TERMINATED = "terminated";
|
private static final String TERMINATED = "terminated";
|
||||||
|
private static final String FILE = LispInterpreterTest.class.getResource("file.lisp").getFile();
|
||||||
|
|
||||||
private Set<String> indicatorSet;
|
private Set<String> indicatorSet;
|
||||||
private ByteArrayOutputStream outputStream;
|
private ByteArrayOutputStream outputStream;
|
||||||
|
@ -95,7 +96,7 @@ public class LispInterpreterTest {
|
||||||
@Test
|
@Test
|
||||||
public void buildFileBasedInterpreter() {
|
public void buildFileBasedInterpreter() {
|
||||||
setCommonFeatures();
|
setCommonFeatures();
|
||||||
builder.useFile("src/test/interpreter/test-files/file.lisp");
|
builder.useFile(FILE);
|
||||||
LispInterpreter interpreter = builder.build();
|
LispInterpreter interpreter = builder.build();
|
||||||
|
|
||||||
assertTrue(interpreter instanceof FileLispInterpreter);
|
assertTrue(interpreter instanceof FileLispInterpreter);
|
||||||
|
@ -128,7 +129,7 @@ public class LispInterpreterTest {
|
||||||
@Test
|
@Test
|
||||||
public void attemptToBuildInterpreterOnBadFile() {
|
public void attemptToBuildInterpreterOnBadFile() {
|
||||||
setCommonFeatures();
|
setCommonFeatures();
|
||||||
builder.useFile("src/test/interpreter/test-files/does-not-exist.lisp");
|
builder.useFile("does-not-exist.lisp");
|
||||||
builder.build();
|
builder.build();
|
||||||
|
|
||||||
assertErrorMessageWritten();
|
assertErrorMessageWritten();
|
||||||
|
@ -165,7 +166,7 @@ public class LispInterpreterTest {
|
||||||
@Test
|
@Test
|
||||||
public void fileBasedInterpreterWorks_PrintsLastValueOnly() {
|
public void fileBasedInterpreterWorks_PrintsLastValueOnly() {
|
||||||
setCommonFeatures();
|
setCommonFeatures();
|
||||||
builder.useFile("src/test/resources/interpreter/file.lisp");
|
builder.useFile(FILE);
|
||||||
builder.build().interpret();
|
builder.build().interpret();
|
||||||
|
|
||||||
assertEquals("PICKLE\n\n", outputStream.toString());
|
assertEquals("PICKLE\n\n", outputStream.toString());
|
||||||
|
|
Loading…
Reference in New Issue