Path: blob/master/test/jdk/tools/launcher/modules/listmods/ListModsTest.java
41153 views
/*1* Copyright (c) 2015, 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* @requires !vm.graal.enabled26* @library /test/lib27* @modules java.se28* @build ListModsTest jdk.test.lib.compiler.CompilerUtils29* @run testng ListModsTest30* @summary Basic test for java --list-modules31*/3233import java.nio.file.Path;34import java.nio.file.Paths;3536import jdk.test.lib.compiler.CompilerUtils;37import jdk.test.lib.process.ProcessTools;38import jdk.test.lib.process.OutputAnalyzer;3940import org.testng.annotations.BeforeTest;41import org.testng.annotations.Test;42import static org.testng.Assert.*;4344/**45* Basic tests for java --list-modules46*/4748public class ListModsTest {4950private static final String TEST_SRC = System.getProperty("test.src");51private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");52private static final Path MODS_DIR = Paths.get("mods");53private static final Path UPGRADEMODS_DIR = Paths.get("upgrademods");5455@BeforeTest56public void setup() throws Exception {57boolean compiled;5859// javac -d mods/m1 --module-path mods src/m1/**60compiled = CompilerUtils.compile(61SRC_DIR.resolve("m1"),62MODS_DIR.resolve("m1"));63assertTrue(compiled);6465// javac -d upgrademods/java.transaction --module-path mods src/java.transaction/**66compiled = CompilerUtils.compile(67SRC_DIR.resolve("java.transaction"),68UPGRADEMODS_DIR.resolve("java.transaction"));69assertTrue(compiled);70}7172@Test73public void testListAll() throws Exception {74exec("--list-modules")75.shouldContain("java.base")76.shouldContain("java.xml")77.shouldHaveExitValue(0);78}7980@Test81public void testListWithModulePath() throws Exception {82exec("--list-modules", "--module-path", MODS_DIR.toString())83.shouldContain("java.base")84.shouldContain("m1")85.shouldHaveExitValue(0);86}8788@Test89public void testListWithUpgradeModulePath() throws Exception {90String dir = UPGRADEMODS_DIR.toString();91exec("--list-modules", "--upgrade-module-path", dir)92.shouldContain(UPGRADEMODS_DIR.toString())93.shouldHaveExitValue(0);94}9596@Test97public void testListWithLimitMods1() throws Exception {98exec("--limit-modules", "java.management.rmi", "--list-modules")99.shouldContain("java.rmi")100.shouldContain("java.base")101.shouldNotContain("java.scripting")102.shouldHaveExitValue(0);103}104105@Test106public void testListWithLimitMods2() throws Exception {107exec("--list-modules",108"--module-path", MODS_DIR.toString(),109"--limit-modules", "java.management")110.shouldContain("java.base")111.shouldNotContain("m1")112.shouldHaveExitValue(0);113}114115/**116* java -version --list-modules => should print version and exit117*/118@Test119public void testListWithPrintVersion1() throws Exception {120exec("-version", "--list-modules")121.shouldNotContain("java.base")122.shouldContain("Runtime Environment")123.shouldHaveExitValue(0);124}125126/**127* java --list-modules -version => should list modules and exit128*/129@Test130public void testListWithPrintVersion2() throws Exception {131exec("--list-modules", "-version")132.shouldContain("java.base")133.shouldNotContain("Runtime Environment")134.shouldHaveExitValue(0);135}136137/**138* java args... returning the OutputAnalyzer to analyzer the output139*/140private OutputAnalyzer exec(String... args) throws Exception {141return ProcessTools.executeTestJava(args)142.outputTo(System.out)143.errorTo(System.out);144}145146}147148149