6705893: javax.script tests should not require a js engine on OpenJDK

Fixed the tests to pass with open JDK.

Reviewed-by: darcy
This commit is contained in:
Swamy Venkataramanappa 2008-08-18 15:28:54 -07:00
parent 36a04a49a7
commit f1f86e9fa2
24 changed files with 207 additions and 41 deletions

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6346734
* @bug 6346734 6705893
* @summary We do *not* support E4X (ECMAScript for XML) in our
* implementation. We want to throw error on XML literals
* as early as possible rather than at "runtime" - i.e., when
@ -37,9 +37,10 @@ public class E4XErrorTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsengine = manager.getEngineByName("js");
ScriptEngine jsengine = Helper.getJsEngine(manager);
if (jsengine == null) {
throw new RuntimeException("no js engine found");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
// The test below depends on the error message content

View File

@ -0,0 +1,41 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import javax.script.*;
/**
* Helper class to consolidate testing requirements for a js engine.
* A js engine is required as part of Sun's product JDK.
*/
public class Helper {
private Helper() {}; // Don't instantiate
public static ScriptEngine getJsEngine(ScriptEngineManager m) {
ScriptEngine e = m.getEngineByName("js");
if (e == null &&
System.getProperty("java.runtime.name").startsWith("Java(TM)")) {
// A js engine is requied for Sun's product JDK
throw new RuntimeException("no js engine found");
}
return e;
}
}

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6346733
* @bug 6346733 6705893
* @summary Verify that independent Bindings instances don't
* get affected by default scope assignments. Also, verify
* that script globals can be created and accessed from Java
@ -36,9 +36,10 @@ public class JavaScriptScopeTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsengine = manager.getEngineByName("js");
ScriptEngine jsengine = Helper.getJsEngine(manager);
if (jsengine == null) {
throw new RuntimeException("no js engine found");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
jsengine.eval("var v = 'hello';");
// Create a new scope

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6346732
* @bug 6346732 6705893
* @summary should be able to assign null and undefined
* value to JavaScript global variables.
*/
@ -34,9 +34,10 @@ public class NullUndefinedVarTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsengine = manager.getEngineByName("js");
ScriptEngine jsengine = Helper.getJsEngine(manager);
if (jsengine == null) {
throw new RuntimeException("no js engine found");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
jsengine.eval("var n = null; " +
"if (n !== null) throw 'expecting null';" +

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6398614
* @bug 6398614 6705893
* @summary Create a user defined ScriptContext and check
* that script can access variables from non-standard scopes
*/
@ -35,7 +35,11 @@ public class PluggableContextTest {
ScriptEngineManager m = new ScriptEngineManager();
ScriptContext ctx = new MyContext();
ctx.setAttribute("x", "hello", MyContext.APP_SCOPE);
ScriptEngine e = m.getEngineByName("js");
ScriptEngine e = Helper.getJsEngine(m);
if (e == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
// the following reference to 'x' throws exception
// if APP_SCOPE is not searched.
e.eval("x", ctx);

View File

@ -35,9 +35,10 @@ public class ProviderTest {
if (se == null) {
throw new RuntimeException("can't locate dummy engine");
}
se = manager.getEngineByName("js");
se = Helper.getJsEngine(manager);
if (se == null) {
throw new RuntimeException("can't locate JavaScript engine");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
}
}

View File

@ -23,8 +23,8 @@
/*
* @test
* @bug 6474943
* @summary Test that Rhion exception messages are
* @bug 6474943 6705893
* @summary Test that Rhino exception messages are
* available from ScriptException.
*/
@ -36,7 +36,11 @@ public class RhinoExceptionTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine engine = m.getEngineByName("js");
ScriptEngine engine = Helper.getJsEngine(m);
if (engine == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
engine.put("msg", ERROR_MSG);
try {
engine.eval("throw new Error(msg);");

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Create JavaScript engine and execute a simple script.
* Tests script engine discovery mechanism.
*/
@ -35,9 +35,10 @@ public class Test1 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest1\n");
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsengine = manager.getEngineByName("js");
ScriptEngine jsengine = Helper.getJsEngine(manager);
if (jsengine == null) {
throw new RuntimeException("no js engine found");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
jsengine.eval(new FileReader(
new File(System.getProperty("test.src", "."), "Test1.js")));

View File

@ -50,7 +50,11 @@ public class Test2 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest2\n");
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine eng = m.getEngineByName("js");
ScriptEngine eng = Helper.getJsEngine(m);
if (eng == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
eng.put("Testobj", new Testobj("Hello World"));
eng.eval(new FileReader(
new File(System.getProperty("test.src", "."), "Test2.js")));

View File

@ -4,6 +4,7 @@
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
@ -23,7 +24,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Test engine and global scopes
*/
@ -37,7 +38,11 @@ public class Test3 {
final Reader reader = new FileReader(
new File(System.getProperty("test.src", "."), "Test3.js"));
ScriptEngineManager m = new ScriptEngineManager();
final ScriptEngine engine = m.getEngineByName("js");
final ScriptEngine engine = Helper.getJsEngine(m);
if (engine == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
Bindings en = new SimpleBindings();
engine.setBindings(en, ScriptContext.ENGINE_SCOPE);
en.put("key", "engine value");

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Test script functions implementing Java interface
*/
@ -34,7 +34,11 @@ public class Test4 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest4\n");
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("js");
ScriptEngine e = Helper.getJsEngine(m);
if (e == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
e.eval(new FileReader(
new File(System.getProperty("test.src", "."), "Test4.js")));
Invocable inv = (Invocable)e;

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Tests engine, global scopes and scope hiding.
*/
@ -34,7 +34,11 @@ public class Test5 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest5\n");
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine engine = m.getEngineByName("js");
ScriptEngine engine = Helper.getJsEngine(m);
if (engine == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
Bindings g = new SimpleBindings();
Bindings e = new SimpleBindings();
g.put("key", "value in global");

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Test basic script compilation. Value eval'ed from
* compiled and interpreted scripts should be same.
*/
@ -35,7 +35,11 @@ public class Test6 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest6\n");
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine engine = m.getEngineByName("js");
ScriptEngine engine = Helper.getJsEngine(m);
if (engine == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
Reader reader = new FileReader(
new File(System.getProperty("test.src", "."), "Test6.js"));
engine.eval(reader);

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Tests importPackage and java access in script
*/
@ -37,7 +37,11 @@ public class Test7 {
new File(System.getProperty("test.src", "."), "Test7.js");
Reader r = new FileReader(file);
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine eng = m.getEngineByName("js");
ScriptEngine eng = Helper.getJsEngine(m);
if (eng == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
eng.put("filename", file.getAbsolutePath());
eng.eval(r);
String str = (String)eng.get("firstLine");

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6249843
* @bug 6249843 6705893
* @summary Test invoking script function or method from Java
*/
@ -34,7 +34,11 @@ public class Test8 {
public static void main(String[] args) throws Exception {
System.out.println("\nTest8\n");
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("js");
ScriptEngine e = Helper.getJsEngine(m);
if (e == null) {
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
e.eval(new FileReader(
new File(System.getProperty("test.src", "."), "Test8.js")));
Invocable inv = (Invocable)e;

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 6346729
* @bug 6346729 6705893
* @summary Create JavaScript engine and check language and engine version
*/
@ -37,9 +37,10 @@ public class VersionTest {
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsengine = manager.getEngineByName("js");
ScriptEngine jsengine = Helper.getJsEngine(manager);
if (jsengine == null) {
throw new RuntimeException("no js engine found");
System.out.println("Warning: No js engine found; test vacuously passes.");
return;
}
String langVersion = jsengine.getFactory().getLanguageVersion();
if (! langVersion.equals(JS_LANG_VERSION)) {

View File

@ -0,0 +1,45 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import javax.script.*;
/*
* If the JDK being tested is <b>not</b> a Sun product JDK and a js
* engine is not present, return an exit code of 2 to indicate that
* the jrunscript tests which assume a js engine can be vacuously
* passed.
*/
public class CheckEngine {
public static void main(String... args) {
int exitCode = 0;
ScriptEngine engine =
(new ScriptEngineManager()).getEngineByName("js");
if (engine == null &&
!(System.getProperty("java.runtime.name").startsWith("Java(TM)"))) {
exitCode = 2;
}
System.exit(exitCode);
}
}

View File

@ -52,4 +52,5 @@ setup() {
JRUNSCRIPT="${TESTJAVA}/bin/jrunscript"
JAVAC="${TESTJAVA}/bin/javac"
JAVA="${TESTJAVA}/bin/java"
}

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscript-DTest.sh
# @summary Test that output of 'jrunscript -D'
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
# test whether value specifieD by -D option is passed
# to script as java.lang.System property. sysProps is

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscript-argsTest.sh
# @summary Test passing of script arguments from command line
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
# we check whether "excess" args are passed as script arguments

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscript-cpTest.sh
# @summary Test -cp option to set classpath
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
rm -f Hello.class
${JAVAC} ${TESTSRC}/Hello.java -d .

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscript-eTest.sh
# @summary Test that output of 'jrunscript -e' matches the dash-e.out file
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
rm -f jrunscript-eTest.out 2>/dev/null
${JRUNSCRIPT} -e "println('hello')" > jrunscript-eTest.out 2>&1

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscript-fTest.sh
# @summary Test that output of 'jrunscript -f' matches the dash-f.out file
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
rm -f jrunscript-fTest.out 2>/dev/null
${JRUNSCRIPT} -f ${TESTSRC}/hello.js > jrunscript-fTest.out 2>&1

View File

@ -25,13 +25,19 @@
# @test
# @bug 6265810
# @bug 6265810 6705893
# @build CheckEngine
# @run shell jrunscriptTest.sh
# @summary Test that output of 'jrunscript' interactive matches the repl.out file
. ${TESTSRC-.}/common.sh
setup
${JAVA} -cp ${TESTCLASSES} CheckEngine
if [ $? -eq 2 ]; then
echo "No js engine found and engine not required; test vacuously passes."
exit 0
fi
rm -f jrunscriptTest.out 2>/dev/null
${JRUNSCRIPT} > jrunscriptTest.out 2>&1 <<EOF