changeset 13524:43def0e36fb2

Replace remaining launcher shell tests
author alanb
date Sun, 26 Jul 2015 21:16:23 +0100
parents 6627ac63d7ee
children 5f0edb05ac50
files test/jdk/jigsaw/launcher/basic/BasicTest.java test/jdk/jigsaw/launcher/basic/basic.sh test/jdk/jigsaw/launcher/limitmods/LimitModsTest.java test/jdk/jigsaw/launcher/mixedmode/MixedModeTest.java test/jdk/jigsaw/launcher/mixedmode/basic.sh test/jdk/jigsaw/launcher/upgrademodulepath/UpgradeModulePathTest.java test/jdk/jigsaw/launcher/upgrademodulepath/basic.sh
diffstat 7 files changed, 347 insertions(+), 163 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/basic/BasicTest.java	Sun Jul 26 21:16:23 2015 +0100
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library ../../lib /lib/testlibrary
+ * @modules jdk.jlink/jdk.tools.jmod
+ * @build BasicTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng BasicTest
+ * @summary Basic test of starting an application as a module
+ */
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static jdk.testlibrary.ProcessTools.*;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+
+@Test
+public class BasicTest {
+
+    private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
+
+    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 module name of the test module
+    private static final String TEST_MODULE = "test";
+
+    // the module main class
+    private static final String MAIN_CLASS = "jdk.test.Main";
+
+
+    @BeforeTest
+    public void compileTestModule() throws Exception {
+
+        // javac -d mods/$TESTMODULE src/$TESTMODULE/**
+        boolean compiled
+            = CompilerUtils.compile(SRC_DIR.resolve(TEST_MODULE),
+                                    MODS_DIR.resolve(TEST_MODULE));
+
+        assertTrue(compiled, "test module did not compile");
+    }
+
+
+    /**
+     * The initial module is loaded from an exploded module
+     */
+    public void testRunFromExplodedModule() throws Exception {
+        String modulepath = MODS_DIR.toString();
+        String mid = TEST_MODULE + "/" + MAIN_CLASS;
+
+        // java -mp mods -m $TESTMODULE/$MAINCLASS
+        int exitValue
+            = executeTestJava("-mp", modulepath,
+                              "-m", mid)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+    /**
+     * The initial module is loaded from a JMOD file
+     */
+    public void testRunFromJMod() throws Exception {
+        Path dir = Files.createTempDirectory(USER_DIR, "mlib");
+
+        // jmod create --class-path mods/${TESTMODULE} \
+        //     --main-class $MAIN_CLASS mlib/${TESTMODULE}.jmod
+        String cp = MODS_DIR.resolve(TEST_MODULE).toString();
+        String jmod = dir.resolve("m.jmod").toString();
+        String[] args = {
+            "create",
+            "--class-path", cp,
+            "--main-class", MAIN_CLASS,
+            jmod
+        };
+        jdk.tools.jmod.JmodTask task = new jdk.tools.jmod.JmodTask();
+        assertEquals(task.run(args), 0);
+
+        // java -mp mods -m $TESTMODULE
+        int exitValue
+            = executeTestJava("-mp", dir.toString(),
+                              "-m", TEST_MODULE)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+
+    }
+
+    /**
+     * Attempt to run an unknown module
+     */
+    public void testRunWithUnknownModule() throws Exception {
+        String modulepath = MODS_DIR.toString();
+
+        // java -mp mods -m $TESTMODULE
+        int exitValue
+            = executeTestJava("-mp", modulepath,
+                              "-m", "rhubarb")
+                .getExitValue();
+
+        assertTrue(exitValue != 0);
+    }
+
+}
--- a/test/jdk/jigsaw/launcher/basic/basic.sh	Sun Jul 26 14:29:49 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-#
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @summary Basic test of starting an application as a module
-
-set -e
-
-if [ -z "$TESTJAVA" ]; then
-  if [ $# -lt 1 ]; then exit 1; fi
-  TESTJAVA="$1"; shift
-  COMPILEJAVA="${TESTJAVA}"
-  TESTSRC="`pwd`"
-  TESTCLASSES="`pwd`"
-fi
-
-JAVAC="$COMPILEJAVA/bin/javac"
-JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}"
-JMOD="$TESTJAVA/bin/jmod ${TESTTOOLVMOPTS}"
-
-rm -rf mods
-mkdir -p mods/test
-$JAVAC -d mods/test `find $TESTSRC/src/test -name "*.java"`
-
-rm -rf mlib
-mkdir -p mlib
-$JMOD create --class-path mods/test --module-version 1.0 --main-class jdk.test.Main \
-    mlib/test@1.0.jmod 
-
-# specify initial module / main class
-$JAVA -mp mods -m test/jdk.test.Main
-
-# specify initial module by name
-$JAVA -mp mlib -m test
-
-exit 0
--- a/test/jdk/jigsaw/launcher/limitmods/LimitModsTest.java	Sun Jul 26 14:29:49 2015 +0100
+++ b/test/jdk/jigsaw/launcher/limitmods/LimitModsTest.java	Sun Jul 26 21:16:23 2015 +0100
@@ -35,10 +35,10 @@
 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.*;
 
+
 @Test
 public class LimitModsTest {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/mixedmode/MixedModeTest.java	Sun Jul 26 21:16:23 2015 +0100
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library ../../lib /lib/testlibrary
+ * @modules jdk.jlink/jdk.tools.jmod
+ * @build MixedModeTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng MixedModeTest
+ * @summary Test running with both a module path and class path
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static jdk.testlibrary.ProcessTools.*;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+
+@Test
+public class MixedModeTest {
+
+    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 module name of the library module
+    private static final String LIB_MODULE = "lib";
+
+    // application source directory
+    private static final String APP_SRC = "app";
+
+    // application is compiled to classes
+    private static final Path CLASSES_DIR = Paths.get("classes");
+
+    // application main class
+    private static final String MAIN_CLASS = "app.Main";
+
+
+    @BeforeTest
+    public void compile() throws Exception {
+
+        // javac -d mods/$LIB_MODULE src/$LIB_MODULE/**
+        boolean compiled = CompilerUtils.compile(
+            SRC_DIR.resolve(LIB_MODULE),
+            MODS_DIR.resolve(LIB_MODULE)
+        );
+        assertTrue(compiled, "library module did not compile");
+
+        // javac -d classes -mp mods src/$APP_DIR/**
+        compiled = CompilerUtils.compile(
+            SRC_DIR.resolve(APP_SRC),
+            CLASSES_DIR,
+            "-mp", MODS_DIR.toString()
+        );
+        assertTrue(compiled, "app did not compile");
+    }
+
+    /**
+     * Run application on class path that makes use of module on the
+     * application module path. Uses -addmods.
+     */
+    public void runRunInMixedMode() throws Exception {
+
+        // java -mp mods -addmods lib -cp classes app.Main
+        int exitValue
+            = executeTestJava("-mp", MODS_DIR.toString(),
+                              "-addmods", LIB_MODULE,
+                              "-cp", CLASSES_DIR.toString(),
+                              MAIN_CLASS)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+
+    }
+
+    /**
+     * Run application on class path that makes use of module on the
+     * application module path. Does not use -addmods and so will
+     * fail at run-time.
+     */
+    public void runRunInMixedModeWithoutAddMods() throws Exception {
+
+        // java -mp mods -cp classes app.Main
+        int exitValue
+            = executeTestJava("-mp", MODS_DIR.toString(),
+                              "-cp", CLASSES_DIR.toString(),
+                              MAIN_CLASS)
+                .getExitValue();
+
+        // CNFE or other error/exception
+        assertTrue(exitValue != 0);
+
+    }
+
+}
--- a/test/jdk/jigsaw/launcher/mixedmode/basic.sh	Sun Jul 26 14:29:49 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#
-# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @summary Test application on class path making use of library on module path
-
-set -e
-
-if [ -z "$TESTJAVA" ]; then
-  if [ $# -lt 1 ]; then exit 1; fi
-  TESTJAVA="$1"; shift
-  COMPILEJAVA="${TESTJAVA}"
-  TESTSRC="`pwd`"
-  TESTCLASSES="`pwd`"
-fi
-
-JAVAC="$COMPILEJAVA/bin/javac ${TESTTOOLVMOPTS}"
-JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}"
-JLINK="$TESTJAVA/bin/jlink ${TESTTOOLVMOPTS}"
-
-rm -rf mods
-mkdir -p mods/lib
-$JAVAC -d mods/lib `find $TESTSRC/src/lib -name "*.java"`
-
-rm -rf classes
-mkdir -p classes
-$JAVAC -d classes -mp mods `find $TESTSRC/src/app -name "*.java"`
-
-# Run with both a module and class path
-$JAVA -mp mods -addmods lib -cp classes app.Main
-
-exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/upgrademodulepath/UpgradeModulePathTest.java	Sun Jul 26 21:16:23 2015 +0100
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library ../../lib /lib/testlibrary
+ * @build UpgradeModulePathTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng UpgradeModulePathTest
+ * @summary Basic test for java -upgrademodulepath
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static jdk.testlibrary.ProcessTools.executeTestJava;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+
+@Test
+public class UpgradeModulePathTest {
+
+    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 module that is upgraded
+    private static final String UPGRADED_MODULE = "java.annotations.common";
+    private static final Path UPGRADEDMODS_DIR = Paths.get("upgradedmods");
+
+    // the test module
+    private static final String TEST_MODULE = "test";
+    private static final String MAIN_CLASS = "jdk.test.Main";
+
+
+    @BeforeTest
+    public void compileModules() throws Exception {
+
+        // javac -d upgradedmods/$UPGRADED_MODULE src/$UPGRADED_MODULE/**
+        boolean compiled = CompilerUtils.compile(
+            SRC_DIR.resolve(UPGRADED_MODULE),
+            UPGRADEDMODS_DIR.resolve(UPGRADED_MODULE)
+        );
+        assertTrue(compiled, UPGRADED_MODULE + " did not compile");
+
+        // javac -d mods/test -upgradedmodulepath upgradedmods ...
+        compiled = CompilerUtils.compile(
+            SRC_DIR.resolve(TEST_MODULE),
+            MODS_DIR.resolve(TEST_MODULE),
+            "-upgrademodulepath", UPGRADEDMODS_DIR.toString()
+        );
+        assertTrue(compiled, UPGRADED_MODULE + " did not compile");
+    }
+
+    /**
+     * Run the test with an upgraded java.annotations.common module.
+     */
+    public void testWithUpgradedModule() throws Exception {
+
+        String mid = TEST_MODULE + "/" + MAIN_CLASS;
+        int exitValue
+            = executeTestJava(
+                "-upgrademodulepath", UPGRADEDMODS_DIR.toString(),
+                "-mp", MODS_DIR.toString(),
+                "-m", mid)
+            .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+}
--- a/test/jdk/jigsaw/launcher/upgrademodulepath/basic.sh	Sun Jul 26 14:29:49 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-#
-# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @summary Basic test that upgrades/overrides a module linked into
-#          the runtime image
-
-set -e
-
-if [ -z "$TESTJAVA" ]; then
-  if [ $# -lt 1 ]; then exit 1; fi
-  TESTJAVA="$1"; shift
-  COMPILEJAVA="${TESTJAVA}"
-  TESTSRC="`pwd`"
-  TESTCLASSES="`pwd`"
-fi
-
-JAVAC="$COMPILEJAVA/bin/javac"
-JAVA="$TESTJAVA/bin/java ${TESTVMOPTS}"
-
-rm -rf upgradedmods
-mkdir -p upgradedmods/java.annotations.common
-$JAVAC -d upgradedmods/java.annotations.common \
-    `find $TESTSRC/src/java.annotations.common -name "*.java"`
-
-rm -rf appmods
-mkdir -p appmods/test
-$JAVAC -d appmods/test -cp upgradedmods/java.annotations.common \
-    `find $TESTSRC/src/test -name "*.java"`
-
-# Run with upgrade module path
-$JAVA -upgrademodulepath upgradedmods -modulepath appmods -m test/jdk.test.Main
-
-exit 0