Path: blob/master/test/jdk/tools/launcher/Jexec.java
41144 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 817500026* @summary test jexec27* @build TestHelper28* @run main Jexec29*/3031import java.io.File;32import java.io.IOException;3334public class Jexec extends TestHelper {35private final File testJar;36private final File jexecCmd;37private final String message = "Hello, do you read me ?";3839Jexec() throws IOException {40jexecCmd = new File(JAVA_LIB, "jexec");41if (!jexecCmd.exists() || !jexecCmd.canExecute()) {42throw new Error("jexec: does not exist or not executable");43}4445testJar = new File("test.jar");46StringBuilder tsrc = new StringBuilder();47tsrc.append("public static void main(String... args) {\n");48tsrc.append(" for (String x : args) {\n");49tsrc.append(" System.out.println(x);\n");50tsrc.append(" }\n");51tsrc.append("}\n");52createJar(testJar, tsrc.toString());53}5455public static void main(String... args) throws Exception {56// linux is the only supported platform, give the others a pass57if (!isLinux) {58System.err.println("Warning: unsupported platform test passes vacuously");59return;60}61// ok to run the test now62Jexec t = new Jexec();63t.run(null);64}6566@Test67void jexec() throws Exception {68TestResult tr = doExec(jexecCmd.getAbsolutePath(),69testJar.getAbsolutePath(), message);70if (!tr.isOK()) {71System.err.println(tr);72throw new Exception("incorrect exit value");73}74if (!tr.contains(message)) {75System.err.println(tr);76throw new Exception("expected message \'" + message + "\' not found");77}78}79}808182