langtools/test/tools/javac/doclint/DocLintTest.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 14960 ea7606a9683e
child 27319 030080f03e4f
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14960
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     1
/*
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     4
 *
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     8
 *
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    13
 * accompanied this code).
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    14
 *
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    18
 *
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    21
 * questions.
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    22
 */
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    23
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    24
/*
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    25
 * @test
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    26
 * @bug 8004833
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    27
 * @summary Integrate doclint support into javac
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    28
 */
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    29
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    30
import java.io.File;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    31
import java.io.PrintWriter;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    32
import java.io.StringWriter;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    33
import java.net.URI;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    34
import java.util.Arrays;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    35
import java.util.Collections;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    36
import java.util.List;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    37
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    38
import javax.tools.Diagnostic;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    39
import javax.tools.JavaCompiler;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    40
import javax.tools.JavaFileObject;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    41
import javax.tools.SimpleJavaFileObject;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    42
import javax.tools.StandardJavaFileManager;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    43
import javax.tools.StandardLocation;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    44
import javax.tools.ToolProvider;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    45
import static javax.tools.Diagnostic.Kind.*;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    46
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    47
import com.sun.source.util.JavacTask;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.main.Main;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    49
import java.util.EnumSet;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    50
import java.util.Set;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    51
import java.util.regex.Matcher;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    52
import java.util.regex.Pattern;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    53
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    54
public class DocLintTest {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    55
    public static void main(String... args) throws Exception {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    56
        new DocLintTest().run();
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    57
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    58
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    59
    JavaCompiler javac;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    60
    StandardJavaFileManager fm;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    61
    JavaFileObject file;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    62
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    63
    final String code =
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    64
        /* 01 */    "/** Class comment. */\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    65
        /* 02 */    "public class Test {\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    66
        /* 03 */    "    /** Method comment. */\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    67
        /* 04 */    "    public void method() { }\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    68
        /* 05 */    "\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    69
        /* 06 */    "    /** Syntax < error. */\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    70
        /* 07 */    "    private void syntaxError() { }\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    71
        /* 08 */    "\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    72
        /* 09 */    "    /** @see DoesNotExist */\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    73
        /* 10 */    "    protected void referenceError() { }\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    74
        /* 08 */    "\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    75
        /* 09 */    "    /** @return */\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    76
        /* 10 */    "    public int emptyReturn() { return 0; }\n" +
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    77
        /* 11 */    "}\n";
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    78
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    79
    final String rawDiags = "-XDrawDiagnostics";
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    80
    private enum Message {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    81
        // doclint messages
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    82
        DL_ERR6(ERROR, "Test.java:6:16: compiler.err.proc.messager: malformed HTML"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    83
        DL_ERR9(ERROR, "Test.java:9:14: compiler.err.proc.messager: reference not found"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    84
        DL_WRN12(WARNING, "Test.java:12:9: compiler.warn.proc.messager: no description for @return"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    85
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    86
        OPT_BADARG(ERROR, "invalid flag: -Xdoclint:badarg");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    87
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    88
        final Diagnostic.Kind kind;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    89
        final String text;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    90
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    91
        static Message get(String text) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    92
            for (Message m: values()) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    93
                if (m.text.equals(text))
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    94
                    return m;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    95
            }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    96
            return null;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    97
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    98
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
    99
        Message(Diagnostic.Kind kind, String text) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   100
            this.kind = kind;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   101
            this.text = text;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   102
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   103
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   104
        @Override
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   105
        public String toString() {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   106
            return "[" + kind + ",\"" + text + "\"]";
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   107
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   108
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   109
    void run() throws Exception {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   110
        javac = ToolProvider.getSystemJavaCompiler();
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   111
        fm = javac.getStandardFileManager(null, null, null);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   112
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   113
        file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   114
            @Override
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   115
            public CharSequence getCharContent(boolean ignoreEncoding) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   116
                return code;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   117
            }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   118
        };
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   119
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   120
        test(Collections.<String>emptyList(),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   121
                Main.Result.OK,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   122
                EnumSet.noneOf(Message.class));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   123
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   124
        test(Arrays.asList("-Xdoclint:none"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   125
                Main.Result.OK,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   126
                EnumSet.noneOf(Message.class));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   127
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   128
        test(Arrays.asList(rawDiags, "-Xdoclint"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   129
                Main.Result.ERROR,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   130
                EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   131
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   132
        test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   133
                Main.Result.OK,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   134
                EnumSet.of(Message.DL_WRN12));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   135
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   136
        test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   137
                Main.Result.ERROR,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   138
                EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   139
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   140
        test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   141
                Main.Result.ERROR,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   142
                EnumSet.of(Message.DL_ERR9));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   143
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   144
        test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   145
                Main.Result.CMDERR,
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   146
                EnumSet.of(Message.OPT_BADARG));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   147
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   148
        if (errors > 0)
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   149
            throw new Exception(errors + " errors occurred");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   150
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   151
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   152
    void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   153
        System.err.println("test: " + opts);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   154
        StringWriter sw = new StringWriter();
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   155
        PrintWriter pw = new PrintWriter(sw);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   156
        List<JavaFileObject> files = Arrays.asList(file);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   157
        try {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   158
            JavacTask t = (JavacTask) javac.getTask(pw, fm, null, opts, null, files);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   159
            boolean ok = t.call();
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   160
            pw.close();
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   161
            String out = sw.toString().replaceAll("[\r\n]+", "\n");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   162
            if (!out.isEmpty())
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   163
                System.err.println(out);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   164
            if (ok && expectResult != Main.Result.OK) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   165
                error("Compilation succeeded unexpectedly");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   166
            } else if (!ok && expectResult != Main.Result.ERROR) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   167
                error("Compilation failed unexpectedly");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   168
            } else
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   169
                check(out, expectMessages);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   170
        } catch (IllegalArgumentException e) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   171
            System.err.println(e);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   172
            String expectOut = expectMessages.iterator().next().text;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   173
            if (expectResult != Main.Result.CMDERR)
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   174
                error("unexpected exception caught");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   175
            else if (!e.getMessage().equals(expectOut)) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   176
                error("unexpected exception message: "
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   177
                        + e.getMessage()
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   178
                        + " expected: " + expectOut);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   179
            }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   180
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   181
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   182
//        if (errors > 0)
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   183
//            throw new Error("stop");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   184
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   185
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   186
    private void check(String out, Set<Message> expect) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   187
        Pattern stats = Pattern.compile("^([1-9]+) (error|warning)(s?)");
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   188
        Set<Message> found = EnumSet.noneOf(Message.class);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   189
        int e = 0, w = 0;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   190
        if (!out.isEmpty()) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   191
            for (String line: out.split("[\r\n]+")) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   192
                Matcher s = stats.matcher(line);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   193
                if (s.matches()) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   194
                    int i = Integer.valueOf(s.group(1));
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   195
                    if (s.group(2).equals("error"))
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   196
                        e++;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   197
                    else
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   198
                        w++;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   199
                    continue;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   200
                }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   201
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   202
                Message m = Message.get(line);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   203
                if (m == null)
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   204
                    error("Unexpected line: " + line);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   205
                else
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   206
                    found.add(m);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   207
            }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   208
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   209
        for (Message m: expect) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   210
            if (!found.contains(m))
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   211
                error("expected message not found: " + m.text);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   212
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   213
        for (Message m: found) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   214
            if (!expect.contains(m))
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   215
                error("unexpected message found: " + m.text);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   216
        }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   217
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   218
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   219
    void error(String msg) {
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   220
        System.err.println("Error: " + msg);
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   221
        errors++;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   222
    }
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   223
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   224
    int errors;
ea7606a9683e 8004833: Integrate doclint support into javac
jjg
parents:
diff changeset
   225
}