test/jdk/tools/launcher/modules/addreads/AddReadsTestWarningError.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45467 jdk/test/tools/launcher/modules/addreads/AddReadsTestWarningError.java@99c87a16a8e4
child 51675 b487c1e914d0
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     1
/*
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     4
 *
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     8
 *
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    13
 * accompanied this code).
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    14
 *
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    18
 *
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    21
 * questions.
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    22
 */
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    23
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    24
/**
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    25
 * @test
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    26
 * @bug 8168836
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    27
 * @summary  Basic argument validation for --add-reads
45191
ba48b1679390 8180724: move ModuleInfoMaker to the top level testlibrary
iignatyev
parents: 44359
diff changeset
    28
 * @library /lib/testlibrary /test/lib
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    29
 * @modules jdk.compiler
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45191
diff changeset
    30
 * @build jdk.test.lib.compiler.ModuleInfoMaker
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45191
diff changeset
    31
 * @build jdk.test.lib.compiler.CompilerUtils
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45191
diff changeset
    32
 * @build jdk.testlibrary.*
45191
ba48b1679390 8180724: move ModuleInfoMaker to the top level testlibrary
iignatyev
parents: 44359
diff changeset
    33
 * @build AddReadsTestWarningError
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    34
 * @run testng AddReadsTestWarningError
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    35
 */
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    36
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    37
import java.io.BufferedOutputStream;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    38
import java.io.ByteArrayOutputStream;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    39
import java.io.PrintStream;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    40
import java.nio.file.Path;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    41
import java.nio.file.Paths;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    42
import java.util.Arrays;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    43
import java.util.stream.Stream;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    44
45191
ba48b1679390 8180724: move ModuleInfoMaker to the top level testlibrary
iignatyev
parents: 44359
diff changeset
    45
import jdk.test.lib.compiler.ModuleInfoMaker;
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    46
import jdk.testlibrary.OutputAnalyzer;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    47
import static jdk.testlibrary.ProcessTools.*;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    48
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    49
import org.testng.annotations.BeforeTest;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    50
import org.testng.annotations.DataProvider;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    51
import org.testng.annotations.Test;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    52
import static org.testng.Assert.*;
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    53
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    54
@Test
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    55
public class AddReadsTestWarningError {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    56
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    57
    private static final Path MODS_DIR = Paths.get("mods");
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    58
    private static final Path SRC_DIR = Paths.get("src");
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    59
    private static final String M1_MAIN = "m1/p1.C1";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    60
    private static final String M4_MAIN = "m4/p4.C4";
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    61
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    62
    @BeforeTest
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    63
    public void setup() throws Exception {
42993
d761de69e27f 8172215: java launcher no longer accepts -cp "" empty string
mchung
parents: 42774
diff changeset
    64
        ModuleInfoMaker builder = new ModuleInfoMaker(SRC_DIR);
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    65
        builder.writeJavaFiles("m1",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    66
            "module m1 { requires m4; }",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    67
            "package p1; public class C1 { " +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    68
            "    public static void main(String... args) {" +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    69
            "        p2.C2 c2 = new p2.C2();" +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    70
            "        p3.C3 c3 = new p3.C3();" +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    71
            "    }" +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    72
            "}"
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    73
        );
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    74
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    75
        builder.writeJavaFiles("m2",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    76
            "module m2 { exports p2; }",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    77
            "package p2; public class C2 { }"
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    78
        );
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    79
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    80
        builder.writeJavaFiles("m3",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    81
            "module m3 { exports p3; }",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    82
            "package p3; public class C3 { }"
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    83
        );
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    84
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    85
        builder.writeJavaFiles("m4",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    86
            "module m4 { requires m2; requires m3; }",
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    87
            "package p4; public class C4 { " +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    88
            "    public static void main(String... args) {}" +
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    89
            "}"
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    90
        );
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    91
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    92
        builder.compile("m2", MODS_DIR);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    93
        builder.compile("m3", MODS_DIR);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    94
        builder.compile("m4", MODS_DIR);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    95
        builder.compile("m1", MODS_DIR, "--add-reads", "m1=m2,m3");
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    96
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    97
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    98
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
    99
    @DataProvider(name = "goodcases")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   100
    public Object[][] goodCases() {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   101
        return new Object[][]{
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   102
            // empty items
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   103
            { "m1=,m2,m3",       null },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   104
            { "m1=m2,,m3",       null },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   105
            { "m1=m2,m3,",       null },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   106
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   107
            // duplicates
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   108
            { "m1=m2,m2,m3,,",  null },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   109
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   110
        };
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   111
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   112
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   113
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   114
    @Test(dataProvider = "goodcases")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   115
    public void test(String value, String ignore) throws Exception {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   116
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   117
        PrintStream ps = new PrintStream(new BufferedOutputStream(baos));
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   118
        OutputAnalyzer outputAnalyzer =
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   119
            executeTestJava("--add-reads", value,
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   120
                            "--module-path", MODS_DIR.toString(),
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   121
                            "-m", M1_MAIN)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   122
                .outputTo(ps)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   123
                .errorTo(ps);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   124
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   125
        assertTrue(outputAnalyzer.getExitValue() == 0);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   126
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   127
        System.out.println(baos.toString());
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   128
        String[] output = baos.toString().split("\\R");
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   129
        assertFalse(Arrays.stream(output)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   130
                          .filter(s -> !s.matches("WARNING: Module name .* may soon be illegal"))
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   131
                          .filter(s -> s.startsWith("WARNING:"))
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   132
                          .findAny().isPresent());
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   133
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   134
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   135
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   136
    @DataProvider(name = "illFormedAddReads")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   137
    public Object[][] illFormedAddReads() {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   138
        return new Object[][]{
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   139
            { "m1",         "Unable to parse --add-reads <module>=<value>: m1" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   140
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   141
            // missing source part
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   142
            { "=m2",        "Unable to parse --add-reads <module>=<value>: =m2" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   143
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   144
            // empty list, missing target
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   145
            { "m1=",        "Unable to parse --add-reads <module>=<value>: m1=" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   146
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   147
            // empty list
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   148
            { "m1=,,",      "Target must be specified: --add-reads m1=,," },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   149
        };
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   150
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   151
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   152
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   153
    @Test(dataProvider = "illFormedAddReads")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   154
    public void testIllFormedAddReads(String value, String msg) throws Exception {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   155
        int exitValue =
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   156
            executeTestJava("--add-reads", value,
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   157
                            "--module-path", MODS_DIR.toString(),
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   158
                            "-m", M4_MAIN)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   159
                .outputTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   160
                .errorTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   161
                .shouldContain(msg)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   162
                .getExitValue();
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   163
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   164
        assertTrue(exitValue != 0);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   165
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   166
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   167
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   168
    @DataProvider(name = "unknownNames")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   169
    public Object[][] unknownNames() {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   170
        return new Object[][]{
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   171
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   172
            // source not found
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42993
diff changeset
   173
            {"DoesNotExist=m2",    "WARNING: Unknown module: DoesNotExist specified to --add-reads"},
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   174
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   175
            // target not found
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42993
diff changeset
   176
            {"m2=DoesNotExist",    "WARNING: Unknown module: DoesNotExist specified to --add-reads"},
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   177
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   178
            // bad names
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42993
diff changeset
   179
            {"m*=m2",              "WARNING: Unknown module: m* specified to --add-reads"},
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 42993
diff changeset
   180
            {"m2=m!",              "WARNING: Unknown module: m! specified to --add-reads"},
42774
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   181
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   182
        };
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   183
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   184
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   185
    @Test(dataProvider = "unknownNames")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   186
    public void testUnknownNames(String value, String msg) throws Exception {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   187
        int exitValue =
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   188
            executeTestJava("--add-reads", value,
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   189
                            "--module-path", MODS_DIR.toString(),
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   190
                            "-m", M4_MAIN)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   191
                .outputTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   192
                .errorTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   193
                .shouldContain(msg)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   194
                .getExitValue();
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   195
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   196
        assertTrue(exitValue == 0);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   197
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   198
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   199
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   200
    @DataProvider(name = "missingArguments")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   201
    public Object[][] missingArguments() {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   202
        return new Object[][]{
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   203
            { new String[] {"--add-reads" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   204
                "Error: --add-reads requires modules to be specified"},
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   205
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   206
            { new String[] { "--add-reads=" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   207
                "Error: --add-reads= requires modules to be specified"},
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   208
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   209
            { new String[] { "--add-reads", "" },
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   210
                "Error: --add-reads requires modules to be specified"},
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   211
        };
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   212
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   213
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   214
    @Test(dataProvider = "missingArguments")
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   215
    public void testEmptyArgument(String[] options, String msg) throws Exception {
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   216
        String[] args = Stream.concat(Arrays.stream(options), Stream.of("-version"))
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   217
                              .toArray(String[]::new);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   218
        int exitValue = executeTestJava(args)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   219
            .outputTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   220
            .errorTo(System.out)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   221
            .shouldContain(msg)
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   222
            .getExitValue();
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   223
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   224
        assertTrue(exitValue != 0);
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   225
    }
74bcf37d15d8 8168836: Minor clean up on warning/error messages on --add-exports and --add-reads
mchung
parents:
diff changeset
   226
}