forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestInteractiveRequestAbort.java
More file actions
45 lines (35 loc) · 1.2 KB
/
Copy pathTestInteractiveRequestAbort.java
File metadata and controls
45 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package php.java.test;
import java.io.File;
import java.io.FileWriter;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import junit.framework.TestCase;
import php.java.bridge.Request.AbortException;
public class TestInteractiveRequestAbort extends TestCase {
public TestInteractiveRequestAbort(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void test() throws Exception {
String devNull = new File("/dev/null").exists()? "/dev/null" : "devNull";
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("php-interactive");
e.getContext().setErrorWriter(new FileWriter(new File(devNull)));
e.getContext().setWriter(new FileWriter(new File(devNull)));
try {
e.eval("function toString() {return 'hello'; }; echo java_closure(); echo new JavaException('java.lang.Exception', 'hello'); echo JavaException('foo')");
} catch (ScriptException ex) {
Throwable orig = ex.getCause();
if (orig instanceof AbortException) {
return;
}
}
fail("test failed");
}
}