test/langtools/tools/javac/options/smokeTests/OptionSmokeTest.java
author vromero
Mon, 29 Oct 2018 17:09:44 -0400
changeset 52323 c306abfeae0d
parent 51182 b0fcf59be391
permissions -rw-r--r--
8213100: fix test OptionSmokeTest before removing it from the problem list Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     1
/*
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     4
 *
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     8
 *
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    13
 * accompanied this code).
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    14
 *
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    18
 *
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    21
 * questions.
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    22
 */
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    23
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    24
/**
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    25
 * @test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    26
 * @bug 8196433
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    27
 * @summary use the new error diagnostic approach at javac.Main
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    28
 * @library /tools/lib
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.code
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.main
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.util
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    33
 *          jdk.jdeps/com.sun.tools.javap
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    34
 * @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
    35
 * @run main/othervm OptionSmokeTest
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    36
 */
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    37
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
    38
import java.util.Locale;
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
    39
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    40
import java.nio.file.Path;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    41
import java.nio.file.Paths;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    42
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    43
import com.sun.tools.javac.util.Assert;
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
    44
import com.sun.tools.javac.code.Source;
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    45
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    46
import toolbox.TestRunner;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    47
import toolbox.ToolBox;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    48
import toolbox.JavacTask;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    49
import toolbox.Task;
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    50
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    51
public class OptionSmokeTest extends TestRunner {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    52
    ToolBox tb = new ToolBox();
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    53
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    54
    public OptionSmokeTest() {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    55
        super(System.err);
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
    56
        Locale.setDefault(Locale.US);
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    57
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    58
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    59
    protected void runTests() throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    60
        runTests(m -> new Object[] { Paths.get(m.getName()) });
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    61
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    62
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    63
    Path[] findJavaFiles(Path... paths) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    64
        return tb.findJavaFiles(paths);
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    65
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    66
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    67
    public static void main(String... args) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    68
        new OptionSmokeTest().runTests();
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    69
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    70
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    71
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    72
    public void optionA1(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
    73
        doTest(base, "error: -A requires an argument; use '-Akey' or '-Akey=value'", "-A");
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    74
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    75
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    76
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    77
    public void optionA2(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    78
        doTest(base,
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    79
                "error: key in annotation processor option '-A1e=2' is not a dot-separated sequence of identifiers",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    80
                "-A1e=2");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    81
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    82
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    83
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    84
    public void noFlag(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    85
        doTest(base, "error: invalid flag: -noFlag", "-noFlag");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    86
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    87
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    88
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    89
    public void profileAndBSP(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    90
        doTest(base, "error: profile and bootclasspath options cannot be used together",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
    91
                String.format("-profile compact1 -bootclasspath . -target %s -source %s", Source.DEFAULT.name, Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    92
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    93
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    94
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    95
    public void invalidProfile(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
    96
        doTest(base, "error: invalid profile: noProfile", "-profile noProfile");
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    97
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    98
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
    99
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   100
    public void invalidTarget(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   101
        doTest(base, "error: invalid target release: 999999", "-target 999999");
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   102
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   103
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   104
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   105
    public void optionNotAvailableWithTarget(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   106
        doTest(base, String.format("error: option -profile not allowed with target %s", Source.DEFAULT.name),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   107
                String.format("-profile compact1 -target %s", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   108
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   109
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   110
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   111
    public void optionTooMany(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   112
        doTest(base, "error: option --default-module-for-created-files can only be specified once",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   113
                "--default-module-for-created-files=m1x --default-module-for-created-files=m1x");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   114
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   115
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   116
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   117
    public void noSrcFiles(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   118
        doTestNoSource(base, "error: no source files", String.format("-target %s", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   119
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   120
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   121
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   122
    public void requiresArg(Path base) throws Exception {
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
   123
        doTestNoSource(base, "error: --target requires an argument", "-target");
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   124
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   125
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   126
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   127
    public void invalidSource(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   128
        doTestNoSource(base, "error: invalid source release: 999999", "-source 999999");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   129
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   130
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   131
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   132
    public void sourceAndModuleSourceCantBeTogether(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   133
        doTest(base, "error: cannot specify both --source-path and --module-source-path",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   134
                "--source-path . --module-source-path .");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   135
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   136
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   137
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   138
    public void sourceAndTargetMismatch(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   139
        doTest(base, String.format("warning: source release %s requires target release %s", Source.DEFAULT.name, Source.DEFAULT.name),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   140
                String.format("-source %s -target %s", Source.DEFAULT.name, Source.MIN.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   141
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   142
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   143
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   144
    public void targetConflictsWithDefaultSource(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   145
        doTest(base, String.format("warning: target release %s conflicts with default source release %s", Source.MIN.name, Source.DEFAULT.name),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   146
                String.format("-target %s", Source.MIN.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   147
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   148
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   149
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   150
    public void profileNotValidForTarget(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   151
        doTest(base, String.format("warning: profile compact2 is not valid for target release %s", Source.MIN.name),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   152
                String.format("-profile compact2 -target %s -source %s", Source.MIN.name, Source.MIN.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   153
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   154
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   155
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   156
    public void fileNotFound(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   157
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   158
                .files("notExistent/T.java")
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   159
                .run(Task.Expect.FAIL)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   160
                .writeAll()
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   161
                .getOutput(Task.OutputKind.DIRECT);
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   162
        Assert.check(log.startsWith(String.format("error: file not found: notExistent%sT.java", fileSeparator)),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   163
                String.format("real value of log:%s", log));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   164
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   165
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   166
    static final String fileSeparator = System.getProperty("file.separator");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   167
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   168
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   169
    public void notADirectory(Path base) throws Exception {
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   170
        doTest(base, String.format("error: not a directory: notADirectory%ssrc%sDummy.java", fileSeparator, fileSeparator),
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   171
                String.format("-d notADirectory%ssrc%sDummy.java", fileSeparator, fileSeparator));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   172
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   173
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   174
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   175
    public void notAFile(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   176
        // looks like a java file, it is a directory
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   177
        Path dir = base.resolve("dir.java");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   178
        tb.createDirectories(dir);
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   179
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   180
                .spaceSeparatedOptions("-XDsourcefile " + dir)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   181
                .run(Task.Expect.FAIL)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   182
                .writeAll()
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   183
                .getOutput(Task.OutputKind.DIRECT);
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   184
        Assert.check(log.startsWith(String.format("error: not a file: notAFile%sdir.java", fileSeparator)));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   185
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   186
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   187
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   188
    public void badValueForOption(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   189
        doTestNoSource(base, "error: bad value for --patch-module option: \'notExistent\'",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   190
                "--patch-module notExistent");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   191
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   192
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   193
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   194
    public void patchModuleMoreThanOnce(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   195
        doTestNoSource(base, "error: --patch-module specified more than once for m",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   196
                "--patch-module m=. --patch-module m=.");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   197
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   198
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   199
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   200
    public void unmatchedQuoteInEnvVar(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   201
        Path src = base.resolve("src");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   202
        tb.writeJavaFiles(src, "class Dummy {}");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   203
        String log = new JavacTask(tb, Task.Mode.EXEC)
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   204
                .envVar("JDK_JAVAC_OPTIONS",
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   205
                        String.format("--add-exports jdk.compiler%scom.sun.tools.javac.jvm=\"ALL-UNNAMED", fileSeparator))
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   206
                .files(findJavaFiles(src))
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   207
                .run(Task.Expect.FAIL)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   208
                .writeAll()
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   209
                .getOutput(Task.OutputKind.STDERR);
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   210
        Assert.check(log.startsWith("error: unmatched quote in environment variable JDK_JAVAC_OPTIONS"));
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   211
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   212
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   213
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   214
    public void optionCantBeUsedWithRelease(Path base) throws Exception {
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
   215
        doTestNoSource(base, "error: option --source cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   216
                String.format("--release %s -source %s", Source.DEFAULT.name, Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   217
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   218
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   219
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   220
    public void releaseVersionNotSupported(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   221
        doTestNoSource(base, "error: release version 99999999 not supported",
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   222
                "--release 99999999");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   223
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   224
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   225
    // taken from former test: tools/javac/options/release/ReleaseOptionClashes
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   226
    @Test
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   227
    public void releaseAndBootclasspath(Path base) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   228
        doTestNoSource(base, "error: option --boot-class-path cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   229
                String.format("--release %s -bootclasspath any", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   230
        doTestNoSource(base, "error: option -Xbootclasspath: cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   231
                String.format("--release %s -Xbootclasspath:any", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   232
        doTestNoSource(base, "error: option -Xbootclasspath/p: cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   233
                String.format("--release %s -Xbootclasspath/p:any", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   234
        doTestNoSource(base, "error: option -endorseddirs cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   235
                String.format("--release %s -endorseddirs any", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   236
        doTestNoSource(base, "error: option -extdirs cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   237
                String.format("--release %s -extdirs any", Source.DEFAULT.name));
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
   238
        doTestNoSource(base, "error: option --source cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   239
                String.format("--release %s -source %s", Source.MIN.name, Source.DEFAULT.name));
52323
c306abfeae0d 8213100: fix test OptionSmokeTest before removing it from the problem list
vromero
parents: 51182
diff changeset
   240
        doTestNoSource(base, "error: option --target cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   241
                String.format("--release %s -target %s", Source.MIN.name, Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   242
        doTestNoSource(base, "error: option --system cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   243
                String.format("--release %s --system none", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   244
        doTestNoSource(base, "error: option --upgrade-module-path cannot be used together with --release",
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   245
                String.format("--release %s --upgrade-module-path any", Source.DEFAULT.name));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   246
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   247
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   248
    void doTest(Path base, String output, String options) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   249
        Path src = base.resolve("src");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   250
        tb.writeJavaFiles(src, "class Dummy { }");
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   251
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   252
                .spaceSeparatedOptions(options)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   253
                .files(findJavaFiles(src))
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   254
                .run(Task.Expect.FAIL)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   255
                .writeAll()
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   256
                .getOutput(Task.OutputKind.DIRECT);
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   257
        Assert.check(log.startsWith(output), String.format("expected:\n%s\nfound:\n%s", output, log));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   258
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   259
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   260
    void doTestNoSource(Path base, String output, String options) throws Exception {
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   261
        String log = new JavacTask(tb, Task.Mode.CMDLINE)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   262
                .spaceSeparatedOptions(options)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   263
                .run(Task.Expect.FAIL)
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   264
                .writeAll()
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   265
                .getOutput(Task.OutputKind.DIRECT);
51182
b0fcf59be391 8205493: OptionSmokeTest.java uses hard-coded release values
vromero
parents: 49822
diff changeset
   266
        Assert.check(log.startsWith(output), String.format("expected:\n%s\nfound:\n%s", output, log));
49822
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   267
    }
53aae0c219e6 8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
diff changeset
   268
}