Path: blob/master/test/jdk/tools/jimage/JImageBasicsTest.java
41144 views
/*1* Copyright (c) 2016, 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* @summary Tests to verify jimage basic options, i.e. --version, -h26* @library /test/lib27* @modules jdk.jlink/jdk.tools.jimage28* @build jdk.test.lib.Asserts29* @run main JImageBasicsTest30*/3132import static jdk.test.lib.Asserts.assertTrue;3334public class JImageBasicsTest extends JImageCliTest {3536public void testVersion() {37jimage("--version")38.assertSuccess()39.resultChecker(r -> {40assertTrue(r.output.contains(System.getProperty("java.version")), "Contains java version.");41});42}4344public void testFullVersion() {45jimage("--full-version")46.assertSuccess()47.resultChecker(r -> {48assertTrue(r.output.contains(System.getProperty("java.version")), "Contains java version.");49});50}5152public void testHelp() {53jimage("--help")54.assertSuccess()55.resultChecker(r -> verifyHelpOutput(r.output));56}5758public void testShortHelp() {59jimage("-h")60.assertSuccess()61.resultChecker(r -> verifyHelpOutput(r.output));62}6364public void testUnknownAction() {65jimage("unknown")66.assertFailure()67.assertShowsError();68}6970public void testUnknownOption() {71jimage("--unknown")72.assertFailure()73.assertShowsError();74}7576private void verifyHelpOutput(String output) {77assertTrue(output.startsWith("Usage: jimage"), "Usage is printed.");78assertTrue(output.contains("extract"), "Option 'extract' is found.");79assertTrue(output.contains("info"), "Option 'info' is found.");80assertTrue(output.contains("list"), "Option 'list' is found.");81assertTrue(output.contains("verify"), "Option 'verify' is found.");82}8384public static void main(String[] args) throws Throwable {85new JImageBasicsTest().runTests();86}87}88899091