Path: blob/master/test/langtools/tools/jdeps/Options.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* @bug 8168386 820511626* @summary Test option validation27* @modules jdk.jdeps28* @library lib29* @build JdepsRunner30* @run testng Options31*/323334import org.testng.annotations.DataProvider;35import org.testng.annotations.Test;3637import static org.testng.Assert.assertTrue;3839public class Options {40private static final String TEST_CLASSES = System.getProperty("test.classes");4142@DataProvider(name = "errors")43public Object[][] errors() {44return new Object[][]{45{46new String[] { "-summary", "-v", TEST_CLASSES },47"-v, -verbose cannot be used with -s, -summary option"48},49{50new String[] { "-jdkinternal", "-summary", TEST_CLASSES },51"-summary or -verbose cannot be used with -jdkinternals option"52},53{54new String[] { "-jdkinternal", "-p", "java.lang", TEST_CLASSES },55"--package, --regex, --require cannot be used with -jdkinternals option"56},57{58new String[] { "--missing-deps", "-summary", TEST_CLASSES },59"-summary or -verbose cannot be used with --missing-deps option"60},61{62new String[] { "--missing-deps", "-p", "java.lang", TEST_CLASSES },63"--package, --regex, --require cannot be used with --missing-deps option"64},65{66new String[] { "--inverse", TEST_CLASSES },67"--package (-p), --regex (-e), --require option must be specified"68},69{70new String[] { "--inverse", "-R", TEST_CLASSES },71"-R cannot be used with --inverse option"72},73{74new String[] { "--generate-module-info", "dots", "-cp", TEST_CLASSES },75"-classpath cannot be used with --generate-module-info option"76},77{78new String[] { "--list-deps", "-summary", TEST_CLASSES },79"--list-deps and --list-reduced-deps options are specified"80},81{82new String[] { "--list-deps", "--list-reduced-deps", TEST_CLASSES },83"--list-deps and --list-reduced-deps options are specified"84},85};86}8788@Test(dataProvider = "errors")89public void test(String[] options, String expected) {90jdepsError(options).outputContains(expected);91}929394public static JdepsRunner jdepsError(String... args) {95JdepsRunner jdeps = new JdepsRunner(args);96assertTrue(jdeps.run(true) != 0);97return jdeps;98}99100@Test101public void testSystemOption() {102JdepsRunner jdeps;103104// valid path105jdeps = new JdepsRunner("--check", "java.base", "--system", System.getProperty("java.home"));106assertTrue(jdeps.run(true) == 0);107108// invalid path109jdeps = new JdepsRunner("--check", "java.base", "--system", "bad");110assertTrue(jdeps.run(true) != 0);111jdeps.outputContains("invalid path: bad");112}113}114115116