Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/tool/EnablePreviewOption.java
40957 views
1
/*
2
* Copyright (c) 2015, 2018, 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 8199196
27
* @summary Test --enable-preview option in javadoc
28
* @modules jdk.javadoc/jdk.javadoc.internal.tool
29
* @library /tools/lib
30
* @build toolbox.ToolBox toolbox.TestRunner
31
* @run main EnablePreviewOption
32
*/
33
34
import java.io.IOException;
35
import java.io.PrintWriter;
36
import java.io.StringWriter;
37
import java.nio.file.Path;
38
import java.nio.file.Paths;
39
import java.util.ArrayList;
40
import java.util.Arrays;
41
import java.util.List;
42
import java.util.function.Predicate;
43
44
import jdk.javadoc.internal.tool.Main;
45
import jdk.javadoc.internal.tool.Main.Result;
46
47
import static jdk.javadoc.internal.tool.Main.Result.*;
48
49
import toolbox.TestRunner;
50
import toolbox.ToolBox;
51
52
public class EnablePreviewOption extends TestRunner {
53
public static void main(String... args) throws Exception {
54
new EnablePreviewOption().runTests();
55
}
56
57
ToolBox tb = new ToolBox();
58
59
Path file = Paths.get("C.java");
60
String thisVersion = System.getProperty("java.specification.version");
61
String prevVersion = String.valueOf(Integer.valueOf(thisVersion) - 1);
62
63
EnablePreviewOption() throws IOException {
64
super(System.err);
65
tb.writeFile(file, "public class C { }");
66
}
67
68
@Test
69
public void testSource() {
70
runTest(List.of("--enable-preview", "-source", thisVersion),
71
OK,
72
out -> !out.contains("error")
73
&& out.contains("Building tree for all the packages and classes..."));
74
}
75
76
@Test
77
public void testRelease() {
78
runTest(List.of("--enable-preview", "--release", thisVersion),
79
OK,
80
out -> !out.contains("error")
81
&& out.contains("Building tree for all the packages and classes..."));
82
}
83
84
@Test
85
public void testNoVersion() {
86
runTest(List.of("--enable-preview"),
87
CMDERR,
88
out -> out.contains("error: --enable-preview must be used with either -source or --release"));
89
}
90
91
@Test
92
public void testBadSource() {
93
runTest(List.of("--enable-preview", "-source", "BAD"),
94
ERROR,
95
out -> out.contains("error: invalid source release: BAD"));
96
}
97
98
@Test
99
public void testOldSource() {
100
runTest(List.of("--enable-preview", "-source", prevVersion),
101
CMDERR,
102
out -> out.matches("(?s)error: invalid source release .* with --enable-preview.*"));
103
}
104
105
private void runTest(List<String> options, Result expectedResult, Predicate<String> validate) {
106
System.err.println("running with options: " + options);
107
List<String> args = new ArrayList<>();
108
args.addAll(options);
109
args.add("-XDrawDiagnostics");
110
args.add(file.toString());
111
StringWriter out = new StringWriter();
112
PrintWriter pw = new PrintWriter(out);
113
int actualResult = Main.execute(args.toArray(new String[0]), pw);
114
System.err.println("actual result=" + actualResult);
115
System.err.println("actual output=" + out.toString());
116
if (actualResult != expectedResult.exitCode)
117
error("Exit code not as expected");
118
if (!validate.test(out.toString())) {
119
error("Output not as expected");
120
}
121
}
122
}
123
124