summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java')
-rw-r--r--junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java b/junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java
new file mode 100644
index 0000000..1460119
--- /dev/null
+++ b/junit4/src/test/java/org/junit/tests/running/core/SystemExitTest.java
@@ -0,0 +1,30 @@
+package org.junit.tests.running.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.junit.Test;
+
+// Make sure System.exit works as expected. We've had problems with this on some platforms.
+public class SystemExitTest {
+
+ private static final int EXIT_CODE= 5;
+
+ static public class Exit {
+ public static void main(String[] args) {
+ System.exit(EXIT_CODE);
+ }
+ }
+
+ @Test public void failureCausesExitCodeOf1() throws Exception {
+ String java= System.getProperty("java.home")+File.separator+"bin"+File.separator+"java";
+ String classPath= getClass().getClassLoader().getResource(".").getFile() + File.pathSeparator + System.getProperty("java.class.path");
+ String [] cmd= { java, "-cp", classPath, getClass().getName() + "$Exit"};
+ Process process= Runtime.getRuntime().exec(cmd);
+ InputStream input= process.getInputStream();
+ while((input.read()) != -1);
+ assertEquals(EXIT_CODE, process.waitFor());
+ }
+}