Path: blob/master/test/jdk/tools/launcher/InfoStreams.java
41144 views
/*1* Copyright (c) 2016, 2018, 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* @library /test/lib26* @build InfoStreams jdk.test.lib.process.ProcessTools27* @run main InfoStreams28* @summary Test that informational options use the correct streams29*/3031import jdk.test.lib.process.ProcessTools;32import jdk.test.lib.process.OutputAnalyzer;3334public class InfoStreams {3536public static OutputAnalyzer run(String ... opts) throws Exception {37return ProcessTools.executeTestJava(opts).shouldHaveExitValue(0);38}3940private static final String41java_version = System.getProperty("java.version"),42USAGE = "^Usage: java ",43VERSION_ERR = "^(java|openjdk) version \"" + java_version + "\"",44VERSION_OUT = "^(java|openjdk) " + java_version,45FULLVERSION_ERR = "^(java|openjdk) full version \"" + java_version + ".*\"",46FULLVERSION_OUT = "^(java|openjdk) " + java_version,47NONSTD = ".*These extra options are subject to change";4849public static void main(String ... args) throws Exception {5051String classPath = System.getProperty("java.class.path");5253run("-help").stderrShouldMatch(USAGE).stdoutShouldNotMatch(USAGE);54run("--help").stdoutShouldMatch(USAGE).stderrShouldNotMatch(USAGE);5556run("-version").stderrShouldMatch(VERSION_ERR)57.stdoutShouldNotMatch(VERSION_ERR)58.stdoutShouldNotMatch(VERSION_OUT);59run("--version").stdoutShouldMatch(VERSION_OUT)60.stderrShouldNotMatch(VERSION_OUT)61.stderrShouldNotMatch(VERSION_ERR);6263run("-showversion", "--dry-run", "-cp", classPath, "InfoStreams")64.stderrShouldMatch(VERSION_ERR)65.stdoutShouldNotMatch(VERSION_ERR)66.stdoutShouldNotMatch(VERSION_OUT);67run("--show-version", "--dry-run", "-cp", classPath, "InfoStreams")68.stdoutShouldMatch(VERSION_OUT)69.stderrShouldNotMatch(VERSION_OUT)70.stderrShouldNotMatch(VERSION_ERR);7172run("-fullversion").stderrShouldMatch(FULLVERSION_ERR)73.stdoutShouldNotMatch(FULLVERSION_ERR)74.stdoutShouldNotMatch(FULLVERSION_OUT);75run("--full-version").stdoutShouldMatch(FULLVERSION_OUT)76.stderrShouldNotMatch(FULLVERSION_OUT)77.stderrShouldNotMatch(FULLVERSION_ERR);7879run("-X").stderrShouldMatch(NONSTD).stdoutShouldNotMatch(NONSTD);80run("--help-extra").stdoutShouldMatch(NONSTD).stderrShouldNotMatch(NONSTD);81}82}838485