transcendental-lisp/test/function/builtin/LOADTester.java

84 lines
2.5 KiB
Java
Raw Normal View History

package function.builtin;
2017-02-11 10:42:07 -05:00
import static org.junit.Assert.assertTrue;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import java.io.*;
import org.junit.*;
import environment.RuntimeEnvironment;
2017-02-11 10:42:07 -05:00
import error.ErrorManager;
import function.ArgumentValidator.*;
public class LOADTester {
private ByteArrayOutputStream outputStream;
2017-02-11 10:42:07 -05:00
private ByteArrayOutputStream errorOutputStream;
2017-02-11 10:42:07 -05:00
private void assertWarningMessagePrinted() {
assertTrue(outputStream.toByteArray().length > 0);
2017-02-11 10:42:07 -05:00
assertTrue(errorOutputStream.toByteArray().length == 0);
}
private void assertErrorMessagePrinted() {
assertTrue(errorOutputStream.toByteArray().length > 0);
assertTrue(outputStream.toByteArray().length == 0);
}
private void assertNothingPrinted() {
assertTrue(outputStream.toByteArray().length == 0);
2017-02-11 10:42:07 -05:00
assertTrue(outputStream.toByteArray().length == 0);
}
@Before
public void setUp() {
this.outputStream = new ByteArrayOutputStream();
2017-02-11 10:42:07 -05:00
this.errorOutputStream = new ByteArrayOutputStream();
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream));
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream));
RuntimeEnvironment.getInstance().setErrorManager(new ErrorManager());
}
@Test
public void loadGoodFile_ReturnsTAndPrintsNothing() {
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
2017-02-11 10:42:07 -05:00
assertT(evaluateString(input));
assertNothingPrinted();
}
2017-01-26 16:00:47 -05:00
@Test
public void loadBadFile_ReturnsNilAndPrintsError() {
String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")";
2017-02-11 10:42:07 -05:00
assertNil(evaluateString(input));
assertErrorMessagePrinted();
}
@Test
public void loadNonExistentFile_ReturnsNilAndPrintsError() {
String input = "(load \"doesNotExist.lisp\")";
2017-02-11 10:42:07 -05:00
assertNil(evaluateString(input));
assertWarningMessagePrinted();
}
@Test(expected = BadArgumentTypeException.class)
public void testLoadWithBadArgumentType() {
evaluateString("(load '1)");
}
@Test(expected = TooManyArgumentsException.class)
public void testLoadWithTooManyArguments() {
evaluateString("(load \"1\" \"2\")");
}
@Test(expected = TooFewArgumentsException.class)
public void testLoadWithTooFewArguments() {
evaluateString("(load)");
}
}