--- old/test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java 2015-10-12 09:04:58.000000000 +0300 +++ new/test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java 2015-10-12 09:04:57.000000000 +0300 @@ -24,16 +24,20 @@ /** * @test * @library ../../lib /lib/testlibrary - * @build OverlappingPackagesTest CompilerUtils + * @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 + * 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.*; @@ -41,6 +45,8 @@ import org.testng.annotations.Test; import static org.testng.Assert.*; +import jdk.testlibrary.OutputAnalyzer; + @Test public class OverlappingPackagesTest { @@ -50,8 +56,8 @@ private static final Path MODS_DIR = Paths.get("mods"); // the names of the modules in this test - private static List modules = Arrays.asList("m1", "m2", "misc", "test"); - + private static final List modules = Arrays.asList("m1", "m2", + "misc", "test"); /** * Compiles all modules used by the test @@ -75,7 +81,6 @@ .outputTo(System.out) .errorTo(System.err) .getExitValue(); - assertTrue(exitValue == 0); } @@ -85,31 +90,64 @@ * sun.misc and so should overlap with the base module. */ public void testOverlapWithBaseModule() throws Exception { - int exitValue + OutputAnalyzer output = executeTestJava("-mp", MODS_DIR.toString(), "-addmods", "misc", "-m", "test/test.Main") .outputTo(System.out) - .errorTo(System.err) - .getExitValue(); - - assertTrue(exitValue != 0); + .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 { - int exitValue + 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); + 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); + } }