changeset 13523:6627ac63d7ee

Replace two launcher shell tests
author alanb
date Sun, 26 Jul 2015 14:29:49 +0100
parents 3a0dcb0595da
children 43def0e36fb2
files test/jdk/jigsaw/launcher/addexports/AddExportsTest.java test/jdk/jigsaw/launcher/addexports/basic.sh test/jdk/jigsaw/launcher/limitmods/LimitModsTest.java test/jdk/jigsaw/launcher/limitmods/basic.sh test/jdk/jigsaw/launcher/limitmods/src/test/jdk/test/UseAWT.java
diffstat 5 files changed, 249 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/addexports/AddExportsTest.java	Sun Jul 26 14:29:49 2015 +0100
@@ -0,0 +1,136 @@
+/*
+ * 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 AddExportsTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng AddExportsTest
+ * @summary Basic tests for java -XaddExports
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+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 AddExportsTest {
+
+    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.UsesUnsafe";
+
+
+    @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),
+                                    "-XaddExports:java.base/sun.misc=test");
+
+        assertTrue(compiled, "test module did not compile");
+    }
+
+
+    /**
+     * Run class path application that uses sun.misc.Unsafe
+     */
+    public void testUnnamedModule() throws Exception {
+
+        // java -XaddExports:java.base/sun.misc=ALL-UNNAMED \
+        //      -cp mods/$TESTMODULE jdk.test.UsesUnsafe
+
+        String classpath = MODS_DIR.resolve(TEST_MODULE).toString();
+        int exitValue
+            = executeTestJava("-XaddExports:java.base/sun.misc=ALL-UNNAMED",
+                              "-cp", classpath,
+                              MAIN_CLASS)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+
+    /**
+     * Run named module that uses sun.misc.Unsafe
+     */
+    public void testNamedModule() throws Exception {
+
+        //  java -XaddExports:java.base/sun.misc=test \
+        //       -mp mods -m $TESTMODULE/$MAIN_CLASS
+
+        String mid = TEST_MODULE + "/" + MAIN_CLASS;
+        int exitValue =
+            executeTestJava("-XaddExports:java.base/sun.misc=" + TEST_MODULE,
+                            "-mp", MODS_DIR.toString(),
+                            "-m", mid)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+
+    /**
+     * Exercise -XaddExports with bad values
+     */
+    @Test(dataProvider = "badvalues")
+    public void testWithBadValue(String value, String ignore) throws Exception {
+
+        //  -XaddExports:$VALUE -cp mods/test jdk.test.UsesUnsafe
+        String classpath = MODS_DIR.resolve(TEST_MODULE).toString();
+        int exitValue =
+            executeTestJava("-XaddExports:" + value,
+                            "-cp", classpath,
+                            MAIN_CLASS)
+                .getExitValue();
+
+        assertTrue(exitValue != 0);
+    }
+
+    @DataProvider(name = "badvalues")
+    public Object[][] badValues() {
+        return new Object[][]{
+
+            { "java.base/sun.misc,java.monkey/sun.monkey", null }, // unknown module
+            { "java.base/sun.misc,java.base/sun.monkey",   null }, // unknown package
+            { "java.base/sun.misc,java.base",              null }  // missing package
+
+        };
+    }
+}
\ No newline at end of file
--- a/test/jdk/jigsaw/launcher/addexports/basic.sh	Sun Jul 26 12:13:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-#
-# 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
-# @summary Basic test of -XaddExports to export JDK-internal APIs
-
-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 mods
-mkdir -p mods/test
-$JAVAC -XaddExports:java.base/sun.misc=test -d mods/test \
-    `find $TESTSRC/src/test -name "*.java"`
-
-# unnamed module using sun.misc.Unsafe
-$JAVA -XaddExports:java.base/sun.misc=ALL-UNNAMED -cp mods/test jdk.test.UsesUnsafe
-
-# named module using sun.misc.Unsafe
-$JAVA -XaddExports:java.base/sun.misc=test -mp mods -m test/jdk.test.UsesUnsafe
-
-
-# Negative tests
-
-set +e
-failures=0
-
-go() {
-  sh -xc "$JAVA $*" 2>&1
-  if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
-}
-
-# unknown module
-go -XaddExports:java.base/sun.misc,java.monkey/sun.monkey -cp mods/test jdk.test.UsesUnsafe
-
-# unknown package
-go -XaddExports:java.base/sun.misc,java.base/sun.monkey -cp mods/test jdk.test.UsesUnsafe
-
-# missing package
-go -XaddExports:java.base/sun.misc,java.base -cp mods/test jdk.test.UsesUnsafe
-
-echo ''
-if [ $failures -ne 3 ]; then
-  echo "$failures cases failed, expected 3"
-  exit 1
-else
-  echo "Failures as expected"
-  exit 0
-fi 
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/limitmods/LimitModsTest.java	Sun Jul 26 14:29:49 2015 +0100
@@ -0,0 +1,111 @@
+/*
+ * 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 LimitModsTest CompilerUtils jdk.testlibrary.ProcessTools
+ * @run testng LimitModsTest
+ * @summary Basic tests for java -limitmods
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+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 {
+
+    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.UseAWT";
+
+
+    @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");
+    }
+
+    /**
+     * Run class path application with -limitmods
+     */
+    public void testUnnamedModule() throws Exception {
+        String classpath = MODS_DIR.resolve(TEST_MODULE).toString();
+
+        // java -limitmods java.base -cp mods/$TESTMODULE ...
+        int exitValue1
+            = executeTestJava("-limitmods", "java.base",
+                              "-cp", classpath,
+                              MAIN_CLASS)
+                .getExitValue();
+
+        assertTrue(exitValue1 != 0);
+
+
+        // java -limitmods java.base -cp mods/$TESTMODULE ...
+        int exitValue2
+            = executeTestJava("-limitmods", "java.desktop",
+                              "-cp", classpath,
+                             MAIN_CLASS)
+                .getExitValue();
+
+        assertTrue(exitValue2 == 0);
+    }
+
+    /**
+     * Run named module with -limitmods
+     */
+    public void testNamedModule() throws Exception {
+        String modulepath = MODS_DIR.toString();
+        String mid = TEST_MODULE + "/" + MAIN_CLASS;
+
+        // java -limitmods java.base -mp mods -m $TESTMODULE/$MAINCLASS
+        int exitValue
+            = executeTestJava("-limitmods", "java.base",
+                              "-mp", modulepath,
+                              "-m", mid)
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+}
--- a/test/jdk/jigsaw/launcher/limitmods/basic.sh	Sun Jul 26 12:13:07 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +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 launcher -limitmods option
-# @run shell basic.sh
-
-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}"
-
-mkdir -p mods/test
-$JAVAC -d mods/test `find $TESTSRC/src/test -name "*.java"`
-
-# -classpath && -limitmods
-$JAVA -limitmods java.desktop -cp mods/test jdk.test.UseAWT expect-pass
-$JAVA -limitmods java.base -cp mods/test jdk.test.UseAWT expect-fail
-
-# -limitmods and -m
-$JAVA -limitmods java.base -mp mods -m test/jdk.test.UseAWT expect-pass
-
-exit 0
--- a/test/jdk/jigsaw/launcher/limitmods/src/test/jdk/test/UseAWT.java	Sun Jul 26 12:13:07 2015 +0100
+++ b/test/jdk/jigsaw/launcher/limitmods/src/test/jdk/test/UseAWT.java	Sun Jul 26 14:29:49 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -23,23 +23,10 @@
 
 package jdk.test;
 
-import java.net.URL;
 import java.awt.Component;
-import java.lang.reflect.Module;
 
 public class UseAWT {
     public static void main(String[] args) {
-        boolean expectFail = args[0].equals("expect-fail");
-        boolean expectPass = args[0].equals("expect-pass");
-        if (expectFail == expectPass)
-            throw new RuntimeException("Need to run with expect-* argument");
-
-        // test class loading
-        try {
-            Class<?> c = Component.class;
-            if (expectFail) throw new RuntimeException("No Error thrown");
-        } catch (NoClassDefFoundError e) {
-            if (expectPass) throw new RuntimeException(e);
-        }
+        System.out.println(java.awt.Component.class);
     }
 }