jdk/test/tools/launcher/modules/basic/BasicTest.java
author mchung
Wed, 12 Oct 2016 15:41:00 -0700
changeset 41484 834b7539ada3
parent 40261 86a49ba76f52
child 45393 de4e1efc8eec
permissions -rw-r--r--
8164689: Retrofit jar, jlink, jmod as a ToolProvider Reviewed-by: alanb, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
 * @library /lib/testlibrary
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    27
 * @modules jdk.compiler
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    28
 *          jdk.jartool
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    29
 *          jdk.jlink
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 * @build BasicTest CompilerUtils jdk.testlibrary.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
 * @run testng BasicTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @summary Basic test of starting an application as a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.io.File;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Paths;
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    39
import java.util.spi.ToolProvider;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    41
import jdk.testlibrary.ProcessTools;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
public class BasicTest {
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    50
    private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    51
        .orElseThrow(() ->
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    52
            new RuntimeException("jar tool not found")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    53
        );
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    54
    private static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    55
        .orElseThrow(() ->
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    56
            new RuntimeException("jmod tool not found")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    57
        );
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final Path USER_DIR = Paths.get(System.getProperty("user.dir"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    // the module name of the test module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    private static final String TEST_MODULE = "test";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    // the module main class
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    private static final String MAIN_CLASS = "jdk.test.Main";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
    public void compileTestModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        // javac -d mods/$TESTMODULE src/$TESTMODULE/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        boolean compiled
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            = CompilerUtils.compile(SRC_DIR.resolve(TEST_MODULE),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
                                    MODS_DIR.resolve(TEST_MODULE));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        assertTrue(compiled, "test module did not compile");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    84
    /**
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    85
     * Execute "java" with the given arguments, returning the exit code.
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    86
     */
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    87
    private int exec(String... args) throws Exception {
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    88
       return ProcessTools.executeTestJava(args)
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    89
                .outputTo(System.out)
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    90
                .errorTo(System.out)
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    91
                .getExitValue();
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    92
    }
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    93
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
     * The initial module is loaded from an exploded module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    public void testRunWithExplodedModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        String dir = MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        String subdir = MODS_DIR.resolve(TEST_MODULE).toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        String mid = TEST_MODULE + "/" + MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   103
        // java --module-path mods -module $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   104
        int exitValue = exec("--module-path", dir, "--module", mid);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   105
        assertTrue(exitValue == 0);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   106
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   107
        // java --module-path mods/$TESTMODULE --module $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   108
        exitValue = exec("--module-path", subdir, "--module", mid);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   111
        // java --module-path=mods --module=$TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   112
        exitValue = exec("--module-path=" + dir, "--module=" + mid);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   113
        assertTrue(exitValue == 0);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   114
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   115
        // java --module-path=mods/$TESTMODULE --module=$TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   116
        exitValue = exec("--module-path=" + subdir, "--module=" + mid);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   117
        assertTrue(exitValue == 0);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   118
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   119
        // java -p mods -m $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   120
        exitValue = exec("-p", dir, "-m", mid);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   121
        assertTrue(exitValue == 0);
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   122
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   123
        // java -p mods/$TESTMODULE -m $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   124
        exitValue = exec("-p", subdir, "-m", mid);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
     * The initial module is loaded from a modular JAR file
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    public void testRunWithModularJar() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        Path dir = Files.createTempDirectory(USER_DIR, "mlib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        Path jar = dir.resolve("m.jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        // jar --create ...
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        String classes = MODS_DIR.resolve(TEST_MODULE).toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        String[] args = {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
            "--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
            "--file=" + jar,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
            "--main-class=" + MAIN_CLASS,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
            "-C", classes, "."
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
        };
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   144
        int rc = JAR_TOOL.run(System.out, System.out, args);
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   145
        assertTrue(rc == 0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   147
        // java --module-path mlib -module $TESTMODULE
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   148
        int exitValue = exec("--module-path", dir.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   149
                             "--module", TEST_MODULE);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   152
        // java --module-path mlib/m.jar -module $TESTMODULE
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   153
        exitValue = exec("--module-path", jar.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   154
                         "--module", TEST_MODULE);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
     * Attempt to run with the initial module packaged as a JMOD file.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
    public void testTryRunWithJMod() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        Path dir = Files.createTempDirectory(USER_DIR, "mlib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        // jmod create ...
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        String cp = MODS_DIR.resolve(TEST_MODULE).toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        String jmod = dir.resolve("m.jmod").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        String[] args = {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            "create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            "--main-class", MAIN_CLASS,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
            jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        };
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   174
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   175
        assertEquals(JMOD_TOOL.run(System.out, System.out, args), 0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   177
        // java --module-path mods --module $TESTMODULE
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   178
        int exitValue = exec("--module-path", dir.toString(),
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   179
                             "--module", TEST_MODULE);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
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
     * Run the test with a non-existent file on the application module path.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
     * It should be silently ignored.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
    public void testRunWithNonExistentEntry() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        String mp = "DoesNotExist" + File.pathSeparator + MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        String mid = TEST_MODULE + "/" + MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   192
        // java --module-path mods --module $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   193
        int exitValue = exec("--module-path", mp, "--module", mid);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
     * Attempt to run an unknown initial module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    public void testTryRunWithBadModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        String modulepath = MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   204
        // java --module-path mods -m $TESTMODULE
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   205
        int exitValue = exec("--module-path", modulepath, "-m", "rhubarb");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
     * Attempt to run with -m specifying a main class that does not
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
     * exist.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
    public void testTryRunWithBadMainClass() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        String modulepath = MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        String mid = TEST_MODULE + "/p.rhubarb";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   218
        // java --module-path mods -m $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   219
        int exitValue = exec("--module-path", modulepath, "-m", mid);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
     * Attempt to run with -m specifying a modular JAR that does not have
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
     * a MainClass attribute
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    public void testTryRunWithMissingMainClass() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        Path dir = Files.createTempDirectory(USER_DIR, "mlib");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        // jar --create ...
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
        String classes = MODS_DIR.resolve(TEST_MODULE).toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
        String jar = dir.resolve("m.jar").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
        String[] args = {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            "--create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            "--file=" + jar,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            "-C", classes, "."
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        };
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   239
        int rc = JAR_TOOL.run(System.out, System.out, args);
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   240
        assertTrue(rc == 0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   242
        // java --module-path mods -m $TESTMODULE
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   243
        int exitValue = exec("--module-path", dir.toString(), "-m", TEST_MODULE);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
     * Attempt to run with -m specifying a main class that is a different
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
     * module to that specified to -m
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
    public void testTryRunWithMainClassInWrongModule() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
        String modulepath = MODS_DIR.toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        String mid = "java.base/" + MAIN_CLASS;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   256
        // java --module-path mods --module $TESTMODULE/$MAINCLASS
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
   257
        int exitValue = exec("--module-path", modulepath, "--module", mid);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
        assertTrue(exitValue != 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
}