test/jdk/tools/jmod/JmodNegativeTest.java
author gadams
Tue, 09 Jan 2018 13:58:30 -0500
changeset 48629 a58c1924e037
parent 47216 71c04702a3d5
child 50428 8c88df2e8a78
permissions -rw-r--r--
6640188: Methods com.cun.attach.VirtualMachine.load... don't throw NullPointerxception Reviewed-by: sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/**
45286
cd809e28c082 8180887: move FileUtils to top level testlibrary
iignatyev
parents: 42468
diff changeset
     2
 * Copyright (c) 2015, 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: 45286
diff changeset
    26
 * @library /test/lib
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.jlink
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 45286
diff changeset
    29
 * @build jdk.test.lib.compiler.CompilerUtils
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45393
diff changeset
    30
 *        jdk.test.lib.util.FileUtils
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 45393
diff changeset
    31
 *        jdk.test.lib.Platform
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
 * @run testng JmodNegativeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
 * @summary Negative tests for jmod
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.io.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.nio.file.Files;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.util.function.Consumer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.util.function.Supplier;
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    44
import java.util.spi.ToolProvider;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import java.util.zip.ZipOutputStream;
45286
cd809e28c082 8180887: move FileUtils to top level testlibrary
iignatyev
parents: 42468
diff changeset
    46
import jdk.test.lib.util.FileUtils;
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 45286
diff changeset
    47
import jdk.test.lib.compiler.CompilerUtils;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import org.testng.annotations.DataProvider;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
import static java.io.File.pathSeparator;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import static java.nio.charset.StandardCharsets.UTF_8;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
import static org.testng.Assert.assertTrue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
public class JmodNegativeTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    58
    static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    59
        .orElseThrow(() ->
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    60
            new RuntimeException("jmod tool not found")
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    61
        );
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
    62
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    static final String TEST_SRC = System.getProperty("test.src", ".");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    static final Path EXPLODED_DIR = Paths.get("build");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    static final Path MODS_DIR = Paths.get("jmods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    public void buildExplodedModules() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        if (Files.exists(EXPLODED_DIR))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
            Path dir = EXPLODED_DIR.resolve(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            assertTrue(compileModule(name, dir.resolve("classes")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        if (Files.exists(MODS_DIR))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
            FileUtils.deleteFileTreeWithRetry(MODS_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        Files.createDirectories(MODS_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    public void testNoArgs() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        jmod()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            .resultChecker(r ->
42468
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 41484
diff changeset
    88
                assertContains(r.output, "Error: one of create, extract, list, describe, or hash must be specified")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    public void testBadAction() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
        jmod("badAction")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            .resultChecker(r ->
42468
7a9555a7e080 8166568: Add jmod extract subcommand
chegar
parents: 41484
diff changeset
    97
                assertContains(r.output, "Error: mode must be one of create, extract, list, describe, or hash")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        jmod("--badOption")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
                assertContains(r.output, "Error: 'badOption' is not a recognized option")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
            );
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    public void testTooManyArgs() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        Path jmod = MODS_DIR.resolve("doesNotExist.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
             jmod.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
             "AAA")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
                assertContains(r.output, "Error: unknown option(s): [AAA]")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    public void testCreateNoArgs() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        jmod("create")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                assertContains(r.output, "Error: jmod-file must be specified")
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
    public void testListNoArgs() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        jmod("list")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                assertContains(r.output, "Error: jmod-file must be specified")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    public void testListFileDoesNotExist() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        Path jmod = MODS_DIR.resolve("doesNotExist.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        jmod("list",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                assertContains(r.output, "Error: no jmod file found: "
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
                        + jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    public void testListJmodIsDir() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        Path jmod = MODS_DIR.resolve("testListJmodIsDir.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        if (Files.notExists(jmod))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            Files.createDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        jmod("list",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                assertContains(r.output, "Error: error opening jmod file")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    public void testlistJmodMalformed() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        Path jmod = MODS_DIR.resolve("testlistJmodMalformed.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
        if (Files.notExists(jmod))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            Files.createFile(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
        jmod("list",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
                assertContains(r.output, "Error: error opening jmod file")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    @Test
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   182
    public void testHashModulesModulePathNotSpecified() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        jmod("create",
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   184
             "--hash-modules", "anyPattern.*",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
             "output.jmod")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                assertContains(r.output, "Error: --module-path must be "
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   189
                        +"specified when hashing modules")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
    public void testCreateJmodAlreadyExists() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
        Path jmod = MODS_DIR.resolve("testCreateJmodAlreadyExists.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        if (Files.notExists(jmod))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            Files.createFile(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
             "--class-path", Paths.get(".").toString(), // anything that exists
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
                assertContains(r.output, "Error: file already exists: " + jmod.toString())
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    public void testCreateJmodIsDir() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        Path jmod = MODS_DIR.resolve("testCreateJmodAlreadyExists");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        if (Files.notExists(jmod))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            Files.createDirectory(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
             "--class-path", Paths.get(".").toString(), // anything that exists
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
                assertContains(r.output, "Error: file already exists: " + jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
            );
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
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
    public void testInvalidModuleVersion() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Path jmod = MODS_DIR.resolve("testEmptyModuleVersion.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
        for (String version : new String[] { "", "NOT_A_VALID_VERSION" }) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                 "--class-path", cp,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                 "--module-version", version,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                 jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
                    assertContains(r.output, "Error: invalid module version")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
                );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
    public void testEmptyFileInClasspath() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
        Path jmod = MODS_DIR.resolve("testEmptyFileInClasspath.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
        Path jar = MODS_DIR.resolve("NotARealJar_Empty.jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
        FileUtils.deleteFileIfExistsWithRetry(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
        Files.createFile(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
             "--class-path", jar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
                assertContains(r.output, "Error: module-info.class not found")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
    public void testEmptyJarInClasspath() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
        Path jmod = MODS_DIR.resolve("testEmptyJarInClasspath.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
        Path jar = MODS_DIR.resolve("empty.jar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
        FileUtils.deleteFileIfExistsWithRetry(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
        try (FileOutputStream fos = new FileOutputStream(jar.toFile());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
             ZipOutputStream zos = new ZipOutputStream(fos)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            // empty
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
             "--class-path", jar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                assertContains(r.output, "Error: module-info.class not found")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
    public void testModuleInfoNotFound() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
        Path jar = MODS_DIR.resolve("empty");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
        FileUtils.deleteFileIfExistsWithRetry(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
        Files.createDirectory(jar);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
             "--class-path", jar.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
                assertContains(r.output, "Error: module-info.class not found")
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
    public void testModuleInfoIsDir() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   299
        Path cp = MODS_DIR.resolve("module-info.class");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   300
        FileUtils.deleteFileIfExistsWithRetry(cp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   301
        Files.createDirectory(cp);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   302
        Files.createFile(cp.resolve("nada.txt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
             "--class-path", cp.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   307
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   309
                assertContains(r.output, "Error: module-info.class not found")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   310
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   311
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   312
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   313
    @Test
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   314
    public void testNoModuleHash() throws IOException {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
        Path emptyDir = Paths.get("empty");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
        if (Files.exists(emptyDir))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
            FileUtils.deleteFileTreeWithRetry(emptyDir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
        Files.createDirectory(emptyDir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
        String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   322
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
        jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
             "--class-path", cp,
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   325
             "--hash-modules", ".*",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   326
             "--module-path", emptyDir.toString(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
            jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   328
            .resultChecker(r ->
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   329
                assertContains(r.output, "No hashes recorded: " +
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   330
                    "no module specified for hashing depends on foo")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
    public void testEmptyFileInModulePath() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   336
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        Path empty = MODS_DIR.resolve("emptyFile.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        FileUtils.deleteFileIfExistsWithRetry(empty);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
        Files.createFile(empty);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
            String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
            jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   345
                 "--class-path", cp,
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   346
                 "--hash-modules", ".*",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   347
                 "--module-path", MODS_DIR.toString(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
                 jmod.toString())
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   349
                .assertFailure();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
            FileUtils.deleteFileWithRetry(empty);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
    public void testFileInModulePath() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   357
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
        Path file = MODS_DIR.resolve("testFileInModulePath.txt");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
        FileUtils.deleteFileIfExistsWithRetry(file);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
        Files.createFile(file);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        jmod("create",
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   364
             "--hash-modules", ".*",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   365
             "--module-path", file.toString(),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
             jmod.toString())
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
            .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
            .resultChecker(r ->
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
                assertContains(r.output, "Error: path must be a directory")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
            );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   372
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
    @DataProvider(name = "pathDoesNotExist")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
    public Object[][] pathDoesNotExist() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
        FileUtils.deleteFileIfExistsWithRetry(Paths.get("doesNotExist"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
        List<Supplier<JmodResult>> tasks = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                () -> jmod("create",
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   381
                           "--hash-modules", "anyPattern",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   382
                           "--module-path", "doesNotExist",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                           "--class-path", "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
                           "--class-path", "doesNotExist.jar",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   391
                           "--cmds", "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   392
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                           "--config", "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   396
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
                           "--libs", "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                           "output.jmod") );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
        String errMsg = "Error: path not found: doesNotExist";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   401
        return tasks.stream().map(t -> new Object[] {t, errMsg} )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
                             .toArray(Object[][]::new);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
    @Test(dataProvider = "pathDoesNotExist")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
    public void testPathDoesNotExist(Supplier<JmodResult> supplier,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
                                     String errMsg)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
        supplier.get()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
                .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
                .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   412
                    assertContains(r.output, errMsg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
                });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   415
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    @DataProvider(name = "partOfPathDoesNotExist")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
    public Object[][] partOfPathDoesNotExist() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   420
        FileUtils.deleteFileIfExistsWithRetry(Paths.get("doesNotExist"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   421
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
        Path emptyDir = Paths.get("empty");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   423
        if (Files.exists(emptyDir))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   424
            FileUtils.deleteFileTreeWithRetry(emptyDir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   425
        Files.createDirectory(emptyDir);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   426
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   427
        List<Supplier<JmodResult>> tasks = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
            () -> jmod("create",
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   429
                       "--hash-modules", "anyPattern",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   430
                       "--module-path","empty" + pathSeparator + "doesNotExist",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   431
                       "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
            () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   433
                       "--class-path", "empty" + pathSeparator + "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
                       "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   435
            () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   436
                       "--class-path", "empty" + pathSeparator + "doesNotExist.jar",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   437
                       "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   438
            () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   439
                       "--cmds", "empty" + pathSeparator + "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   440
                       "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   441
            () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
                       "--config", "empty" + pathSeparator + "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
                       "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
            () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                       "--libs", "empty" + pathSeparator + "doesNotExist",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
                       "output.jmod") );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
        String errMsg = "Error: path not found: doesNotExist";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
        return tasks.stream().map(t -> new Object[] {t, errMsg} )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
                             .toArray(Object[][]::new);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
    @Test(dataProvider = "partOfPathDoesNotExist")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   454
    public void testPartOfPathNotExist(Supplier<JmodResult> supplier,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                                       String errMsg)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
        supplier.get()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
                .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   459
                .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
                    assertContains(r.output, errMsg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
                });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
    @DataProvider(name = "pathIsFile")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
    public Object[][] pathIsFile() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
        Path jmod = MODS_DIR.resolve("output.jmod");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
        FileUtils.deleteFileIfExistsWithRetry(jmod);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
        Path aFile = Paths.get("aFile.txt");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
        if (Files.exists(aFile) && !Files.isRegularFile(aFile))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
            throw new InternalError("Unexpected file:" + aFile);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
        else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
            Files.createFile(aFile);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
        List<Supplier<JmodResult>> tasks = Arrays.asList(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
                           "--class-path", "aFile.txt",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
                () -> jmod("create",
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39882
diff changeset
   479
                           "--module-path", "aFile.txt",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   481
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   482
                           "--cmds", "aFile.txt",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   483
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   485
                           "--config", "aFile.txt",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   486
                           "output.jmod"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   487
                () -> jmod("create",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   488
                           "--libs", "aFile.txt",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
                           "output.jmod") );
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   490
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   491
        String errMsg = "Error: path must be a directory: aFile.txt";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   492
        Object[][] a = tasks.stream().map(t -> new Object[] {t, errMsg} )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   493
                                     .toArray(Object[][]::new);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   494
        a[0][1] = "invalid class path entry: aFile.txt";  // class path err msg
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   495
        return a;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   496
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   497
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   498
    @Test(dataProvider = "pathIsFile")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   499
    public void testPathIsFile(Supplier<JmodResult> supplier,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   500
                               String errMsg)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   501
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   502
        supplier.get()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   503
                .assertFailure()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   504
                .resultChecker(r -> {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   505
                    assertContains(r.output, errMsg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   506
                });
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   507
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   508
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   509
    // ---
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   510
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   511
    static boolean compileModule(String name, Path dest) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   512
        return CompilerUtils.compile(SRC_DIR.resolve(name), dest);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   513
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   514
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   515
    static void assertContains(String output, String subString) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
        if (output.contains(subString))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   517
            assertTrue(true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   518
        else
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   519
            assertTrue(false,"Expected to find [" + subString + "], in output ["
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   520
                             + output + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   521
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   522
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   523
    static JmodResult jmod(String... args) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   524
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   525
        PrintStream ps = new PrintStream(baos);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
        System.out.println("jmod " + Arrays.asList(args));
41484
834b7539ada3 8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents: 40261
diff changeset
   527
        int ec = JMOD_TOOL.run(ps, ps, args);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   528
        return new JmodResult(ec, new String(baos.toByteArray(), UTF_8));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   529
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   530
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   531
    static class JmodResult {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   532
        final int exitCode;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   533
        final String output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   534
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   535
        JmodResult(int exitValue, String output) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   536
            this.exitCode = exitValue;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   537
            this.output = output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   538
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   539
        JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   540
        JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   541
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   542
}