AllDefaultTest.java revision 3778:f6ae0686d664
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 0000000
27 * @summary Test use of ALL-DEFAULT token
28 * @library /tools/lib
29 * @modules
30 *      jdk.compiler/com.sun.tools.javac.api
31 *      jdk.compiler/com.sun.tools.javac.main
32 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavaTask ModuleTestBase
33 * @run main AllDefaultTest
34 */
35
36import java.nio.file.Path;
37
38import toolbox.JavacTask;
39import toolbox.Task;
40
41public class AllDefaultTest extends ModuleTestBase {
42    public static void main(String... args) throws Exception {
43        AllDefaultTest t = new AllDefaultTest();
44        t.runTests();
45    }
46
47    @Test
48    public void testCompileTime_notAllowed(Path base) throws Exception {
49        tb.writeJavaFiles(base, "class C { }");
50        String out = new JavacTask(tb)
51                .options("-XDrawDiagnostics",
52                        "--add-modules=ALL-DEFAULT")
53                .files(tb.findJavaFiles(base))
54                .run(Task.Expect.FAIL)
55                .writeAll()
56                .getOutput(Task.OutputKind.DIRECT);
57
58        if (!out.contains("- compiler.err.bad.name.for.option: --add-modules, ALL-DEFAULT")) {
59            error("expected text not found");
60        }
61    }
62
63    @Test
64    public void testRuntimeTime_ignored_1(Path base) throws Exception {
65        tb.writeJavaFiles(base, "class C { }");
66        new JavacTask(tb, Task.Mode.EXEC)
67                .options("-XDrawDiagnostics",
68                        "-J--add-modules=ALL-DEFAULT",
69                        "--inherit-runtime-environment")
70                .files(tb.findJavaFiles(base))
71                .run()
72                .writeAll();
73    }
74
75    @Test
76    public void testRuntimeTime_ignored_2(Path base) throws Exception {
77        tb.writeJavaFiles(base, "class C { }");
78        new JavacTask(tb, Task.Mode.EXEC)
79                .options("-XDrawDiagnostics",
80                        "-J--add-modules=jdk.compiler",
81                        "--inherit-runtime-environment")
82                .files(tb.findJavaFiles(base))
83                .run()
84                .writeAll();
85    }
86}
87