--- old/test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java 2015-09-21 15:55:52.000000000 -0700 +++ new/test/jdk/jigsaw/scenarios/overlappingpackages/OverlappingPackagesTest.java 2015-09-21 15:55:52.000000000 -0700 @@ -24,14 +24,16 @@ /** * @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 */ +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; @@ -41,6 +43,8 @@ import org.testng.annotations.Test; import static org.testng.Assert.*; +import jdk.testlibrary.OutputAnalyzer; + @Test public class OverlappingPackagesTest { @@ -50,7 +54,11 @@ 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 List modules = Arrays.asList("m1", "m2", "misc", + "test"); + + private static final String DUP_P_MSG = "Package p in both module m2 and " + + "module m1"; /** @@ -85,31 +93,86 @@ * 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); + output.shouldContain(DUP_P_MSG); + 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); + } + /** + * Run the test with "-addmods m1,m2" with one of the modules being + * on the module path and the other one - on the upgrade module path. + * Both modules have package p. + */ + public void testOverlapUpgratePath() throws Exception { + Path upgradePath = Paths.get("up"); + Path dest = upgradePath.resolve("m1"); + Files.createDirectories(upgradePath); + Path src = MODS_DIR.resolve("m1"); + Files.move(src, dest); + try { + OutputAnalyzer output + = executeTestJava("-mp", MODS_DIR.toString(), + "-upgrademodulepath", upgradePath.toString(), + "-addmods", "m1,m2", + "-m", "test/test.Main") + .outputTo(System.out) + .errorTo(System.err); + output.shouldContain(DUP_P_MSG); + assertTrue(output.getExitValue() != 0); + } finally { + Files.move(dest, src); + } + } }