1/*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 8168386
27 * @summary Test option validation
28 * @modules jdk.jdeps
29 * @library lib
30 * @build JdepsRunner
31 * @run testng Options
32 */
33
34
35import org.testng.annotations.DataProvider;
36import org.testng.annotations.Test;
37
38import static org.testng.Assert.assertTrue;
39
40public class Options {
41    private static final String TEST_CLASSES = System.getProperty("test.classes");
42
43    @DataProvider(name = "errors")
44    public Object[][] errors() {
45        return new Object[][]{
46            {
47                new String[] { "-summary", "-v", TEST_CLASSES },
48                "-v, -verbose cannot be used with -s, -summary option"
49            },
50            {
51                new String[] { "-jdkinternal", "-summary", TEST_CLASSES },
52                "-summary or -verbose cannot be used with -jdkinternals option"
53            },
54            {
55                new String[] { "-jdkinternal", "-p", "java.lang", TEST_CLASSES },
56                "--package, --regex, --require cannot be used with  -jdkinternals option"
57            },
58            {
59                new String[] { "--inverse", TEST_CLASSES },
60                "--package (-p), --regex (-e), --require option must be specified"
61            },
62            {
63                new String[] { "--inverse", "-R", TEST_CLASSES },
64                "-R cannot be used with --inverse option"
65            },
66            {
67                new String[] { "--generate-module-info", "dots", "-cp", TEST_CLASSES },
68                "-classpath cannot be used with --generate-module-info option"
69            },
70            {
71                new String[] { "--list-deps", "-summary", TEST_CLASSES },
72                "--list-deps and --list-reduced-deps options are specified"
73            },
74            {
75                new String[] { "--list-deps", "--list-reduced-deps", TEST_CLASSES },
76                "--list-deps and --list-reduced-deps options are specified"
77            },
78        };
79    }
80
81    @Test(dataProvider = "errors")
82    public void test(String[] options, String expected) {
83        jdepsError(options).outputContains(expected);
84    }
85
86
87    public static JdepsRunner jdepsError(String... args) {
88        JdepsRunner jdeps = new JdepsRunner(args);
89        assertTrue(jdeps.run(true) != 0);
90        return jdeps;
91    }
92}
93