langtools/test/tools/javac/modules/ObscureMessageForBadProvidesTest.java
author sadayapalam
Mon, 06 Feb 2017 18:14:51 +0530
changeset 43584 63e67712246b
parent 38827 884d32899770
permissions -rw-r--r--
8166420: Confusing error message when reading bad module declaration Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38827
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     1
/*
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     4
 *
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     8
 *
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    13
 * accompanied this code).
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    14
 *
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    18
 *
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    21
 * questions.
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    22
 */
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    23
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    24
/*
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    25
 * @test
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    26
 * @bug 8152062
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    27
 * @summary obscure error message for bad 'provides'
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    28
 * @library /tools/lib
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    29
 * @modules
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    30
 *      jdk.compiler/com.sun.tools.javac.api
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    31
 *      jdk.compiler/com.sun.tools.javac.main
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    33
 * @run main ObscureMessageForBadProvidesTest
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    34
 */
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    35
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    36
import java.nio.file.Path;
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    37
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    38
import toolbox.JavacTask;
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    39
import toolbox.Task;
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    40
import toolbox.ToolBox;
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    41
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    42
public class ObscureMessageForBadProvidesTest extends ModuleTestBase {
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    43
    public static void main(String... args) throws Exception {
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    44
        new ObscureMessageForBadProvidesTest().runTests();
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    45
    }
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    46
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    47
    @Test
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    48
    public void theTest(Path base) throws Exception {
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    49
        Path mod = base.resolve("mod");
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    50
        tb.writeJavaFiles(mod, "module mod { provides java.lang.String with java.io.File; }");
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    51
        Path classes = base.resolve("classes");
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    52
        tb.createDirectories(classes);
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    53
        String log = new JavacTask(tb)
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    54
                .options("-XDrawDiagnostics")
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    55
                .outdir(classes)
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    56
                .files(findJavaFiles(mod))
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    57
                .run(Task.Expect.FAIL)
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    58
                .writeAll()
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    59
                .getOutput(Task.OutputKind.DIRECT);
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    60
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    61
        if (!log.startsWith("module-info.java:1:52: compiler.err.service.implementation.must.be.subtype.of.service.interface"))
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    62
            throw new Exception("expected output not found");
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    63
    }
884d32899770 8152062: obscure error message for bad 'provides'
vromero
parents:
diff changeset
    64
}