2017-02-26 12:31:27 -05:00
|
|
|
package main;
|
|
|
|
|
2017-03-23 16:14:26 -04:00
|
|
|
import static java.text.MessageFormat.format;
|
|
|
|
import static main.LispMain.*;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
2017-02-26 12:31:27 -05:00
|
|
|
import org.junit.*;
|
2017-03-23 16:14:26 -04:00
|
|
|
import org.junit.contrib.java.lang.system.*;
|
|
|
|
|
|
|
|
import com.googlecode.lanterna.terminal.virtual.*;
|
|
|
|
|
|
|
|
import environment.RuntimeEnvironment;
|
|
|
|
import interpreter.LispInterpreterBuilderImpl;
|
|
|
|
import terminal.*;
|
2017-02-26 12:31:27 -05:00
|
|
|
|
2017-03-15 13:37:39 -04:00
|
|
|
public class MainTest {
|
2017-02-26 12:31:27 -05:00
|
|
|
|
2017-03-23 16:14:26 -04:00
|
|
|
LispMain main;
|
|
|
|
PipedOutputStream inputWriter;
|
|
|
|
PipedInputStream outputReader;
|
|
|
|
VirtualTerminal terminal;
|
|
|
|
RuntimeEnvironment environment;
|
|
|
|
|
|
|
|
public MainTest() {
|
|
|
|
this.environment = RuntimeEnvironment.getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public ExpectedSystemExit exit = ExpectedSystemExit.none();
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public SystemErrRule systemErrRule = new SystemErrRule().enableLog().mute();
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public SystemOutRule systemOutRule = new SystemOutRule().enableLog().mute();
|
|
|
|
|
2017-02-26 12:31:27 -05:00
|
|
|
@Before
|
2017-03-23 16:14:26 -04:00
|
|
|
public void setUp() throws Exception {
|
|
|
|
environment.reset();
|
|
|
|
TerminalConfiguration configuration = new TerminalConfiguration();
|
|
|
|
inputWriter = new PipedOutputStream();
|
|
|
|
outputReader = new PipedInputStream();
|
|
|
|
terminal = new DefaultVirtualTerminal();
|
|
|
|
configuration.setInputWriter(inputWriter);
|
|
|
|
configuration.setOutputReader(outputReader);
|
|
|
|
configuration.setTerminal(terminal);
|
|
|
|
main = new LispMain(new LispInterpreterBuilderImpl() {}, configuration);
|
|
|
|
}
|
2017-02-26 12:31:27 -05:00
|
|
|
|
|
|
|
@After
|
2017-03-23 16:14:26 -04:00
|
|
|
public void tearDown() throws Exception {
|
|
|
|
terminal.close();
|
|
|
|
environment.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void runWithBadFile() {
|
|
|
|
String expectedMessage = "[critical] test/main/test-files/bad.lisp (No such file or directory)";
|
|
|
|
|
|
|
|
exit.expectSystemExitWithStatus(1);
|
|
|
|
exit.checkAssertionAfterwards(() -> {
|
|
|
|
assertEquals(format("{0}{1}{2}\n", ANSI_PURPLE, expectedMessage, ANSI_RESET),
|
|
|
|
systemErrRule.getLogWithNormalizedLineSeparator());
|
|
|
|
assertEquals("", systemOutRule.getLogWithNormalizedLineSeparator());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
main.runWithFile("test/main/test-files/bad.lisp");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void runWithFile_PrintsDecoratedLastValueOnly() {
|
|
|
|
main.runWithFile("test/main/test-files/file.lisp");
|
|
|
|
assertEquals("", systemErrRule.getLogWithNormalizedLineSeparator());
|
|
|
|
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET),
|
|
|
|
systemOutRule.getLogWithNormalizedLineSeparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void runInteractive() {
|
|
|
|
VirtualTerminalInteractor t = new VirtualTerminalInteractor();
|
|
|
|
try {
|
|
|
|
t.start();
|
|
|
|
} finally {
|
|
|
|
t.stop();
|
|
|
|
}
|
|
|
|
}
|
2017-02-26 12:31:27 -05:00
|
|
|
|
|
|
|
}
|