49 lines
1.1 KiB
Java
49 lines
1.1 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 Set<String> indicatorSet;
|
|
|
|
private void assertTerminated() {
|
|
assertTrue(indicatorSet.contains(TERMINATED));
|
|
}
|
|
|
|
private void assertNotTerminated() {
|
|
assertFalse(indicatorSet.contains(TERMINATED));
|
|
}
|
|
|
|
@Before
|
|
public void setUp() {
|
|
indicatorSet = new HashSet<>();
|
|
RuntimeEnvironment.getInstance().setTerminationFunction(() -> indicatorSet.add(TERMINATED));
|
|
}
|
|
|
|
@Test
|
|
public void exitWorks() {
|
|
evaluateString("(exit)");
|
|
assertTerminated();
|
|
}
|
|
|
|
@Test
|
|
public void exitNotCalled_IndicatorSetIsClean() {
|
|
assertNotTerminated();
|
|
}
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
public void exitWithTooManyArguments() {
|
|
evaluateString("(exit 1)");
|
|
}
|
|
|
|
}
|