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