langtools/test/tools/doclint/tool/RunTest.java
author jjg
Mon, 21 Jan 2013 10:00:46 -0800
changeset 15370 c1c9a9e11b26
child 18004 dcf9d59b1635
permissions -rw-r--r--
8006263: Supplementary test cases needed for doclint Reviewed-by: mcimadamore Contributed-by: peter.jensen@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15370
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     1
/*
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     4
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     8
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    13
 * accompanied this code).
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    14
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    18
 *
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    21
 * questions.
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    22
 */
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    23
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    24
/*
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    25
 * @test
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    26
 * @bug 8006263
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    27
 * @summary Supplementary test cases needed for doclint
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    28
 */
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    29
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    30
import com.sun.source.util.JavacTask;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    31
import com.sun.tools.doclint.DocLint;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    32
import com.sun.tools.doclint.DocLint.BadArgs;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.api.JavacTool;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    34
import java.io.ByteArrayOutputStream;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    35
import java.io.IOException;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    36
import java.io.PrintStream;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    37
import java.io.PrintWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    38
import java.io.StringWriter;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    39
import java.net.URI;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    40
import java.security.Permission;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    41
import java.util.Arrays;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    42
import java.util.List;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    43
import java.util.Objects;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    44
import javax.tools.JavaFileObject;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    45
import javax.tools.SimpleJavaFileObject;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    46
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    47
public class RunTest {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    48
    static class SimpleSecurityManager extends SecurityManager {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    49
        boolean allowExit = false;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    50
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    51
        @Override
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    52
        public void checkExit(int status) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    53
            if (!allowExit)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    54
                throw new SecurityException("System.exit(" + status + ")");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    55
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    56
        @Override
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    57
        public void checkPermission(Permission perm) { }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    58
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    59
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    60
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    61
    public static void main(String... args) throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    62
        // if no security manager already installed, install one to
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    63
        // prevent System.exit
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    64
        SimpleSecurityManager secmgr = null;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    65
        if (System.getSecurityManager() == null) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    66
            System.setSecurityManager(secmgr = new SimpleSecurityManager() { });
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    67
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    68
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    69
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    70
            new RunTest().run();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    71
        } finally {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    72
            if (secmgr != null)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    73
                secmgr.allowExit = true;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    74
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    75
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    76
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    77
    void run() throws Exception {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    78
        testMain();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    79
        testRun();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    80
        testInit();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    81
        testArgsNoFiles();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    82
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    83
        if (errors > 0)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    84
            throw new Exception(errors + " errors found");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    85
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    86
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    87
    void testMain() {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    88
        System.err.println("test main(String[])");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    89
        testMain(true, "-help");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    90
        testMain(false, "-unknownOption");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    91
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    92
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    93
    void testMain(boolean expectOK, String... args) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    94
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    95
            DocLint.main(args);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    96
            if (!expectOK)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    97
                error("expected SecurityException (from System.exit) not thrown");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    98
        } catch (SecurityException e) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
    99
            System.err.println(e);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   100
            if (expectOK)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   101
                error("unexpected SecurityException caught");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   102
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   103
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   104
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   105
    void testRun() throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   106
        System.err.println("test run(String[])");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   107
        DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   108
        String[] args = { "-help" };
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   109
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   110
        PrintStream ps = new PrintStream(baos);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   111
        PrintStream prev = System.out;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   112
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   113
            System.setOut(ps);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   114
            dl.run(args);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   115
        } finally {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   116
            System.setOut(prev);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   117
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   118
        ps.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   119
        String stdout = baos.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   120
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   121
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   122
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   123
        dl.run(pw, args);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   124
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   125
        String direct = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   126
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   127
        if (!stdout.equals(direct)) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   128
            error("unexpected output");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   129
            System.err.println("EXPECT>>" + direct + "<<");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   130
            System.err.println("FOUND>>" + stdout + "<<");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   131
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   132
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   133
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   134
    void testInit() {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   135
        System.err.println("test init");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   136
        DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   137
        String name = dl.getName();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   138
        if (!Objects.equals(name, "doclint"))
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   139
            error("unexpected result for DocLint.getName()");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   140
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   141
        List<? extends JavaFileObject> files =
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   142
                Arrays.asList(createFile("Test.java", "/** &0; */ class Test{ }"));
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   143
        String[] goodArgs = { "-Xmsgs" };
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   144
        testInit(true, goodArgs, files);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   145
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   146
        String[] badArgs = { "-unknown" };
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   147
        testInit(false, badArgs, files);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   148
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   149
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   150
    void testInit(boolean expectOK, String[] args, List<? extends JavaFileObject> files) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   151
        JavacTool javac = JavacTool.create();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   152
        JavacTask task = javac.getTask(null, null, null, null, null, files);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   153
        try {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   154
            DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   155
            dl.init(task, args, true);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   156
            if (!expectOK)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   157
                error("expected IllegalArgumentException not thrown");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   158
            task.call();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   159
        } catch (IllegalArgumentException e) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   160
            System.err.println(e);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   161
            if (expectOK)
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   162
                error("unexpected IllegalArgumentException caught");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   163
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   164
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   165
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   166
    void testArgsNoFiles() throws BadArgs, IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   167
        System.err.println("test args, no files");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   168
        DocLint dl = new DocLint();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   169
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   170
        StringWriter sw = new StringWriter();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   171
        PrintWriter pw = new PrintWriter(sw);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   172
        dl.run(pw, "-Xmsgs");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   173
        pw.close();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   174
        String out = sw.toString();
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   175
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   176
        String expect = "no files given";
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   177
        if (!Objects.equals(out.trim(), expect)) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   178
            error("unexpected output");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   179
            System.err.println("EXPECT>>" + expect + "<<");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   180
            System.err.println("FOUND>>" + out + "<<");
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   181
        }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   182
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   183
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   184
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   185
    JavaFileObject createFile(String name, final String body) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   186
        return new SimpleJavaFileObject(URI.create(name), JavaFileObject.Kind.SOURCE) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   187
            @Override
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   188
            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   189
                return body;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   190
            }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   191
        };
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   192
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   193
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   194
    void error(String msg) {
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   195
        System.err.println("Error: " + msg);
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   196
        errors++;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   197
    }
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   198
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   199
    int errors;
c1c9a9e11b26 8006263: Supplementary test cases needed for doclint
jjg
parents:
diff changeset
   200
}