nashorn/test/script/nosecurity/jjs-common.js
changeset 36689 3370f6f942ff
parent 35324 b9b0e5fdc996
equal deleted inserted replaced
36688:49f82e2e9fa4 36689:3370f6f942ff
    24 /**
    24 /**
    25  * JDK-8144113: Nashorn: enable jjs testing.
    25  * JDK-8144113: Nashorn: enable jjs testing.
    26  * @subtest
    26  * @subtest
    27  * @summary test used by all other jjs-option* test cases
    27  * @summary test used by all other jjs-option* test cases
    28  */
    28  */
    29 var javaHome = $ENV.JAVA_HOME,
    29 
    30     homeJjs = "${javaHome}/bin/jjs",
    30 load(__DIR__ + "JDK-util.js")
    31     altJjs = $EXEC('which jjs').trim(),
    31 
    32     homejavac = "${javaHome}/bin/javac",
    32 var javaHome = System.getenv("JAVA_HOME"),
    33     altjavac = $EXEC('which javac').trim()
    33     homeJjs = "${javaHome}" + "/bin/jjs",
    34 
    34     altJjs = which('jjs'),
    35 var Files = Java.type('java.nio.file.Files'),
    35     homejavac = "${javaHome}" + "/bin/javac",
    36     Paths = Java.type('java.nio.file.Paths'),
    36     altjavac = which('javac')
    37     System = Java.type('java.lang.System')
    37 
       
    38 if (windows) {
       
    39     if (winCyg) {
       
    40         //Files.exists() expects proper extension as it talks to windows filesystem even on cygwin
       
    41         //make paths work on on underlying shells cygwin/cmd/linux.
       
    42         homeJjs = toShellPath("${javaHome}" + "/bin/jjs.exe")
       
    43         homejavac = toShellPath("${javaHome}" + "/bin/javac.exe")
       
    44     }
       
    45     else {
       
    46         homeJjs = toShellPath("${javaHome}" + "\\bin\\jjs.exe")
       
    47         homejavac = toShellPath("${javaHome}" + "\\bin\\javac.exe")
       
    48     }
       
    49     altJjs = which('jjs.exe')
       
    50     altjavac = which('javac.exe')
       
    51 }
    38 
    52 
    39 // Initialize default values for variables used in different functions
    53 // Initialize default values for variables used in different functions
    40 var func_cond_p = <<EOD
    54 var func_cond_p = <<EOD
    41 $EXIT == 0
    55 $EXIT == 0
    42 EOD
    56 EOD
    60 var args_p = "-scripting"
    74 var args_p = "-scripting"
    61 var args_n = "-scripting"
    75 var args_n = "-scripting"
    62 
    76 
    63 // create file to check -flag passing
    77 // create file to check -flag passing
    64 var path_f = Paths.get("temp-flag.js")
    78 var path_f = Paths.get("temp-flag.js")
    65 var testflag_file = path_f.toAbsolutePath()
    79 var testflag_file = toShellPath(path_f.toAbsolutePath().toString())
    66 
    80 
    67 // create file to check -flag functionality
    81 // create file to check -flag functionality
    68 var path_func = Paths.get("temp-func.js")
    82 var path_func = Paths.get("temp-func.js")
    69 var testfunc_file = path_func.toAbsolutePath()
    83 var testfunc_file = toShellPath(path_func.toAbsolutePath().toString())
    70 
       
    71 
    84 
    72 function exists(f) {
    85 function exists(f) {
    73     return Files.exists(Paths.get(f))
    86     return Files.exists(Paths.get(f))
    74 }
    87 }
    75 
    88 
    80     throw "no jjs executable found; tried ${homeJjs} and ${altJjs}"
    93     throw "no jjs executable found; tried ${homeJjs} and ${altJjs}"
    81 }
    94 }
    82 
    95 
    83 // write code to testflag_file
    96 // write code to testflag_file
    84 function write_testflag_file() {
    97 function write_testflag_file() {
    85     Files.write(testflag_file, msg_flag.getBytes())
    98     Files.write(Paths.get(testflag_file), msg_flag.getBytes())
    86 }
    99 }
    87 
   100 
    88 // write code to testfunc_file
   101 // write code to testfunc_file
    89 function write_testfunc_file() {
   102 function write_testfunc_file() {
    90     Files.write(testfunc_file, msg_func.getBytes())
   103     Files.write(Paths.get(testfunc_file), msg_func.getBytes())
    91 }
   104 }
    92 
   105 
    93 function flag_test_pass() {
   106 function flag_test_pass() {
    94     print("flag test PASSED")
   107     print("flag test PASSED")
    95 }
   108 }
   104     var out = $OUT.trim(),
   117     var out = $OUT.trim(),
   105         err = $ERR.trim()
   118         err = $ERR.trim()
   106     if (positive) {
   119     if (positive) {
   107         if (eval(func_cond_p))
   120         if (eval(func_cond_p))
   108             print("functionality test PASSED")
   121             print("functionality test PASSED")
   109         else
   122         else 
   110             print("functionality test FAILED. stdout: ${out} -- stderr: ${err}")
   123             print("functionality test FAILED. stdout: ${out} -- stderr: ${err}")
   111     }
   124     }
   112     else {
   125     else {
   113         if (eval(func_cond_n))
   126         if (eval(func_cond_n))
   114             print("functionality test PASSED")
   127             print("functionality test PASSED")
   154         print("${flag} flag positive test:")
   167         print("${flag} flag positive test:")
   155         testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test
   168         testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test
   156         print("${flag} flag negative test:")
   169         print("${flag} flag negative test:")
   157         testjjs_opt("${args_n} ${testflag_file}", false, true)        // negative test
   170         testjjs_opt("${args_n} ${testflag_file}", false, true)        // negative test
   158     } finally {
   171     } finally {
   159         $EXEC("rm ${testflag_file}")
   172         rm("${testflag_file}")
   160         $EXEC("rm ${testfunc_file}")
   173         rm("${testfunc_file}")
   161     }
   174     }
   162 }
   175 }
   163 
   176 
   164 // Main entry point to check only functionality of given -flag
   177 // Main entry point to check only functionality of given -flag
   165 function testjjs_functionality(flag, param) {
   178 function testjjs_functionality(flag, param) {
   169         print("${flag} flag positive test:")
   182         print("${flag} flag positive test:")
   170         testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test
   183         testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test
   171         print("${flag} flag negative test:")
   184         print("${flag} flag negative test:")
   172         testjjs_opt_func("${args_n} ${testfunc_file}", false)        // negative test
   185         testjjs_opt_func("${args_n} ${testfunc_file}", false)        // negative test
   173     } finally {
   186     } finally {
   174         $EXEC("rm ${testfunc_file}")
   187         rm("${testfunc_file}")
   175     }
   188     }
   176 }
   189 }
   177 
   190 
   178 // Main entry point to check only -flag settings for given flag
   191 // Main entry point to check only -flag settings for given flag
   179 function testjjs_flag(flag, param) {
   192 function testjjs_flag(flag, param) {
   183         print("${flag} flag positive test:")
   196         print("${flag} flag positive test:")
   184         testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test
   197         testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test
   185         print("${flag} flag negative test:")
   198         print("${flag} flag negative test:")
   186         testjjs_opt("${args_n} ${testflag_file}", false, false)        // negative test
   199         testjjs_opt("${args_n} ${testflag_file}", false, false)        // negative test
   187     } finally {
   200     } finally {
   188         $EXEC("rm ${testflag_file}")
   201         rm("${testflag_file}")
   189     }
   202     }
   190 }
   203 }