aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormnunez <none@none>2014-03-19 16:01:19 +0100
committermnunez <none@none>2014-03-19 16:01:19 +0100
commit3a5ab5918f1003e3ff24c62b9944283d80fd2b99 (patch)
tree1f61dfb06633f94922a3bc92365e4304affc80af /test
parent48da5a4e3f02011b8aca82ab6365494e3dfada74 (diff)
downloadnashorn-3a5ab5918f1003e3ff24c62b9944283d80fd2b99.tar.gz
8037779: NoPersistenceCachingTest fails with ant test
Reviewed-by: sundar, hannesw
Diffstat (limited to 'test')
-rw-r--r--test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java b/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java
index aefa828b..7b84f5a7 100644
--- a/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java
+++ b/test/src/jdk/nashorn/internal/runtime/NoPersistenceCachingTest.java
@@ -37,6 +37,8 @@ import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.SimpleScriptContext;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
/**
* @test
@@ -50,8 +52,8 @@ public class NoPersistenceCachingTest {
private ScriptContext context1, context2, context3;
private ByteArrayOutputStream stderr;
private PrintStream prevStderr;
- private final String script = "print('Hello')";
+ @BeforeTest
public void setupTest() {
stderr = new ByteArrayOutputStream();
prevStderr = System.err;
@@ -69,33 +71,33 @@ public class NoPersistenceCachingTest {
}
String[] options = new String[]{"--log=compiler:finest"};
engine = nashornFactory.getScriptEngine(options);
+ context1 = engine.getContext();
+ context2 = new SimpleScriptContext();
+ context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
+ context3 = new SimpleScriptContext();
+ context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
}
+ @AfterTest
public void setErrTest() {
System.setErr(prevStderr);
}
public void runTest(int numberOfContext, String expectedOutputPattern,
int expectedPatternOccurrence) {
- setupTest();
+
try {
switch (numberOfContext) {
case 2:
- context1 = engine.getContext();
- context2 = new SimpleScriptContext();
- context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
- engine.eval(script, context1);
- engine.eval(script, context2);
+ String scriptTwoContexts = "print('HelloTwoContexts')";
+ engine.eval(scriptTwoContexts, context1);
+ engine.eval(scriptTwoContexts, context2);
break;
case 3:
- context1 = engine.getContext();
- context2 = new SimpleScriptContext();
- context2.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
- context3 = new SimpleScriptContext();
- context3.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
- engine.eval(script, context1);
- engine.eval(script, context2);
- engine.eval(script, context3);
+ String scriptThreeContexts = "print('HelloThreeContexts')";
+ engine.eval(scriptThreeContexts, context1);
+ engine.eval(scriptThreeContexts, context2);
+ engine.eval(scriptThreeContexts, context3);
break;
}
} catch (final Exception se) {
@@ -113,7 +115,7 @@ public class NoPersistenceCachingTest {
+ expectedPatternOccurrence + " and found: " + matches + "\n"
+ stderr);
}
- setErrTest();
+ stderr.reset();
}
private static String getCodeCachePattern() {