Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/modules/addreads/AddReadsTestWarningError.java
41155 views
1
/*
2
* Copyright (c) 2016, 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 8168836
27
* @summary Basic argument validation for --add-reads
28
* @library /test/lib
29
* @modules jdk.compiler
30
* @build jdk.test.lib.compiler.ModuleInfoMaker
31
* @build jdk.test.lib.compiler.CompilerUtils
32
* @build AddReadsTestWarningError
33
* @run testng AddReadsTestWarningError
34
*/
35
36
import java.io.BufferedOutputStream;
37
import java.io.ByteArrayOutputStream;
38
import java.io.PrintStream;
39
import java.nio.file.Path;
40
import java.nio.file.Paths;
41
import java.util.Arrays;
42
import java.util.stream.Stream;
43
44
import jdk.test.lib.compiler.ModuleInfoMaker;
45
import jdk.test.lib.process.OutputAnalyzer;
46
import static jdk.test.lib.process.ProcessTools.*;
47
48
import org.testng.annotations.BeforeTest;
49
import org.testng.annotations.DataProvider;
50
import org.testng.annotations.Test;
51
import static org.testng.Assert.*;
52
53
@Test
54
public class AddReadsTestWarningError {
55
56
private static final Path MODS_DIR = Paths.get("mods");
57
private static final Path SRC_DIR = Paths.get("src");
58
private static final String M1_MAIN = "m1/p1.C1";
59
private static final String M4_MAIN = "m4/p4.C4";
60
61
@BeforeTest
62
public void setup() throws Exception {
63
ModuleInfoMaker builder = new ModuleInfoMaker(SRC_DIR);
64
builder.writeJavaFiles("m1",
65
"module m1 { requires m4; }",
66
"package p1; public class C1 { " +
67
" public static void main(String... args) {" +
68
" p2.C2 c2 = new p2.C2();" +
69
" p3.C3 c3 = new p3.C3();" +
70
" }" +
71
"}"
72
);
73
74
builder.writeJavaFiles("m2",
75
"module m2 { exports p2; }",
76
"package p2; public class C2 { }"
77
);
78
79
builder.writeJavaFiles("m3",
80
"module m3 { exports p3; }",
81
"package p3; public class C3 { }"
82
);
83
84
builder.writeJavaFiles("m4",
85
"module m4 { requires m2; requires m3; }",
86
"package p4; public class C4 { " +
87
" public static void main(String... args) {}" +
88
"}"
89
);
90
91
builder.compile("m2", MODS_DIR);
92
builder.compile("m3", MODS_DIR);
93
builder.compile("m4", MODS_DIR);
94
builder.compile("m1", MODS_DIR, "--add-reads", "m1=m2,m3");
95
}
96
97
98
@DataProvider(name = "goodcases")
99
public Object[][] goodCases() {
100
return new Object[][]{
101
// empty items
102
{ "m1=,m2,m3", null },
103
{ "m1=m2,,m3", null },
104
{ "m1=m2,m3,", null },
105
106
// duplicates
107
{ "m1=m2,m2,m3,,", null },
108
109
};
110
}
111
112
113
@Test(dataProvider = "goodcases")
114
public void test(String value, String ignore) throws Exception {
115
ByteArrayOutputStream baos = new ByteArrayOutputStream();
116
PrintStream ps = new PrintStream(new BufferedOutputStream(baos));
117
OutputAnalyzer outputAnalyzer =
118
executeTestJava("--add-reads", value,
119
"--module-path", MODS_DIR.toString(),
120
"-m", M1_MAIN)
121
.outputTo(ps)
122
.errorTo(ps);
123
124
assertTrue(outputAnalyzer.getExitValue() == 0);
125
126
System.out.println(baos.toString());
127
String[] output = baos.toString().split("\\R");
128
assertFalse(Arrays.stream(output)
129
.filter(s -> !s.matches("WARNING: Module name .* may soon be illegal"))
130
.filter(s -> s.startsWith("WARNING:"))
131
.findAny().isPresent());
132
}
133
134
135
@DataProvider(name = "illFormedAddReads")
136
public Object[][] illFormedAddReads() {
137
return new Object[][]{
138
{ "m1", "Unable to parse --add-reads <module>=<value>: m1" },
139
140
// missing source part
141
{ "=m2", "Unable to parse --add-reads <module>=<value>: =m2" },
142
143
// empty list, missing target
144
{ "m1=", "Unable to parse --add-reads <module>=<value>: m1=" },
145
146
// empty list
147
{ "m1=,,", "Target must be specified: --add-reads m1=,," },
148
};
149
}
150
151
152
@Test(dataProvider = "illFormedAddReads")
153
public void testIllFormedAddReads(String value, String msg) throws Exception {
154
int exitValue =
155
executeTestJava("--add-reads", value,
156
"--module-path", MODS_DIR.toString(),
157
"-m", M4_MAIN)
158
.outputTo(System.out)
159
.errorTo(System.out)
160
.shouldContain(msg)
161
.getExitValue();
162
163
assertTrue(exitValue != 0);
164
}
165
166
167
@DataProvider(name = "unknownNames")
168
public Object[][] unknownNames() {
169
return new Object[][]{
170
171
// source not found
172
{"DoesNotExist=m2", "WARNING: Unknown module: DoesNotExist specified to --add-reads"},
173
174
// target not found
175
{"m2=DoesNotExist", "WARNING: Unknown module: DoesNotExist specified to --add-reads"},
176
177
// bad names
178
{"m*=m2", "WARNING: Unknown module: m* specified to --add-reads"},
179
{"m2=m!", "WARNING: Unknown module: m! specified to --add-reads"},
180
181
};
182
}
183
184
@Test(dataProvider = "unknownNames")
185
public void testUnknownNames(String value, String msg) throws Exception {
186
int exitValue =
187
executeTestJava("--add-reads", value,
188
"--module-path", MODS_DIR.toString(),
189
"-m", M4_MAIN)
190
.outputTo(System.out)
191
.errorTo(System.out)
192
.shouldContain(msg)
193
.getExitValue();
194
195
assertTrue(exitValue == 0);
196
}
197
198
199
@DataProvider(name = "missingArguments")
200
public Object[][] missingArguments() {
201
return new Object[][]{
202
{ new String[] {"--add-reads" },
203
"Error: --add-reads requires modules to be specified"},
204
205
{ new String[] { "--add-reads=" },
206
"Error: --add-reads= requires modules to be specified"},
207
208
{ new String[] { "--add-reads", "" },
209
"Error: --add-reads requires modules to be specified"},
210
};
211
}
212
213
@Test(dataProvider = "missingArguments")
214
public void testEmptyArgument(String[] options, String msg) throws Exception {
215
String[] args = Stream.concat(Arrays.stream(options), Stream.of("-version"))
216
.toArray(String[]::new);
217
int exitValue = executeTestJava(args)
218
.outputTo(System.out)
219
.errorTo(System.out)
220
.shouldContain(msg)
221
.getExitValue();
222
223
assertTrue(exitValue != 0);
224
}
225
}
226
227