42277
|
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 8164316
|
|
27 |
* @summary tests the example used in package-info.java and doclet options.
|
|
28 |
* @modules
|
|
29 |
* jdk.javadoc/jdk.javadoc.internal.api
|
|
30 |
* jdk.javadoc/jdk.javadoc.internal.tool
|
|
31 |
* jdk.compiler/com.sun.tools.javac.api
|
|
32 |
* jdk.compiler/com.sun.tools.javac.main
|
|
33 |
* @library /tools/lib
|
|
34 |
* @build toolbox.ToolBox toolbox.TestRunner Example
|
|
35 |
* @run main Tester
|
|
36 |
*/
|
|
37 |
|
|
38 |
import java.io.File;
|
|
39 |
import java.util.Arrays;
|
|
40 |
import java.util.ArrayList;
|
|
41 |
import java.util.List;
|
|
42 |
|
|
43 |
import toolbox.*;
|
|
44 |
import toolbox.Task.Expect;
|
|
45 |
|
|
46 |
import static toolbox.Task.OutputKind.*;
|
|
47 |
|
|
48 |
public class Tester extends TestRunner {
|
|
49 |
final ToolBox tb;
|
|
50 |
final File testFile;
|
|
51 |
final File testSrc;
|
|
52 |
final Class<?> docletClass;
|
|
53 |
final static String OV_FN = "overview.html";
|
|
54 |
|
|
55 |
Tester() {
|
|
56 |
super(System.err);
|
|
57 |
testSrc = new File(System.getProperty("test.src"));
|
|
58 |
testFile = new File(testSrc, "Example.java");
|
|
59 |
tb = new ToolBox();
|
|
60 |
ClassLoader cl = Tester.class.getClassLoader();
|
|
61 |
try {
|
|
62 |
docletClass = cl.loadClass("Example");
|
|
63 |
} catch (ClassNotFoundException cfe) {
|
|
64 |
throw new Error(cfe);
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
public static void main(String... args) throws Exception {
|
|
69 |
new Tester().runTests();
|
|
70 |
}
|
|
71 |
|
|
72 |
private Task.Result execTask(String... extraArgs) {
|
|
73 |
return execTask(false, extraArgs);
|
|
74 |
}
|
|
75 |
|
|
76 |
private Task.Result execTask(boolean isNegative, String... extraArgs) {
|
|
77 |
JavadocTask et = new JavadocTask(tb, Task.Mode.API);
|
|
78 |
et.docletClass(docletClass);
|
|
79 |
List<String> args = new ArrayList<>();
|
|
80 |
args.add("-sourcepath");
|
|
81 |
args.add(testSrc.getAbsolutePath());
|
|
82 |
args.add(testFile.getAbsolutePath());
|
|
83 |
args.addAll(Arrays.asList(extraArgs));
|
|
84 |
//args.forEach((a -> System.err.println("arg: " + a)));
|
|
85 |
System.err.println(Arrays.asList(extraArgs));
|
|
86 |
Task.Result result = isNegative
|
|
87 |
? et.options(args).run(Expect.FAIL)
|
|
88 |
: et.options(args).run();
|
|
89 |
return result;
|
|
90 |
}
|
|
91 |
|
|
92 |
void assertPresence(String regex, List<String> output) throws Exception {
|
|
93 |
List<String> foundList = tb.grep(regex, output);
|
|
94 |
if (foundList.isEmpty()) {
|
|
95 |
throw new Exception("Not found, expected: " + regex);
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
@Test
|
|
100 |
public void testOption() throws Exception {
|
|
101 |
Task.Result result = execTask("-overviewfile", OV_FN);
|
|
102 |
assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));
|
|
103 |
}
|
|
104 |
|
|
105 |
@Test
|
|
106 |
public void testOptionAlias() throws Exception {
|
|
107 |
Task.Result result = execTask("-overview-file", OV_FN);
|
|
108 |
assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));
|
|
109 |
}
|
|
110 |
|
|
111 |
@Test
|
|
112 |
public void testOptionAliasDoubleDash() throws Exception {
|
|
113 |
Task.Result result = execTask("--over-view-file", OV_FN);
|
|
114 |
assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));
|
|
115 |
}
|
|
116 |
}
|