diff -r 18e27ee2276b -r b00cbf427368 test/jdk/tools/jpackage/share/InstallDirTest.java --- a/test/jdk/tools/jpackage/share/InstallDirTest.java Mon Sep 30 20:26:28 2019 -0400 +++ b/test/jdk/tools/jpackage/share/InstallDirTest.java Tue Oct 01 18:22:34 2019 -0400 @@ -29,6 +29,8 @@ import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.PackageType; import jdk.jpackage.test.Functional; +import jdk.jpackage.test.JPackageCommand; +import jdk.jpackage.test.Annotations.Parameter; /** * Test --install-dir parameter. Output of the test should be installdirtest*.* @@ -55,12 +57,26 @@ * @summary jpackage with --install-dir * @library ../helpers * @build jdk.jpackage.test.* + * @compile InstallDirTest.java * @modules jdk.jpackage/jdk.jpackage.internal - * @run main/othervm/timeout=360 -Xmx512m InstallDirTest + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main + * --jpt-run=InstallDirTest.testCommon + */ + +/* + * @test + * @summary jpackage with --install-dir + * @library ../helpers + * @build jdk.jpackage.test.* + * @compile InstallDirTest.java + * @modules jdk.jpackage/jdk.jpackage.internal + * @requires (os.family == "linux") + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main + * --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported */ public class InstallDirTest { - public static void main(String[] args) { + public static void testCommon() { final Map INSTALL_DIRS = Functional.identity(() -> { Map reply = new HashMap<>(); reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234")); @@ -75,12 +91,45 @@ return reply; }).get(); - TKit.run(args, () -> { - new PackageTest().configureHelloApp() - .addInitializer(cmd -> { - cmd.addArguments("--install-dir", INSTALL_DIRS.get( - cmd.packageType())); - }).run(); - }); + new PackageTest().configureHelloApp() + .addInitializer(cmd -> { + cmd.addArguments("--install-dir", INSTALL_DIRS.get( + cmd.packageType())); + }).run(); + } + + @Parameter("/") + @Parameter(".") + @Parameter("foo") + @Parameter("/opt/foo/.././.") + public static void testLinuxInvalid(String installDir) { + testLinuxBad(installDir, "Invalid installation directory"); + } + + @Parameter("/usr") + @Parameter("/usr/local") + @Parameter("/usr/foo") + public static void testLinuxUnsupported(String installDir) { + testLinuxBad(installDir, "currently unsupported"); + } + + private static void testLinuxBad(String installDir, + String errorMessageSubstring) { + new PackageTest().configureHelloApp() + .setExpectedExitCode(1) + .forTypes(PackageType.LINUX) + .addInitializer(cmd -> { + cmd.addArguments("--install-dir", installDir); + cmd.saveConsoleOutput(true); + }) + .addBundleVerifier((cmd, result) -> { + String errorMessage = JPackageCommand.filterOutput(result. + getOutput().stream()).filter(line -> line.contains( + errorMessageSubstring)).findFirst().orElse(null); + TKit.assertNotNull(errorMessage, String.format( + "Check output contains [%s] substring", + errorMessageSubstring)); + }) + .run(); } }