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 * @library /lib/testlibrary
27 * @modules jdk.compiler
28 * @build AddExportsTest CompilerUtils jdk.testlibrary.*
29 * @run testng AddExportsTest
30 * @summary Basic tests for java -XaddExports
31 */
32
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35
36 import static jdk.testlibrary.ProcessTools.*;
37
38 import org.testng.annotations.BeforeTest;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41 import static org.testng.Assert.*;
42
43
44 @Test
45 public class AddExportsTest {
46
47 private static final String TEST_SRC = System.getProperty("test.src");
48
49 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
50 private static final Path MODS_DIR = Paths.get("mods");
51 private static final Path UPGRADE_MODS_DIRS = Paths.get("upgrademods");
52
53 // test module m1 that uses Unsafe
54 private static final String TEST1_MODULE = "m1";
131 "-cp", classpath,
132 TEST1_MAIN_CLASS)
133 .outputTo(System.out)
134 .errorTo(System.out)
135 .getExitValue();
136
137 assertTrue(exitValue == 0);
138 }
139
140
141 /**
142 * Run named module that uses jdk.internal.misc.Unsafe
143 */
144 public void testNamedModule() throws Exception {
145
146 // java -XaddExports:java.base/jdk.internal.misc=test \
147 // -mp mods -m $TESTMODULE/$MAIN_CLASS
148
149 String mid = TEST1_MODULE + "/" + TEST1_MAIN_CLASS;
150 int exitValue =
151 executeTestJava("-XaddExports:java.base/jdk.internal.misc=" + TEST1_MODULE,
152 "-mp", MODS_DIR.toString(),
153 "-m", mid)
154 .outputTo(System.out)
155 .errorTo(System.out)
156 .getExitValue();
157
158 assertTrue(exitValue == 0);
159 }
160
161
162 /**
163 * Test -XaddExports with upgraded module
164 */
165 public void testWithUpgradedModule() throws Exception {
166
167 // java -XaddExports:java.transaction/javax.transaction.internal=m2
168 // -upgrademodulepath upgrademods -mp mods -m ...
169 String mid = TEST2_MODULE + "/" + TEST2_MAIN_CLASS;
170 int exitValue = executeTestJava(
171 "-XaddExports:java.transaction/javax.transaction.internal=m2",
172 "-upgrademodulepath", UPGRADE_MODS_DIRS.toString(),
173 "-mp", MODS_DIR.toString(),
174 "-m", mid)
175 .outputTo(System.out)
176 .errorTo(System.out)
177 .getExitValue();
178
179 assertTrue(exitValue == 0);
180 }
181
182
183 /**
184 * Test -XaddExports with module that is added to the set of root modules
185 * with -addmods.
186 */
187 public void testWithAddMods() throws Exception {
188
189 // java -XaddExports:m4/jdk.test4=m3 -mp mods -m ...
190 String mid = TEST3_MODULE + "/" + TEST3_MAIN_CLASS;
191 int exitValue = executeTestJava(
192 "-XaddExports:m4/jdk.test4=m3",
193 "-mp", MODS_DIR.toString(),
194 "-addmods", TEST4_MODULE,
195 "-m", mid)
196 .outputTo(System.out)
197 .errorTo(System.out)
198 .getExitValue();
199
200 assertTrue(exitValue == 0);
201 }
202
203
204 /**
205 * -XaddExports can only be specified once
206 */
207 public void testWithDuplicateOption() throws Exception {
208
209 int exitValue
210 = executeTestJava("-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
211 "-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
212 "-version")
213 .outputTo(System.out)
214 .errorTo(System.out)
215 .shouldContain("specified more than once")
216 .getExitValue();
217
|
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 * @library /lib/testlibrary
27 * @modules jdk.compiler
28 * @build AddExportsTest CompilerUtils jdk.testlibrary.*
29 * @run testng AddExportsTest
30 * @summary Basic tests for java -XaddExports
31 */
32
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.Arrays;
36
37 import static jdk.testlibrary.ProcessTools.*;
38
39 import org.testng.annotations.BeforeTest;
40 import org.testng.annotations.DataProvider;
41 import org.testng.annotations.Test;
42 import static org.testng.Assert.*;
43
44
45 @Test
46 public class AddExportsTest {
47
48 private static final String TEST_SRC = System.getProperty("test.src");
49
50 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
51 private static final Path MODS_DIR = Paths.get("mods");
52 private static final Path UPGRADE_MODS_DIRS = Paths.get("upgrademods");
53
54 // test module m1 that uses Unsafe
55 private static final String TEST1_MODULE = "m1";
132 "-cp", classpath,
133 TEST1_MAIN_CLASS)
134 .outputTo(System.out)
135 .errorTo(System.out)
136 .getExitValue();
137
138 assertTrue(exitValue == 0);
139 }
140
141
142 /**
143 * Run named module that uses jdk.internal.misc.Unsafe
144 */
145 public void testNamedModule() throws Exception {
146
147 // java -XaddExports:java.base/jdk.internal.misc=test \
148 // -mp mods -m $TESTMODULE/$MAIN_CLASS
149
150 String mid = TEST1_MODULE + "/" + TEST1_MAIN_CLASS;
151 int exitValue =
152 executeModularTest(mid, null,
153 Arrays.asList("-XaddExports:java.base/jdk.internal.misc=" + TEST1_MODULE),
154 null, Arrays.asList(MODS_DIR), null)
155 .getExitValue();
156
157 assertTrue(exitValue == 0);
158 }
159
160
161 /**
162 * Test -XaddExports with upgraded module
163 */
164 public void testWithUpgradedModule() throws Exception {
165
166 // java -XaddExports:java.transaction/javax.transaction.internal=m2
167 // -upgrademodulepath upgrademods -mp mods -m ...
168 String mid = TEST2_MODULE + "/" + TEST2_MAIN_CLASS;
169 int exitValue = executeModularTest(mid, null,
170 Arrays.asList("-XaddExports:java.transaction/javax.transaction.internal=m2",
171 "-upgrademodulepath", UPGRADE_MODS_DIRS.toString()),
172 null, Arrays.asList(MODS_DIR), null)
173 .getExitValue();
174
175 assertTrue(exitValue == 0);
176 }
177
178
179 /**
180 * Test -XaddExports with module that is added to the set of root modules
181 * with -addmods.
182 */
183 public void testWithAddMods() throws Exception {
184
185 // java -XaddExports:m4/jdk.test4=m3 -mp mods -m ...
186 String mid = TEST3_MODULE + "/" + TEST3_MAIN_CLASS;
187 int exitValue = executeModularTest(mid, null,
188 Arrays.asList("-XaddExports:m4/jdk.test4=m3"),
189 null, Arrays.asList(MODS_DIR),
190 Arrays.asList(TEST4_MODULE))
191 .getExitValue();
192
193 assertTrue(exitValue == 0);
194 }
195
196
197 /**
198 * -XaddExports can only be specified once
199 */
200 public void testWithDuplicateOption() throws Exception {
201
202 int exitValue
203 = executeTestJava("-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
204 "-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
205 "-version")
206 .outputTo(System.out)
207 .errorTo(System.out)
208 .shouldContain("specified more than once")
209 .getExitValue();
210
|