9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * JDK-8144113: Nashorn: enable jjs testing. 26 * @subtest 27 * @summary test used by all other jjs-option* test cases 28 */ 29 var javaHome = $ENV.JAVA_HOME, 30 homeJjs = "${javaHome}/bin/jjs", 31 altJjs = $EXEC('which jjs').trim(), 32 homejavac = "${javaHome}/bin/javac", 33 altjavac = $EXEC('which javac').trim() 34 35 var Files = Java.type('java.nio.file.Files'), 36 Paths = Java.type('java.nio.file.Paths'), 37 System = Java.type('java.lang.System') 38 39 // Initialize default values for variables used in different functions 40 var func_cond_p = <<EOD 41 $EXIT == 0 42 EOD 43 44 var func_cond_n = <<EOD 45 $EXIT != 0 46 EOD 47 48 var flag_cond_p = <<EOD 49 out == e_outp 50 EOD 51 52 var flag_cond_n = <<EOD 53 out == e_outn 54 EOD 55 56 var e_outp = "true" 57 var e_outn = "false" 58 59 // special cases in which arguments used for negative testing also 60 var args_p = "-scripting" 61 var args_n = "-scripting" 62 63 // create file to check -flag passing 64 var path_f = Paths.get("temp-flag.js") 65 var testflag_file = path_f.toAbsolutePath() 66 67 // create file to check -flag functionality 68 var path_func = Paths.get("temp-func.js") 69 var testfunc_file = path_func.toAbsolutePath() 70 71 72 function exists(f) { 73 return Files.exists(Paths.get(f)) 74 } 75 76 var jjs = exists(homeJjs) ? homeJjs : altJjs 77 var javac = exists(homejavac) ? homejavac : altjavac 78 79 if (!exists(jjs)) { 80 throw "no jjs executable found; tried ${homeJjs} and ${altJjs}" 81 } 82 83 // write code to testflag_file 84 function write_testflag_file() { 85 Files.write(testflag_file, msg_flag.getBytes()) 86 } 87 88 // write code to testfunc_file 89 function write_testfunc_file() { 90 Files.write(testfunc_file, msg_func.getBytes()) 91 } 92 93 function flag_test_pass() { 94 print("flag test PASSED") 95 } 96 97 function flag_test_fail(e_out, out) { 98 print("flag test FAILED expected out:${e_out} found:${out}") 99 } 100 101 // check functionality of flag,cover both positive and negative cases 102 function testjjs_opt_func(args, positive) { 103 $EXEC("${jjs} ${args}") 104 var out = $OUT.trim(), 105 err = $ERR.trim() 106 if (positive) { 107 if (eval(func_cond_p)) 108 print("functionality test PASSED") 109 else 110 print("functionality test FAILED. stdout: ${out} -- stderr: ${err}") 139 if (func) 140 testjjs_opt_func(arg_n, type) 141 } 142 else { 143 flag_test_fail(e_outn, out) 144 } 145 } 146 } 147 148 // Main entry point to test both flag and its functionality 149 function testjjs_flag_and_func(flag, param) { 150 try { 151 var args = "${flag}" + "${param}" 152 write_testflag_file() 153 write_testfunc_file() 154 print("${flag} flag positive test:") 155 testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test 156 print("${flag} flag negative test:") 157 testjjs_opt("${args_n} ${testflag_file}", false, true) // negative test 158 } finally { 159 $EXEC("rm ${testflag_file}") 160 $EXEC("rm ${testfunc_file}") 161 } 162 } 163 164 // Main entry point to check only functionality of given -flag 165 function testjjs_functionality(flag, param) { 166 try { 167 var args = "${flag}" + "${param}" 168 write_testfunc_file() 169 print("${flag} flag positive test:") 170 testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test 171 print("${flag} flag negative test:") 172 testjjs_opt_func("${args_n} ${testfunc_file}", false) // negative test 173 } finally { 174 $EXEC("rm ${testfunc_file}") 175 } 176 } 177 178 // Main entry point to check only -flag settings for given flag 179 function testjjs_flag(flag, param) { 180 try { 181 var args = "${flag}" + "${param}" 182 write_testflag_file() 183 print("${flag} flag positive test:") 184 testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test 185 print("${flag} flag negative test:") 186 testjjs_opt("${args_n} ${testflag_file}", false, false) // negative test 187 } finally { 188 $EXEC("rm ${testflag_file}") 189 } 190 } | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * JDK-8144113: Nashorn: enable jjs testing. 26 * @subtest 27 * @summary test used by all other jjs-option* test cases 28 */ 29 30 load(__DIR__ + "JDK-util.js") 31 32 var javaHome = System.getenv("JAVA_HOME"), 33 homeJjs = "${javaHome}" + "/bin/jjs", 34 altJjs = which('jjs'), 35 homejavac = "${javaHome}" + "/bin/javac", 36 altjavac = which('javac') 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 } 52 53 // Initialize default values for variables used in different functions 54 var func_cond_p = <<EOD 55 $EXIT == 0 56 EOD 57 58 var func_cond_n = <<EOD 59 $EXIT != 0 60 EOD 61 62 var flag_cond_p = <<EOD 63 out == e_outp 64 EOD 65 66 var flag_cond_n = <<EOD 67 out == e_outn 68 EOD 69 70 var e_outp = "true" 71 var e_outn = "false" 72 73 // special cases in which arguments used for negative testing also 74 var args_p = "-scripting" 75 var args_n = "-scripting" 76 77 // create file to check -flag passing 78 var path_f = Paths.get("temp-flag.js") 79 var testflag_file = toShellPath(path_f.toAbsolutePath().toString()) 80 81 // create file to check -flag functionality 82 var path_func = Paths.get("temp-func.js") 83 var testfunc_file = toShellPath(path_func.toAbsolutePath().toString()) 84 85 function exists(f) { 86 return Files.exists(Paths.get(f)) 87 } 88 89 var jjs = exists(homeJjs) ? homeJjs : altJjs 90 var javac = exists(homejavac) ? homejavac : altjavac 91 92 if (!exists(jjs)) { 93 throw "no jjs executable found; tried ${homeJjs} and ${altJjs}" 94 } 95 96 // write code to testflag_file 97 function write_testflag_file() { 98 Files.write(Paths.get(testflag_file), msg_flag.getBytes()) 99 } 100 101 // write code to testfunc_file 102 function write_testfunc_file() { 103 Files.write(Paths.get(testfunc_file), msg_func.getBytes()) 104 } 105 106 function flag_test_pass() { 107 print("flag test PASSED") 108 } 109 110 function flag_test_fail(e_out, out) { 111 print("flag test FAILED expected out:${e_out} found:${out}") 112 } 113 114 // check functionality of flag,cover both positive and negative cases 115 function testjjs_opt_func(args, positive) { 116 $EXEC("${jjs} ${args}") 117 var out = $OUT.trim(), 118 err = $ERR.trim() 119 if (positive) { 120 if (eval(func_cond_p)) 121 print("functionality test PASSED") 122 else 123 print("functionality test FAILED. stdout: ${out} -- stderr: ${err}") 152 if (func) 153 testjjs_opt_func(arg_n, type) 154 } 155 else { 156 flag_test_fail(e_outn, out) 157 } 158 } 159 } 160 161 // Main entry point to test both flag and its functionality 162 function testjjs_flag_and_func(flag, param) { 163 try { 164 var args = "${flag}" + "${param}" 165 write_testflag_file() 166 write_testfunc_file() 167 print("${flag} flag positive test:") 168 testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test 169 print("${flag} flag negative test:") 170 testjjs_opt("${args_n} ${testflag_file}", false, true) // negative test 171 } finally { 172 rm("${testflag_file}") 173 rm("${testfunc_file}") 174 } 175 } 176 177 // Main entry point to check only functionality of given -flag 178 function testjjs_functionality(flag, param) { 179 try { 180 var args = "${flag}" + "${param}" 181 write_testfunc_file() 182 print("${flag} flag positive test:") 183 testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test 184 print("${flag} flag negative test:") 185 testjjs_opt_func("${args_n} ${testfunc_file}", false) // negative test 186 } finally { 187 rm("${testfunc_file}") 188 } 189 } 190 191 // Main entry point to check only -flag settings for given flag 192 function testjjs_flag(flag, param) { 193 try { 194 var args = "${flag}" + "${param}" 195 write_testflag_file() 196 print("${flag} flag positive test:") 197 testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test 198 print("${flag} flag negative test:") 199 testjjs_opt("${args_n} ${testflag_file}", false, false) // negative test 200 } finally { 201 rm("${testflag_file}") 202 } 203 } |