< prev index next >
test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java
Print this page
*** 22,59 ****
*/
/**
* @test
* @library ../../lib /lib/testlibrary
! * @build OverlappingPackagesTest CompilerUtils
* @run testng OverlappingPackagesTest
* @summary Basic test to ensure that startup fails if two or more modules
! * in the boot Layer have the same package
*/
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
@Test
public class OverlappingPackagesTest {
private static final String TEST_SRC = System.getProperty("test.src");
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path MODS_DIR = Paths.get("mods");
// the names of the modules in this test
! private static List<String> modules = Arrays.asList("m1", "m2", "misc", "test");
!
/**
* Compiles all modules used by the test
*/
@BeforeTest
--- 22,65 ----
*/
/**
* @test
* @library ../../lib /lib/testlibrary
! * @build OverlappingPackagesTest CompilerUtils jdk.testlibrary.OutputAnalyzer
* @run testng OverlappingPackagesTest
* @summary Basic test to ensure that startup fails if two or more modules
! * in the boot Layer have the same package. Startup is not supposed
! * to fail if there is a package name duplication with/on the unnamed
! * module.
*/
+ import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
+ import java.util.regex.Pattern;
import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
+ import jdk.testlibrary.OutputAnalyzer;
+
@Test
public class OverlappingPackagesTest {
private static final String TEST_SRC = System.getProperty("test.src");
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
private static final Path MODS_DIR = Paths.get("mods");
// the names of the modules in this test
! private static final List<String> modules = Arrays.asList("m1", "m2",
! "misc", "test");
/**
* Compiles all modules used by the test
*/
@BeforeTest
*** 73,115 ****
= executeTestJava("-mp", MODS_DIR.toString(),
"-m", "test/test.Main")
.outputTo(System.out)
.errorTo(System.err)
.getExitValue();
-
assertTrue(exitValue == 0);
}
/**
* Run the test with "-addmods misc", the misc module has package
* sun.misc and so should overlap with the base module.
*/
public void testOverlapWithBaseModule() throws Exception {
! int exitValue
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "misc",
"-m", "test/test.Main")
.outputTo(System.out)
! .errorTo(System.err)
! .getExitValue();
!
! assertTrue(exitValue != 0);
}
/**
* Run the test with "-addmods m1,m2". Both modules have package p.
*/
public void testOverlap() throws Exception {
! int exitValue
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "m1,m2",
"-m", "test/test.Main")
.outputTo(System.out)
.errorTo(System.err)
.getExitValue();
!
! assertTrue(exitValue != 0);
}
!
}
--- 79,153 ----
= executeTestJava("-mp", MODS_DIR.toString(),
"-m", "test/test.Main")
.outputTo(System.out)
.errorTo(System.err)
.getExitValue();
assertTrue(exitValue == 0);
}
/**
* Run the test with "-addmods misc", the misc module has package
* sun.misc and so should overlap with the base module.
*/
public void testOverlapWithBaseModule() throws Exception {
! OutputAnalyzer output
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "misc",
"-m", "test/test.Main")
.outputTo(System.out)
! .errorTo(System.err);
! output.shouldContain("Module misc contains package sun.misc, " +
! "module java.base exports package sun.misc to misc");
! assertTrue(output.getExitValue() != 0);
}
/**
* Run the test with "-addmods m1,m2". Both modules have package p.
*/
public void testOverlap() throws Exception {
! OutputAnalyzer output
= executeTestJava("-mp", MODS_DIR.toString(),
"-addmods", "m1,m2",
"-m", "test/test.Main")
.outputTo(System.out)
+ .errorTo(System.err);
+ String errorText = "Package p in both module m. and module m.";
+ if(!Pattern.compile(errorText).matcher(output.getOutput()).find()) {
+ fail("Output does not contain expected error: \"" +
+ errorText + "\"");
+ }
+ assertTrue(output.getExitValue() != 0);
+ }
+
+ /**
+ * Run the test with m1 being on the modulepath. m1 module has package p.
+ * Package p is also present on the classpath.
+ */
+ public void testOverlapWithClasspath() throws Exception {
+ int exitValue
+ = executeTestJava("-mp", MODS_DIR.toString(),
+ "-classpath", MODS_DIR.resolve("m1").toString(),
+ "-addmods", "m2",
+ "-m", "test/test.Main")
+ .outputTo(System.out)
.errorTo(System.err)
.getExitValue();
! assertTrue(exitValue == 0);
}
! /**
! * Run with package p present two times on the classpath.
! */
! public void testOverlapWithDupsOnClasspath() throws Exception {
! String cp = MODS_DIR.resolve("m1").toString() + File.pathSeparator +
! MODS_DIR.resolve("m2");
! int exitValue
! = executeTestJava("-mp", MODS_DIR.toString(),
! "-classpath", cp,
! "-m", "test/test.Main")
! .outputTo(System.out)
! .errorTo(System.err)
! .getExitValue();
! assertTrue(exitValue == 0);
! }
}
< prev index next >