Mercurial > hg > openjdk > jdk9 > nashorn
changeset 1603:086c19a36be6
8144113: enable jjs testing
Reviewed-by: mhaupt, sundar
Contributed-by: srinivas.dama@oracle.com
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/Hello.java Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * This is a test program used in the test jjs-option-cp.js + */ +public class Hello { + public Hello() { + } + + public String getString() { + return "hello"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-common.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @subtest + * @summary test used by all other jjs-option* test cases + */ +var javaHome = $ENV.JAVA_HOME, + homeJjs = "${javaHome}/bin/jjs", + altJjs = $EXEC('which jjs').trim(), + homejavac = "${javaHome}/bin/javac", + altjavac = $EXEC('which javac').trim() + +var Files = Java.type('java.nio.file.Files'), + Paths = Java.type('java.nio.file.Paths'), + System = Java.type('java.lang.System') + +// Initialize default values for variables used in different functions +var func_cond_p = <<EOD +$EXIT == 0 +EOD + +var func_cond_n = <<EOD +$EXIT != 0 +EOD + +var flag_cond_p = <<EOD +out == e_outp +EOD + +var flag_cond_n = <<EOD +out == e_outn +EOD + +var e_outp = "true" +var e_outn = "false" + +// special cases in which arguments used for negative testing also +var args_p = "-scripting" +var args_n = "-scripting" + +// create file to check -flag passing +var path_f = Paths.get("temp-flag.js") +var testflag_file = path_f.toAbsolutePath() + +// create file to check -flag functionality +var path_func = Paths.get("temp-func.js") +var testfunc_file = path_func.toAbsolutePath() + + +function exists(f) { + return Files.exists(Paths.get(f)) +} + +var jjs = exists(homeJjs) ? homeJjs : altJjs +var javac = exists(homejavac) ? homejavac : altjavac + +if (!exists(jjs)) { + throw "no jjs executable found; tried ${homeJjs} and ${altJjs}" +} + +// write code to testflag_file +function write_testflag_file() { + Files.write(testflag_file, msg_flag.getBytes()) +} + +// write code to testfunc_file +function write_testfunc_file() { + Files.write(testfunc_file, msg_func.getBytes()) +} + +function flag_test_pass() { + print("flag test PASSED") +} + +function flag_test_fail(e_out, out) { + print("flag test FAILED expected out:${e_out} found:${out}") +} + +// check functionality of flag,cover both positive and negative cases +function testjjs_opt_func(args, positive) { + $EXEC("${jjs} ${args}") + var out = $OUT.trim(), + err = $ERR.trim() + if (positive) { + if (eval(func_cond_p)) + print("functionality test PASSED") + else + print("functionality test FAILED. stdout: ${out} -- stderr: ${err}") + } + else { + if (eval(func_cond_n)) + print("functionality test PASSED") + else + print("functionality test FAILED. stdout: ${out} -- stderr: ${err}") + } + +} + +// check if corresponding $OPTIONS._XXX is set for given flag +function testjjs_opt(args, type, func) { + $EXEC("${jjs} ${args}") + var out = $OUT.trim(), + err = $ERR.trim() + if (type) { + if (eval(flag_cond_p)) { + flag_test_pass() + if (func) + testjjs_opt_func(arg_p, type) + } + else { + flag_test_fail(e_outp, out) + } + } + else { + if (eval(flag_cond_n)) { + flag_test_pass() + if (func) + testjjs_opt_func(arg_n, type) + } + else { + flag_test_fail(e_outn, out) + } + } +} + +// Main entry point to test both flag and its functionality +function testjjs_flag_and_func(flag, param) { + try { + var args = "${flag}" + "${param}" + write_testflag_file() + write_testfunc_file() + print("${flag} flag positive test:") + testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test + print("${flag} flag negative test:") + testjjs_opt("${args_n} ${testflag_file}", false, true) // negative test + } finally { + $EXEC("rm ${testflag_file}") + $EXEC("rm ${testfunc_file}") + } +} + +// Main entry point to check only functionality of given -flag +function testjjs_functionality(flag, param) { + try { + var args = "${flag}" + "${param}" + write_testfunc_file() + print("${flag} flag positive test:") + testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test + print("${flag} flag negative test:") + testjjs_opt_func("${args_n} ${testfunc_file}", false) // negative test + } finally { + $EXEC("rm ${testfunc_file}") + } +} + +// Main entry point to check only -flag settings for given flag +function testjjs_flag(flag, param) { + try { + var args = "${flag}" + "${param}" + write_testflag_file() + print("${flag} flag positive test:") + testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test + print("${flag} flag negative test:") + testjjs_opt("${args_n} ${testflag_file}", false, false) // negative test + } finally { + $EXEC("rm ${testflag_file}") + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-cp.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test to check if -cp flag and its basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +var hello = __DIR__ + "Hello.class"; +var helloj = __DIR__ + "Hello.java"; + +// code to check -flag +var msg_flag = "print($OPTIONS._classpath)" + +// code to check basic functionality +var msg_func = <<EOD +$EXEC("rm -f ${hello}") +$EXEC("${javac} ${helloj}") +var v = new Packages.Hello(); +if (v.string != 'hello') { + throw new Error("Unexpected property value"); +} +EOD + +// flag test expected output variables +var e_outp = "__DIR__" +var e_outn = "null" + +// functionality test arguments +var arg_p = "-scripting -cp ${__DIR__} ${testfunc_file}" +var arg_n = "-scripting ${testfunc_file}" + +// Testing starts here +testjjs_flag_and_func("-cp", " __DIR__") +$EXEC("rm -f ${hello}")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-cp.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +-cp flag positive test: +flag test PASSED +functionality test PASSED +-cp flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-define.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test to check -D flag basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +var path_func = Paths.get("temp-property-func.js") +var testfunc_file = path_func.toAbsolutePath() + +// code to check basic functionality +var msg_func = <<EOD +try { + var System = Java.type('java.lang.System'); + print(System.getProperty('user.name')) + if (System.getProperty('user.name') != "nashorn9") + throw new Error("un expected system property user.name value") +} finally { +} +EOD + +// Testing starts here +testjjs_functionality("-D", "user.name=nashorn9")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-define.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,4 @@ +-D flag positive test: +functionality test PASSED +-D flag negative test: +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-doe.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -doe flag and its basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +// code to check -flag +var msg_flag = "print($OPTIONS._dump_on_error)" + +// code to check basic functionality +var msg_func = <<EOD +print("Hello Nashorn) +EOD + +// flag test expected output variables +var e_outp = "true" +var e_outn = "false" + +// functionality test arguments +var arg_p = "-scripting -doe ${testfunc_file}" +var arg_n = "-scripting ${testfunc_file}" + +// functionality condition checks used. +var func_cond_p = <<'EOD' +err.indexOf("internal") > -1 +EOD + +var func_cond_n = <<'EOD' +err.indexOf("internal") <= -1 +EOD + +// one particular test starts here +testjjs_flag_and_func("-doe", "")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-doe.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +-doe flag positive test: +flag test PASSED +functionality test PASSED +-doe flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-fv.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test if -fv flag its basic funnctionality + */ + +load(__DIR__ + "jjs-common.js") + +// code to check -flag +var msg_flag = "print($OPTIONS._fullversion)" + +// code to check basic functionality +var msg_func = <<EOD +var x = "Hello Nashorn" +EOD + +// flag test expected output variables +var e_outp = "true" +var e_outn = "false" + +// functionality test arguments +var arg_p = "-scripting -fv ${testfunc_file}" +var arg_n = "-scripting ${testfunc_file}" + +var func_cond_p = <<'EOD' +err.indexOf("full") > -1 +EOD + +var func_cond_n = <<'EOD' +err.indexOf("full") <= -1 +EOD + +// one particular test starts here +testjjs_flag_and_func("-fv", "")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-fv.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +-fv flag positive test: +flag test PASSED +functionality test PASSED +-fv flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-fx.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * check -fx option. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -fx flag and its basic functionality + * the JavaFX primary stage is available to Nashorn as a global property $STAGE with -fx + * used this to check with and without -fx + */ + +load(__DIR__ + "jjs-common.js") + +var msg_flag = "print(typeof($STAGE));"; + +// flag test expected output variables +var e_outn = "undefined" + +// positive flag test condition expression string other than the default +var flag_cond_p = <<'EOD' +out != "undefined" +EOD + +// Testing starts here +testjjs_flag("-fx","")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-fx.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,4 @@ +-fx flag positive test: +flag test PASSED +-fx flag negative test: +flag test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-lang.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -lang flag and its basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +// code to check -flag +var msg_flag = "print($OPTIONS._es6)" + +// code to check basic functionality +var msg_func = <<EOD +const X = 4 +try { + X = 55 + throw new Error("should have thrown TypeError") +} catch (e) { + if (!(e instanceof TypeError)) { + throw new Error("TypeError expected, got " + e) + } +} +EOD + +// flag test expected output variables +var e_outp = "true" +var e_outn = "false" + +// functionality test arguments +var arg_p = "-scripting --language=es6 ${testfunc_file}" +var arg_n = "-scripting ${testfunc_file}" + +// Testing starts here +testjjs_flag_and_func("--language", "=es6")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-lang.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +--language flag positive test: +flag test PASSED +functionality test PASSED +--language flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-ot.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -ot flag + */ + +load(__DIR__ + "jjs-common.js") + +var args_n = "-scripting -ot=false" +var msg_flag = "print($OPTIONS._optimistic_types);"; + +// flag test expected output variables +var e_outp = "true" +var e_outn = "false" + +// Testing starts here +testjjs_flag("-ot","")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-ot.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,4 @@ +-ot flag positive test: +flag test PASSED +-ot flag negative test: +flag test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-scripting.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -scripting flag and its basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +// code to check -flag +var msg_flag = "print($OPTIONS._scripting)" + +// code to check basic functionality +var msg_func = <<'EOD' +var x = "Nashorn" +var hello = "Hello ${x}" +if (hello != "Hello Nashorn") { + throw new Error("string interploation not working"); +} +EOD + +// flag test expected output variables +var e_outn = 'ReferenceErrorr: "$OPTIONS" is not defined' +// negative flag test condition +var flag_cond_n = 'err.indexOf("$OPTIONS") > -1' + +// functionality test arguments +var arg_p = "-scripting ${testfunc_file}" +var arg_n = "${testfunc_file}" + +var args_p = "", + args_n = "" + +// Testing starts here +testjjs_flag_and_func("-scripting", "")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-scripting.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +-scripting flag positive test: +flag test PASSED +functionality test PASSED +-scripting flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-strict.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -strict flag and its basic functionality + */ + +load(__DIR__ + "jjs-common.js") + +// code to check -flag +var msg_flag = "print($OPTIONS._strict)" + +// code to check basic functionality +var msg_func = <<EOD +try { + v = "nashorn" + throw new Error("should have thrown reference error") +} catch (e) { + if (!(e instanceof ReferenceError)) { + throw new Error("ReferenceError expected, got " + e) + } +} +EOD + +// functionality test arguments +var arg_p = "-scripting -strict ${testfunc_file}" +var arg_n = "-scripting ${testfunc_file}" + +// Testing starts here +testjjs_flag_and_func("-strict","")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-strict.js.EXPECTED Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,6 @@ +-strict flag positive test: +flag test PASSED +functionality test PASSED +-strict flag negative test: +flag test PASSED +functionality test PASSED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/nosecurity/jjs-option-version.js Wed Jan 20 09:56:29 2016 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8144113: Nashorn: enable jjs testing. + * check if jjs version is same as of java. + * @test + * @option -scripting + * @runif os.not.windows + * @run + * @summary Test -version flag and its functionality + */ + + +load(__DIR__ + "jjs-common.js") + +var javaVersion = System.getProperty('java.version') + +// code to check -flag +var msg_flag = 'var x = "Hello Nashorn"' + +// flag test expected output variables +var e_outp = "nashorn ${javaVersion}" +var e_outn = "Hello Nashorn" + +// not sure why version info is found in error stream not in out stream.?? +flag_cond_p = "err.indexOf(e_outp)> -1" +flag_cond_n = "err.indexOf(e_outp)<= -1" + +testjjs_flag("-version","")