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

61 lines
1.4 KiB
Java
Raw Normal View History

package function.builtin;
import static org.junit.Assert.*;
import static testutil.TestUtilities.evaluateString;
import java.util.*;
import org.junit.Test;
import environment.RuntimeEnvironment;
import function.ArgumentValidator.TooManyArgumentsException;
import testutil.SymbolAndFunctionCleaner;
public class EXITTest extends SymbolAndFunctionCleaner {
private static final String TERMINATED = "terminated";
private RuntimeEnvironment environment;
private Set<String> indicatorSet;
2017-03-15 13:37:39 -04:00
public EXITTest() {
this.environment = RuntimeEnvironment.getInstance();
}
private void assertTerminated() {
assertTrue(indicatorSet.contains(TERMINATED));
}
private void assertNotTerminated() {
assertFalse(indicatorSet.contains(TERMINATED));
}
@Override
public void additionalSetUp() {
indicatorSet = new HashSet<>();
environment.reset();
environment.setTerminationFunction(() -> indicatorSet.add(TERMINATED));
}
@Override
public void additionalTearDown() {
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)");
}
}