transcendental-lisp/test/function/builtin/EXITTester.java
Mike Cifelli 04cb46e94d Store the base directory for an interpreted files
A bug was resolved where some functions were getting a null
ErrorManager.

A reset funtion was added to RuntimeEnvironment.

Resolves #15
2017-03-05 10:20:31 -05:00

60 lines
1.3 KiB
Java

package function.builtin;
import static org.junit.Assert.*;
import static testutil.TestUtilities.evaluateString;
import java.util.*;
import org.junit.*;
import environment.RuntimeEnvironment;
import function.ArgumentValidator.TooManyArgumentsException;
public class EXITTester {
private static final String TERMINATED = "terminated";
private RuntimeEnvironment environment;
private Set<String> indicatorSet;
public EXITTester() {
this.environment = RuntimeEnvironment.getInstance();
}
private void assertTerminated() {
assertTrue(indicatorSet.contains(TERMINATED));
}
private void assertNotTerminated() {
assertFalse(indicatorSet.contains(TERMINATED));
}
@Before
public void setUp() {
indicatorSet = new HashSet<>();
environment.reset();
environment.setTerminationFunction(() -> indicatorSet.add(TERMINATED));
}
@After
public void tearDown() {
environment.reset();
}
@Test
public void exitWorks() {
evaluateString("(exit)");
assertTerminated();
}
@Test
public void exitNotCalled_IndicatorSetIsClean() {
assertNotTerminated();
}
@Test(expected = TooManyArgumentsException.class)
public void exitWithTooManyArguments() {
evaluateString("(exit 1)");
}
}