Add unit test for LOAD

This commit is contained in:
Mike Cifelli 2017-03-05 10:41:49 -05:00
parent 04cb46e94d
commit 8a719c8e44
2 changed files with 11 additions and 3 deletions

View File

@ -66,7 +66,7 @@ public class LOAD extends LispFunction {
try { try {
parser = new LispParser(new FileInputStream(fileName), fileName); parser = new LispParser(new FileInputStream(fileName), fileName);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
this.environment.getErrorManager().handle(new CouldNotLoadFileWarning(fileName)); environment.getErrorManager().handle(new CouldNotLoadFileWarning(fileName));
} }
return parser; return parser;
@ -89,7 +89,7 @@ public class LOAD extends LispFunction {
try { try {
eval(parser.getNextSExpression()); eval(parser.getNextSExpression());
} catch (LispException e) { } catch (LispException e) {
this.environment.getErrorManager().handle(e); environment.getErrorManager().handle(e);
return false; return false;
} }
} }

View File

@ -57,6 +57,14 @@ public class LOADTester {
environment.reset(); environment.reset();
} }
@Test
public void loadEmptyFileName_ReturnsNilAndPrintsWarning() {
String input = "(load \"\")";
assertNil(evaluateString(input));
assertWarningMessagePrinted();
}
@Test @Test
public void loadGoodFile_ReturnsTAndPrintsNothing() { public void loadGoodFile_ReturnsTAndPrintsNothing() {
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")"; String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
@ -74,7 +82,7 @@ public class LOADTester {
} }
@Test @Test
public void loadNonExistentFile_ReturnsNilAndPrintsError() { public void loadNonExistentFile_ReturnsNilAndPrintsWarning() {
String input = "(load \"doesNotExist.lisp\")"; String input = "(load \"doesNotExist.lisp\")";
assertNil(evaluateString(input)); assertNil(evaluateString(input));