< prev index next >

test/tools/launcher/modules/addreads/AddReadsTest.java

Print this page

        

@@ -23,20 +23,20 @@
 
 /**
  * @test
  * @library /lib/testlibrary
  * @modules jdk.compiler
- * @build AddReadsTest CompilerUtils JarUtils jdk.testlibrary.*
+ * @build AddReadsTest CompilerUtils JarUtils jdk.testlibrary.tasks.*
  * @run testng AddReadsTest
  * @summary Basic tests for java --add-reads
  */
 
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
-import jdk.testlibrary.OutputAnalyzer;
-import static jdk.testlibrary.ProcessTools.*;
+import jdk.testlibrary.tasks.JavaTask;
+import jdk.testlibrary.tasks.Task;
 
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;

@@ -55,11 +55,12 @@
 
     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
     private static final Path CLASSES_DIR = Paths.get("classes");
     private static final Path MODS_DIR = Paths.get("mods");
 
-    private static final String MAIN = "m1/p.Main";
+    private static final String M1 = "m1";
+    private static final String MAIN = "p.Main";
 
 
     @BeforeTest
     public void setup() throws Exception {
 

@@ -77,128 +78,104 @@
         // jar cf mods/junit.jar -C classes .
         JarUtils.createJarFile(MODS_DIR.resolve("junit.jar"), CLASSES_DIR);
 
     }
 
-    private OutputAnalyzer run(String... options) throws Exception {
-        return executeTestJava(options)
-            .outputTo(System.out)
-            .errorTo(System.out);
-    }
-
-
     /**
      * Run with junit as a module on the module path.
      */
-    public void testJUnitOnModulePath() throws Exception {
-
+    public void testJUnitOnModulePath() {
         // java --module-path mods --add-modules junit --add-reads m1=junit -m ..
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "--add-modules", "junit",
-                  "--add-reads", "m1=junit",
-                  "-m", MAIN)
-                .getExitValue();
-
-        assertTrue(exitValue == 0);
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .addModules("junit")
+            .addReads(M1, "junit")
+            .module(M1, MAIN)
+            .run();
     }
 
 
     /**
      * Exercise --add-reads m1=ALL-UNNAMED by running with junit on the
      * class path.
      */
-    public void testJUnitOnClassPath() throws Exception {
-
+    public void testJUnitOnClassPath() {
         // java --module-path mods -cp mods/junit.jar --add-reads m1=ALL-UNNAMED -m ..
-        String cp = MODS_DIR.resolve("junit.jar").toString();
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "-cp", cp,
-                  "--add-reads", "m1=ALL-UNNAMED",
-                  "-m", MAIN)
-                .getExitValue();
-
-        assertTrue(exitValue == 0);
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .classPath(MODS_DIR.resolve("junit.jar"))
+            .addReads(M1)
+            .module(M1, MAIN)
+            .run();
     }
 
 
     /**
      * Run with junit as a module on the module path but without --add-reads.
      */
-    public void testJUnitOnModulePathMissingAddReads() throws Exception {
+    public void testJUnitOnModulePathMissingAddReads() {
         // java --module-path mods --add-modules junit --module ..
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "--add-modules", "junit",
-                  "--module", MAIN)
-                .shouldContain("IllegalAccessError")
-                .getExitValue();
-
-        assertTrue(exitValue != 0);
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .addModules("junit")
+            .module(M1, MAIN)
+            .run(Task.Expect.FAIL)
+            .shouldContain(Task.OutputKind.STDERR, "IllegalAccessError");
     }
 
 
     /**
      * Run with junit on the class path but without --add-reads.
      */
-    public void testJUnitOnClassPathMissingAddReads() throws Exception {
+    public void testJUnitOnClassPathMissingAddReads() {
         // java --module-path mods -cp mods/junit.jar -m ..
-        String cp = MODS_DIR.resolve("junit.jar").toString();
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "-cp", cp,
-                  "-m", MAIN)
-                .shouldContain("IllegalAccessError")
-                .getExitValue();
-
-        assertTrue(exitValue != 0);
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .classPath(MODS_DIR.resolve("junit.jar"))
+            .module(M1, MAIN)
+            .run(Task.Expect.FAIL)
+            .shouldContain(Task.OutputKind.STDERR, "IllegalAccessError");
     }
 
 
     /**
      * Exercise --add-reads with a more than one source module.
      */
-    public void testJUnitWithMultiValueOption() throws Exception {
-
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "--add-modules", "java.xml,junit",
-                  "--add-reads", "m1=java.xml,junit",
-                  "--module", MAIN)
-                .getExitValue();
-
-        assertTrue(exitValue == 0);
+    public void testJUnitWithMultiValueOption() {
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .addModules("java.xml", "junit")
+            .addReads(M1, "java.xml", "junit")
+            .module(M1, MAIN)
+            .run();
     }
 
 
     /**
      * Exercise --add-reads where the target module is specified more than once
      */
-    public void testWithTargetSpecifiedManyTimes() throws Exception {
-
-        int exitValue
-            = run("--module-path", MODS_DIR.toString(),
-                  "--add-modules", "java.xml,junit",
-                  "--add-reads", "m1=java.xml",
-                  "--add-reads", "m1=junit",
-                  "-m", MAIN)
-                  .shouldContain("specified more than once")
-                 .getExitValue();
-
-        assertTrue(exitValue != 0);
+    public void testWithTargetSpecifiedManyTimes() {
+        new JavaTask()
+            .modulePath(MODS_DIR)
+            .addModules("java.xml", "junit")
+            .addReads(M1, "java.xml")
+            .addReads(M1, "junit")
+            .module(M1, MAIN)
+            .run(Task.Expect.FAIL)
+            .shouldContain(Task.OutputKind.STDOUT, "specified more than once");
     }
 
 
     /**
      * Exercise --add-reads with bad values
      */
     @Test(dataProvider = "badvalues")
-    public void testWithBadValue(String value, String ignore) throws Exception {
-
+    public void testWithBadValue(String value, String ignore) {
         //  --add-exports $VALUE -version
-        assertTrue(run("--add-reads", value, "-version").getExitValue() != 0);
+       new JavaTask()
+            .vmOptions(value, "-version")
+            .run(Task.Expect.FAIL);
     }
 
     @DataProvider(name = "badvalues")
     public Object[][] badValues() {
         return new Object[][]{
< prev index next >