jdk/test/tools/launcher/modules/addexports/AddExportsTest.java
author iignatyev
Tue, 06 Jun 2017 19:54:08 -0700
changeset 45393 de4e1efc8eec
parent 42338 a60f280f803c
child 45944 882cea808912
permissions -rw-r--r--
8181335: remove packageless CompilerUtils Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    26
 * @library /lib/testlibrary /test/lib
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
 * @modules jdk.compiler
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    28
 * @build AddExportsTest jdk.test.lib.compiler.CompilerUtils jdk.testlibrary.*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @run testng AddExportsTest
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
    30
 * @summary Basic tests for java --add-exports
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.nio.file.Paths;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    35
import java.util.stream.Stream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    37
import jdk.test.lib.compiler.CompilerUtils;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
    38
import jdk.testlibrary.OutputAnalyzer;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import static jdk.testlibrary.ProcessTools.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import org.testng.annotations.DataProvider;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
public class AddExportsTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private static final Path UPGRADE_MODS_DIRS = Paths.get("upgrademods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    // test module m1 that uses Unsafe
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    private static final String TEST1_MODULE = "m1";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    private static final String TEST1_MAIN_CLASS = "jdk.test1.Main";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    // test module m2 uses java.transaction internals
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String TEST2_MODULE = "m2";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    private static final String TEST2_MAIN_CLASS = "jdk.test2.Main";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    // test module m3 uses m4 internals
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    private static final String TEST3_MODULE = "m3";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    private static final String TEST3_MAIN_CLASS = "jdk.test3.Main";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    private static final String TEST4_MODULE = "m4";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    public void compileTestModules() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        // javac -d mods/m1 src/m1/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        boolean compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
                SRC_DIR.resolve(TEST1_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
                MODS_DIR.resolve(TEST1_MODULE),
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
    77
                "--add-exports", "java.base/jdk.internal.misc=m1");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        assertTrue(compiled, "module " + TEST1_MODULE + " did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        // javac -d upgrademods/java.transaction src/java.transaction/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
                SRC_DIR.resolve("java.transaction"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
                UPGRADE_MODS_DIRS.resolve("java.transaction"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        assertTrue(compiled, "module java.transaction did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
    86
        // javac --upgrade-module-path upgrademods -d mods/m2 src/m2/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                SRC_DIR.resolve(TEST2_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                MODS_DIR.resolve(TEST2_MODULE),
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
    90
                "--upgrade-module-path", UPGRADE_MODS_DIRS.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
    91
                "--add-exports", "java.transaction/javax.transaction.internal=m2");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        assertTrue(compiled, "module " + TEST2_MODULE + " did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        // javac -d mods/m3 src/m3/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                SRC_DIR.resolve(TEST3_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                MODS_DIR.resolve(TEST3_MODULE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        assertTrue(compiled, "module " + TEST3_MODULE + " did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        // javac -d mods/m4 src/m4/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        compiled = CompilerUtils.compile(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
                SRC_DIR.resolve(TEST4_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                MODS_DIR.resolve(TEST4_MODULE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        assertTrue(compiled, "module " + TEST4_MODULE + " did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
     * Sanity check with -version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    public void testSanity() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        int exitValue
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   113
            =  executeTestJava("--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
                               "-version")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
    /**
36966
4209c9e19c45 8153737: Unsupported Module
chegar
parents: 36511
diff changeset
   124
     * Run class path application that uses jdk.internal.misc.Unsafe
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    public void testUnnamedModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   128
        // java --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        //      -cp mods/$TESTMODULE jdk.test.UsesUnsafe
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        String classpath = MODS_DIR.resolve(TEST1_MODULE).toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        int exitValue
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   133
            = executeTestJava("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
                              "-cp", classpath,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                              TEST1_MAIN_CLASS)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    /**
36966
4209c9e19c45 8153737: Unsupported Module
chegar
parents: 36511
diff changeset
   145
     * Run named module that uses jdk.internal.misc.Unsafe
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    public void testNamedModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   149
        //  java --add-exports java.base/jdk.internal.misc=test \
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   150
        //       --module-path mods -m $TESTMODULE/$MAIN_CLASS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        String mid = TEST1_MODULE + "/" + TEST1_MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        int exitValue =
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   154
            executeTestJava("--add-exports", "java.base/jdk.internal.misc=" + TEST1_MODULE,
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   155
                            "--module-path", MODS_DIR.toString(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                            "-m", mid)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   166
     * Test --add-exports with upgraded module
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    public void testWithUpgradedModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   170
        // java --add-exports java.transaction/javax.transaction.internal=m2
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   171
        //      --upgrade-module-path upgrademods --module-path mods -m ...
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        String mid = TEST2_MODULE + "/" + TEST2_MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        int exitValue = executeTestJava(
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   174
                "--add-exports", "java.transaction/javax.transaction.internal=m2",
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   175
                "--upgrade-module-path", UPGRADE_MODS_DIRS.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   176
                "--module-path", MODS_DIR.toString(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                "-m", mid)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
    /**
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   187
     * Test --add-exports with module that is added to the set of root modules
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   188
     * with --add-modules.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    public void testWithAddMods() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   192
        // java --add-exports m4/jdk.test4=m3 --module-path mods -m ...
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        String mid = TEST3_MODULE + "/" + TEST3_MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        int exitValue = executeTestJava(
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   195
                "--add-exports", "m4/jdk.test4=m3",
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   196
                "--module-path", MODS_DIR.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   197
                "--add-modules", TEST4_MODULE,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
                "-m", mid)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   208
     * --add-exports and --add-opens allows duplicates
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    public void testWithDuplicateOption() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        int exitValue
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   213
            =  executeTestJava("--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 37363
diff changeset
   214
                               "--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   215
                               "--add-opens", "java.base/java.util=ALL-UNNAMED",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   216
                               "--add-opens", "java.base/java.util=ALL-UNNAMED",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                               "-version")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   222
        assertTrue(exitValue == 0);
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   223
    }
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   224
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   225
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   226
    private OutputAnalyzer execJava(String... options) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   227
        try {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   228
            return executeTestJava(options);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   229
        } catch (Exception e) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   230
            throw new Error(e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   231
        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   232
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   233
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   234
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   235
     * Exercise --add-exports and --add-opens with unknown values.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   236
     * Warning is emitted.
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   237
     */
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   238
    @Test(dataProvider = "unknownvalues")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   239
    public void testWithUnknownValue(String value, String ignore) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   240
        Stream.of("--add-exports", "--add-opens")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   241
            .forEach(option -> {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   242
                //  --add-exports $VALUE -version
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   243
                int exitValue = execJava(option, value, "-version")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   244
                    .stderrShouldMatch("WARNING: .*.monkey.*")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   245
                    .outputTo(System.out)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   246
                    .errorTo(System.out)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   247
                    .getExitValue();
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   248
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   249
                assertTrue(exitValue == 0);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   250
            });
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   251
    }
41414
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   252
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   253
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   254
    @DataProvider(name = "unknownvalues")
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   255
    public Object[][] unknownValues() {
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   256
        return new Object[][]{
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   257
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   258
            { "java.base/jdk.internal.misc=sun.monkey", null }, // unknown target
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   259
            { "java.monkey/sun.monkey=ALL-UNNAMED",     null }, // unknown module
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   260
            { "java.base/sun.monkey=ALL-UNNAMED",       null }, // unknown package
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   261
            { "java.monkey/sun.monkey=ALL-UNNAMED",     null }, // unknown module/package
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   262
7fd4548e9733 8162401: Support multiple --add-exports and --add-reads with the same module/package
mchung
parents: 40261
diff changeset
   263
        };
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   268
     * Exercise --add-exports and --add-opens with bad values
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
    @Test(dataProvider = "badvalues")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   271
    public void testWithBadValue(String value, String ignore) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   272
        Stream.of("--add-exports", "--add-opens")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   273
            .forEach(option -> {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   274
                //  --add-exports $VALUE -version
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   275
                int exitValue = execJava(option, value, "-version")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   276
                    .outputTo(System.out)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   277
                    .errorTo(System.out)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   278
                    .getExitValue();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        assertTrue(exitValue != 0);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41414
diff changeset
   281
            });
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
    @DataProvider(name = "badvalues")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
    public Object[][] badValues() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        return new Object[][]{
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
36966
4209c9e19c45 8153737: Unsupported Module
chegar
parents: 36511
diff changeset
   288
            { "java.base/jdk.internal.misc",            null }, // missing target
4209c9e19c45 8153737: Unsupported Module
chegar
parents: 36511
diff changeset
   289
            { "java.base=ALL-UNNAMED",                  null }, // missing package
4209c9e19c45 8153737: Unsupported Module
chegar
parents: 36511
diff changeset
   290
            { "java.base/=ALL-UNNAMED",                 null }  // missing package
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
}