< prev index next >
test/tools/launcher/modules/addexports/AddExportsTest.java
Print this page
*** 23,41 ****
/**
* @test
* @library /lib/testlibrary
* @modules jdk.compiler
! * @build AddExportsTest CompilerUtils jdk.testlibrary.*
* @run testng AddExportsTest
* @summary Basic tests for java --add-exports
*/
import java.nio.file.Path;
import java.nio.file.Paths;
import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
--- 23,43 ----
/**
* @test
* @library /lib/testlibrary
* @modules jdk.compiler
! * @build AddExportsTest CompilerUtils jdk.testlibrary.* jdk.testlibrary.tasks.JavaTask
* @run testng AddExportsTest
* @summary Basic tests for java --add-exports
*/
import java.nio.file.Path;
import java.nio.file.Paths;
import static jdk.testlibrary.ProcessTools.*;
+ import jdk.testlibrary.tasks.JavaTask;
+ import jdk.testlibrary.tasks.Task;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
*** 103,121 ****
/**
* Sanity check with -version
*/
public void testSanity() throws Exception {
!
! int exitValue
! = executeTestJava("--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
! "-version")
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Run class path application that uses jdk.internal.misc.Unsafe
--- 105,118 ----
/**
* Sanity check with -version
*/
public void testSanity() throws Exception {
! new JavaTask()
! .addExports("java.base/jdk.internal.reflect=ALL-UNNAMED")
! .vmOptions("-version")
! .run();
}
/**
* Run class path application that uses jdk.internal.misc.Unsafe
*** 123,142 ****
public void testUnnamedModule() throws Exception {
// java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
// -cp mods/$TESTMODULE jdk.test.UsesUnsafe
! String classpath = MODS_DIR.resolve(TEST1_MODULE).toString();
! int exitValue
! = executeTestJava("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
! "-cp", classpath,
! TEST1_MAIN_CLASS)
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Run named module that uses jdk.internal.misc.Unsafe
--- 120,135 ----
public void testUnnamedModule() throws Exception {
// java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
// -cp mods/$TESTMODULE jdk.test.UsesUnsafe
! new JavaTask()
! .addExports("java.base/jdk.internal.misc=ALL-UNNAMED")
! .vmOptions("-version")
! .classpath(MODS_DIR.resolve(TEST1_MODULE).toString())
! .className(TEST1_MAIN_CLASS)
! .run();
}
/**
* Run named module that uses jdk.internal.misc.Unsafe
*** 144,241 ****
public void testNamedModule() throws Exception {
// java --add-exports java.base/jdk.internal.misc=test \
// --module-path mods -m $TESTMODULE/$MAIN_CLASS
! String mid = TEST1_MODULE + "/" + TEST1_MAIN_CLASS;
! int exitValue =
! executeTestJava("--add-exports", "java.base/jdk.internal.misc=" + TEST1_MODULE,
! "--module-path", MODS_DIR.toString(),
! "-m", mid)
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Test --add-exports with upgraded module
*/
public void testWithUpgradedModule() throws Exception {
// java --add-exports java.transaction/javax.transaction.internal=m2
// --upgrade-module-path upgrademods --module-path mods -m ...
! String mid = TEST2_MODULE + "/" + TEST2_MAIN_CLASS;
! int exitValue = executeTestJava(
! "--add-exports", "java.transaction/javax.transaction.internal=m2",
! "--upgrade-module-path", UPGRADE_MODS_DIRS.toString(),
! "--module-path", MODS_DIR.toString(),
! "-m", mid)
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Test --add-exports with module that is added to the set of root modules
* with --add-modules.
*/
public void testWithAddMods() throws Exception {
// java --add-exports m4/jdk.test4=m3 --module-path mods -m ...
! String mid = TEST3_MODULE + "/" + TEST3_MAIN_CLASS;
! int exitValue = executeTestJava(
! "--add-exports", "m4/jdk.test4=m3",
! "--module-path", MODS_DIR.toString(),
! "--add-modules", TEST4_MODULE,
! "-m", mid)
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* --add-exports can only be specified once
*/
public void testWithDuplicateOption() throws Exception {
!
! int exitValue
! = executeTestJava("--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
"-version")
! .outputTo(System.out)
! .errorTo(System.out)
! .shouldContain("specified more than once")
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Exercise --add-exports with bad values
*/
@Test(dataProvider = "badvalues")
public void testWithBadValue(String value, String ignore) throws Exception {
-
// --add-exports $VALUE -version
! int exitValue =
! executeTestJava("--add-exports", value,
! "-version")
! .outputTo(System.out)
! .errorTo(System.out)
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
@DataProvider(name = "badvalues")
public Object[][] badValues() {
return new Object[][]{
--- 137,208 ----
public void testNamedModule() throws Exception {
// java --add-exports java.base/jdk.internal.misc=test \
// --module-path mods -m $TESTMODULE/$MAIN_CLASS
! new JavaTask()
! .addExports("java.base/jdk.internal.misc=" + TEST1_MODULE)
! .modulepath(MODS_DIR.toString())
! .moduleName(TEST1_MODULE).className(TEST1_MAIN_CLASS)
! .run();
}
/**
* Test --add-exports with upgraded module
*/
public void testWithUpgradedModule() throws Exception {
// java --add-exports java.transaction/javax.transaction.internal=m2
// --upgrade-module-path upgrademods --module-path mods -m ...
! new JavaTask().ignoreStandardModuleOptions()
! .addExports("java.transaction/javax.transaction.internal=m2")
! .vmOptions("--upgrade-module-path", UPGRADE_MODS_DIRS.toString())
! .modulepath(MODS_DIR.toString())
! .moduleName(TEST2_MODULE).className(TEST2_MAIN_CLASS)
! .run();
}
/**
* Test --add-exports with module that is added to the set of root modules
* with --add-modules.
*/
public void testWithAddMods() throws Exception {
// java --add-exports m4/jdk.test4=m3 --module-path mods -m ...
! new JavaTask().ignoreStandardModuleOptions()
! .addExports("m4/jdk.test4=m3").addModules(TEST4_MODULE)
! .modulepath(MODS_DIR.toString())
! .moduleName(TEST3_MODULE).className(TEST3_MAIN_CLASS)
! .run();
}
/**
* --add-exports can only be specified once
*/
public void testWithDuplicateOption() throws Exception {
! new JavaTask()
! .vmOptions(
! "--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
"--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
"-version")
! .run(Task.Expect.FAIL);
}
/**
* Exercise --add-exports with bad values
*/
@Test(dataProvider = "badvalues")
public void testWithBadValue(String value, String ignore) throws Exception {
// --add-exports $VALUE -version
! new JavaTask()
! .addExports(value)
! .vmOptions("-version")
! .run(Task.Expect.FAIL);
}
@DataProvider(name = "badvalues")
public Object[][] badValues() {
return new Object[][]{
< prev index next >