< prev index next >
test/tools/launcher/modules/addreads/AddReadsTest.java
Print this page
*** 23,42 ****
/**
* @test
* @library /lib/testlibrary
* @modules jdk.compiler
! * @build AddReadsTest CompilerUtils JarUtils jdk.testlibrary.*
* @run testng AddReadsTest
* @summary Basic tests for java --add-reads
*/
import java.nio.file.Path;
import java.nio.file.Paths;
! import jdk.testlibrary.OutputAnalyzer;
! 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,42 ----
/**
* @test
* @library /lib/testlibrary
* @modules jdk.compiler
! * @build AddReadsTest CompilerUtils JarUtils jdk.testlibrary.tasks.*
* @run testng AddReadsTest
* @summary Basic tests for java --add-reads
*/
import java.nio.file.Path;
import java.nio.file.Paths;
! 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.*;
*** 55,65 ****
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path CLASSES_DIR = Paths.get("classes");
private static final Path MODS_DIR = Paths.get("mods");
! private static final String MAIN = "m1/p.Main";
@BeforeTest
public void setup() throws Exception {
--- 55,66 ----
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path CLASSES_DIR = Paths.get("classes");
private static final Path MODS_DIR = Paths.get("mods");
! private static final String M1 = "m1";
! private static final String MAIN = "p.Main";
@BeforeTest
public void setup() throws Exception {
*** 77,204 ****
// jar cf mods/junit.jar -C classes .
JarUtils.createJarFile(MODS_DIR.resolve("junit.jar"), CLASSES_DIR);
}
- private OutputAnalyzer run(String... options) throws Exception {
- return executeTestJava(options)
- .outputTo(System.out)
- .errorTo(System.out);
- }
-
-
/**
* Run with junit as a module on the module path.
*/
! public void testJUnitOnModulePath() throws Exception {
!
// java --module-path mods --add-modules junit --add-reads m1=junit -m ..
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "--add-modules", "junit",
! "--add-reads", "m1=junit",
! "-m", MAIN)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Exercise --add-reads m1=ALL-UNNAMED by running with junit on the
* class path.
*/
! public void testJUnitOnClassPath() throws Exception {
!
// java --module-path mods -cp mods/junit.jar --add-reads m1=ALL-UNNAMED -m ..
! String cp = MODS_DIR.resolve("junit.jar").toString();
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "-cp", cp,
! "--add-reads", "m1=ALL-UNNAMED",
! "-m", MAIN)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Run with junit as a module on the module path but without --add-reads.
*/
! public void testJUnitOnModulePathMissingAddReads() throws Exception {
// java --module-path mods --add-modules junit --module ..
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "--add-modules", "junit",
! "--module", MAIN)
! .shouldContain("IllegalAccessError")
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Run with junit on the class path but without --add-reads.
*/
! public void testJUnitOnClassPathMissingAddReads() throws Exception {
// java --module-path mods -cp mods/junit.jar -m ..
! String cp = MODS_DIR.resolve("junit.jar").toString();
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "-cp", cp,
! "-m", MAIN)
! .shouldContain("IllegalAccessError")
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Exercise --add-reads with a more than one source module.
*/
! public void testJUnitWithMultiValueOption() throws Exception {
!
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "--add-modules", "java.xml,junit",
! "--add-reads", "m1=java.xml,junit",
! "--module", MAIN)
! .getExitValue();
!
! assertTrue(exitValue == 0);
}
/**
* Exercise --add-reads where the target module is specified more than once
*/
! public void testWithTargetSpecifiedManyTimes() throws Exception {
!
! int exitValue
! = run("--module-path", MODS_DIR.toString(),
! "--add-modules", "java.xml,junit",
! "--add-reads", "m1=java.xml",
! "--add-reads", "m1=junit",
! "-m", MAIN)
! .shouldContain("specified more than once")
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Exercise --add-reads with bad values
*/
@Test(dataProvider = "badvalues")
! public void testWithBadValue(String value, String ignore) throws Exception {
!
// --add-exports $VALUE -version
! assertTrue(run("--add-reads", value, "-version").getExitValue() != 0);
}
@DataProvider(name = "badvalues")
public Object[][] badValues() {
return new Object[][]{
--- 78,181 ----
// jar cf mods/junit.jar -C classes .
JarUtils.createJarFile(MODS_DIR.resolve("junit.jar"), CLASSES_DIR);
}
/**
* Run with junit as a module on the module path.
*/
! public void testJUnitOnModulePath() {
// java --module-path mods --add-modules junit --add-reads m1=junit -m ..
! new JavaTask()
! .modulePath(MODS_DIR)
! .addModules("junit")
! .addReads(M1, "junit")
! .module(M1, MAIN)
! .run();
}
/**
* Exercise --add-reads m1=ALL-UNNAMED by running with junit on the
* class path.
*/
! public void testJUnitOnClassPath() {
// java --module-path mods -cp mods/junit.jar --add-reads m1=ALL-UNNAMED -m ..
! new JavaTask()
! .modulePath(MODS_DIR)
! .classPath(MODS_DIR.resolve("junit.jar"))
! .addReads(M1)
! .module(M1, MAIN)
! .run();
}
/**
* Run with junit as a module on the module path but without --add-reads.
*/
! public void testJUnitOnModulePathMissingAddReads() {
// java --module-path mods --add-modules junit --module ..
! new JavaTask()
! .modulePath(MODS_DIR)
! .addModules("junit")
! .module(M1, MAIN)
! .run(Task.Expect.FAIL)
! .shouldContain(Task.OutputKind.STDERR, "IllegalAccessError");
}
/**
* Run with junit on the class path but without --add-reads.
*/
! public void testJUnitOnClassPathMissingAddReads() {
// java --module-path mods -cp mods/junit.jar -m ..
! new JavaTask()
! .modulePath(MODS_DIR)
! .classPath(MODS_DIR.resolve("junit.jar"))
! .module(M1, MAIN)
! .run(Task.Expect.FAIL)
! .shouldContain(Task.OutputKind.STDERR, "IllegalAccessError");
}
/**
* Exercise --add-reads with a more than one source module.
*/
! public void testJUnitWithMultiValueOption() {
! new JavaTask()
! .modulePath(MODS_DIR)
! .addModules("java.xml", "junit")
! .addReads(M1, "java.xml", "junit")
! .module(M1, MAIN)
! .run();
}
/**
* Exercise --add-reads where the target module is specified more than once
*/
! public void testWithTargetSpecifiedManyTimes() {
! new JavaTask()
! .modulePath(MODS_DIR)
! .addModules("java.xml", "junit")
! .addReads(M1, "java.xml")
! .addReads(M1, "junit")
! .module(M1, MAIN)
! .run(Task.Expect.FAIL)
! .shouldContain(Task.OutputKind.STDOUT, "specified more than once");
}
/**
* Exercise --add-reads with bad values
*/
@Test(dataProvider = "badvalues")
! public void testWithBadValue(String value, String ignore) {
// --add-exports $VALUE -version
! new JavaTask()
! .vmOptions(value, "-version")
! .run(Task.Expect.FAIL);
}
@DataProvider(name = "badvalues")
public Object[][] badValues() {
return new Object[][]{
< prev index next >