sundar@1525: /* sdama@1838: * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. sundar@1525: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1525: * sundar@1525: * This code is free software; you can redistribute it and/or modify it sundar@1525: * under the terms of the GNU General Public License version 2 only, as sundar@1525: * published by the Free Software Foundation. sundar@1525: * sundar@1525: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1525: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1525: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1525: * version 2 for more details (a copy is included in the LICENSE file that sundar@1525: * accompanied this code). sundar@1525: * sundar@1525: * You should have received a copy of the GNU General Public License version sundar@1525: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1525: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1525: * sundar@1525: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1525: * or visit www.oracle.com if you need additional information or have any sundar@1525: * questions. sundar@1525: */ sundar@1525: sundar@1525: /** sundar@1525: * JDK-8087292: nashorn should have a "fail-fast" option for scripting, analog to bash "set -e" sundar@1525: * sundar@1525: * @test sundar@1525: * @option -scripting sundar@1525: * @run sundar@1525: */ sundar@1525: sdama@1838: load(__DIR__ + "JDK-util.js") sdama@1838: sdama@1838: var jHomePath = System.getenv("JAVA_HOME") sdama@1838: var jLauncher = "${jHomePath}/bin/java" sdama@1838: var altjLauncher = which('java') sdama@1838: sdama@1838: if (windows) { sdama@1838: if(winCyg) { sdama@1838: jLauncher = "${jHomePath}" + "/bin/java.exe" sdama@1838: jLauncher = cygpath(jLauncher,outPath.windows) sdama@1838: } sdama@1838: else { sdama@1838: jLauncher = "${jHomePath}" + "\\bin\\java.exe" sdama@1838: altjLauncher = which('java.exe') sdama@1838: altjLauncher = cygpath(altjLauncher,outPath.windows) sdama@1838: } sdama@1838: } sdama@1838: sdama@1838: function exists(f) { sdama@1838: return Files.exists(Paths.get(f)) sdama@1838: } sdama@1838: sdama@1838: var javaLauncher = exists(jLauncher) ? jLauncher : altjLauncher sdama@1838: sdama@1838: sdama@1838: if (!exists(javaLauncher)) { sdama@1838: throw "no java launcher found; tried ${jLauncher} and ${altjLauncher}" sdama@1838: } sdama@1838: sundar@1525: function tryExec() { sundar@1525: try { sdama@1838: $EXEC("${javaLauncher}") sundar@1525: } catch (e) { sdama@1838: print(e) sundar@1525: } sundar@1525: sundar@1525: // make sure we got non-zero ("failure") exit code! sundar@1525: if ($EXIT == 0) { sdama@1838: print("Error: expected $EXIT code to be non-zero") sundar@1525: } sundar@1525: } sdama@1838: //convert windows paths to cygwin sdama@1838: if (windows) sdama@1838: javaLauncher = (winCyg) ? cygpath(javaLauncher,outPath.mixed).trim() : cygpath(javaLauncher,outPath.windows).trim() sundar@1525: sundar@1525: // no exception now! sdama@1838: tryExec() sundar@1525: sundar@1525: // turn on error with non-zero exit code sdama@1838: $EXEC.throwOnError = true sdama@1838: tryExec() sundar@1525: sundar@1525: // no exception after this sdama@1838: $EXEC.throwOnError = false sdama@1838: tryExec()