test/tools/doclint/RunTest.java

Mon, 31 Aug 2015 13:37:01 -0700

author
asaha
date
Mon, 31 Aug 2015 13:37:01 -0700
changeset 2971
153d0309e698
parent 1774
37295244f534
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u65-b12 for changeset 54e958a3719e

     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /* @test
    25  * @bug 8004832 8000103
    26  * @summary Add new doclint package
    27  * @summary Create doclint utility
    28  */
    30 import java.io.File;
    31 import java.io.IOException;
    32 import java.io.PrintWriter;
    33 import java.io.StringWriter;
    34 import java.lang.annotation.Annotation;
    35 import java.lang.annotation.Retention;
    36 import java.lang.annotation.RetentionPolicy;
    37 import java.lang.reflect.InvocationTargetException;
    38 import java.lang.reflect.Method;
    40 import com.sun.tools.doclint.DocLint;
    41 import com.sun.tools.doclint.DocLint.BadArgs;
    43 /** javadoc error on toplevel:  a & b. */
    44 public class RunTest {
    45     /** javadoc error on member: a < b */
    46     public static void main(String... args) throws Exception {
    47         new RunTest().run();
    48     }
    51     File testSrc = new File(System.getProperty("test.src"));
    52     File thisFile = new File(testSrc, RunTest.class.getSimpleName() + ".java");
    54     void run() throws Exception {
    55         for (Method m: getClass().getDeclaredMethods()) {
    56             Annotation a = m.getAnnotation(Test.class);
    57             if (a != null) {
    58                 System.err.println("test: " + m.getName());
    59                 try {
    60                     StringWriter sw = new StringWriter();
    61                     PrintWriter pw = new PrintWriter(sw);;
    62                     m.invoke(this, new Object[] { pw });
    63                     String out = sw.toString();
    64                     System.err.println(">>> " + out.replace("\n", "\n>>> "));
    65                     if (!out.contains("a < b"))
    66                         error("\"a < b\" not found");
    67                     if (!out.contains("a & b"))
    68                         error("\"a & b\" not found");
    69                 } catch (InvocationTargetException e) {
    70                     Throwable cause = e.getCause();
    71                     throw (cause instanceof Exception) ? ((Exception) cause) : e;
    72                 }
    73                 System.err.println();
    74             }
    75         }
    77         if (errors > 0)
    78             throw new Exception(errors + " errors occurred");
    79     }
    82     void error(String msg) {
    83         System.err.println("Error: " + msg);
    84         errors++;
    85     }
    87     int errors;
    89     /** Marker annotation for test cases. */
    90     @Retention(RetentionPolicy.RUNTIME)
    91     @interface Test { }
    93     @Test
    94     void testMain(PrintWriter pw) throws BadArgs, IOException {
    95         String[] args = { "-Xmsgs", thisFile.getPath() };
    96         DocLint d = new DocLint();
    97         d.run(pw, args);
    98     }
    99 }

mercurial