8006263: Supplementary test cases needed for doclint
Reviewed-by: mcimadamore
Contributed-by: peter.jensen@oracle.com
--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Fri Jan 18 15:38:14 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Mon Jan 21 10:00:46 2013 -0800
@@ -92,7 +92,7 @@
boolean foundInheritDoc = false;
boolean foundReturn = false;
- enum Flag {
+ public enum Flag {
TABLE_HAS_CAPTION,
HAS_ELEMENT,
HAS_TEXT
--- a/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Fri Jan 18 15:38:14 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Mon Jan 21 10:00:46 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -122,7 +122,7 @@
if (javacFiles.isEmpty()) {
if (!needHelp)
- System.out.println("no files given");
+ out.println("no files given");
}
JavacTool tool = JavacTool.create();
@@ -179,11 +179,11 @@
}
} else if (arg.equals(STATS)) {
env.messages.setStatsEnabled(true);
- } else if (arg.matches("-bootclasspath") && i + 1 < args.length) {
+ } else if (arg.equals("-bootclasspath") && i + 1 < args.length) {
javacBootClassPath = splitPath(args[++i]);
- } else if (arg.matches("-classpath") && i + 1 < args.length) {
+ } else if (arg.equals("-classpath") && i + 1 < args.length) {
javacClassPath = splitPath(args[++i]);
- } else if (arg.matches("-sourcepath") && i + 1 < args.length) {
+ } else if (arg.equals("-sourcepath") && i + 1 < args.length) {
javacSourcePath = splitPath(args[++i]);
} else if (arg.equals(XMSGS_OPTION)) {
env.messages.setOptions(null);
@@ -234,6 +234,8 @@
out.println(" equivalent to -Xmsgs:all/protected, meaning that");
out.println(" all messages are reported for protected and public");
out.println(" declarations only. ");
+ out.println(" -stats");
+ out.println(" Report statistics on the reported issues.");
out.println(" -h -help --help -usage -?");
out.println(" Show this message.");
out.println("");
@@ -247,7 +249,7 @@
List<File> splitPath(String path) {
List<File> files = new ArrayList<File>();
- for (String f: path.split(File.separator)) {
+ for (String f: path.split(File.pathSeparator)) {
if (f.length() > 0)
files.add(new File(f));
}
--- a/langtools/src/share/classes/com/sun/tools/doclint/Entity.java Fri Jan 18 15:38:14 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Entity.java Mon Jan 21 10:00:46 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@
* risk. This code and its internal interfaces are subject to change
* or deletion without notice.</b></p>
*/
-enum Entity {
+public enum Entity {
nbsp(160),
iexcl(161),
cent(162),
--- a/langtools/src/share/classes/com/sun/tools/doclint/HtmlTag.java Fri Jan 18 15:38:14 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/HtmlTag.java Mon Jan 21 10:00:46 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -273,7 +273,7 @@
static final Map<String,Attr> index = new HashMap<String,Attr>();
static {
for (Attr t: values()) {
- index.put(t.name().toLowerCase(), t);
+ index.put(t.getText(), t);
}
}
}
@@ -346,7 +346,7 @@
private static final Map<String,HtmlTag> index = new HashMap<String,HtmlTag>();
static {
for (HtmlTag t: values()) {
- index.put(t.name().toLowerCase(), t);
+ index.put(t.getText(), t);
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/CoverageExtras.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ */
+
+import com.sun.tools.doclint.Checker;
+import com.sun.tools.doclint.Entity;
+import com.sun.tools.doclint.HtmlTag;
+import com.sun.tools.doclint.Messages;
+import java.util.Objects;
+
+public class CoverageExtras {
+ public static void main(String... args) {
+ new CoverageExtras().run();
+ }
+
+ void run() {
+ check(HtmlTag.A, HtmlTag.valueOf("A"), HtmlTag.values());
+ check(HtmlTag.Attr.ABBR, HtmlTag.Attr.valueOf("ABBR"), HtmlTag.Attr.values());
+ check(HtmlTag.AttrKind.INVALID, HtmlTag.AttrKind.valueOf("INVALID"), HtmlTag.AttrKind.values());
+ check(HtmlTag.BlockType.BLOCK, HtmlTag.BlockType.valueOf("BLOCK"), HtmlTag.BlockType.values());
+ check(HtmlTag.EndKind.NONE, HtmlTag.EndKind.valueOf("NONE"), HtmlTag.EndKind.values());
+ check(HtmlTag.Flag.EXPECT_CONTENT, HtmlTag.Flag.valueOf("EXPECT_CONTENT"), HtmlTag.Flag.values());
+
+ check(Checker.Flag.TABLE_HAS_CAPTION, Checker.Flag.valueOf("TABLE_HAS_CAPTION"), Checker.Flag.values());
+
+ check(Entity.nbsp, Entity.valueOf("nbsp"), Entity.values());
+
+ check(Messages.Group.ACCESSIBILITY, Messages.Group.valueOf("ACCESSIBILITY"), Messages.Group.values());
+ }
+
+ <T extends Enum<T>> void check(T expect, T value, T[] values) {
+ if (!Objects.equals(expect, value)) {
+ error("Mismatch: '" + expect + "', '" + value + "'");
+ }
+ if (!Objects.equals(expect, values[0])) {
+ error("Mismatch: '" + expect + "', '" + values[0] + "'");
+ }
+ }
+
+ void error(String msg) {
+ System.err.println("Error: " + msg);
+ errors++;
+ }
+
+ int errors;
+}
--- a/langtools/test/tools/doclint/DocLintTester.java Fri Jan 18 15:38:14 2013 +0000
+++ b/langtools/test/tools/doclint/DocLintTester.java Mon Jan 21 10:00:46 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
import java.util.List;
import com.sun.tools.doclint.DocLint;
+import com.sun.tools.doclint.DocLint.BadArgs;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
@@ -45,6 +46,7 @@
public void run(String... args) throws Exception {
String testSrc = System.getProperty("test.src");
+ boolean badArgs = false;
File refFile = null;
List<String> opts = new ArrayList<String>();
List<File> files = new ArrayList<File>();
@@ -52,19 +54,25 @@
String arg = args[i];
if (arg.equals("-ref")) {
refFile = new File(testSrc, args[++i]);
+ } else if (arg.equals("-badargs")) {
+ badArgs = true;
} else if (arg.startsWith("-Xmsgs")) {
opts.add(arg);
+ } else if (arg.startsWith("-")) {
+ opts.add(arg);
+ if (i < args.length - 1 && !args[i+1].startsWith("-"))
+ opts.add(args[++i]);
} else
files.add(new File(testSrc, arg));
}
- check(opts, files, refFile);
+ check(opts, files, badArgs, refFile);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
- void check(List<String> opts, List<File> files, File refFile) throws Exception {
+ void check(List<String> opts, List<File> files, boolean expectBadArgs, File refFile) throws Exception {
List<String> args = new ArrayList<String>();
args.addAll(opts);
for (File file: files)
@@ -72,7 +80,14 @@
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- new DocLint().run(pw, args.toArray(new String[args.size()]));
+ try {
+ new DocLint().run(pw, args.toArray(new String[args.size()]));
+ if (expectBadArgs)
+ error("expected exception not thrown");
+ } catch (BadArgs e) {
+ if (!expectBadArgs)
+ error("unexpected exception caught: " + e);
+ }
pw.flush();
String out = normalizeNewlines(removeFileNames(sw.toString())).trim();
if (out != null)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/html/EntitiesTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,317 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ * @library ..
+ * @build DocLintTester
+ * @run main DocLintTester -Xmsgs:-html EntitiesTest.java
+ * @run main DocLintTester -Xmsgs:html -ref EntitiesTest.out EntitiesTest.java
+ */
+
+/** */
+class EntitiesTest {
+
+ /**
+ *    
+ * ࡎ ࡎ ࡎ
+ */
+ void range_test() { }
+
+ /**
+ *  
+ * ¡ ¡
+ * ¢ ¢
+ * £ £
+ * ¤ ¤
+ * ¥ ¥
+ * ¦ ¦
+ * § §
+ * ¨ ¨
+ * © ©
+ * ª ª
+ * « «
+ * ¬ ¬
+ * ­ ­
+ * ® ®
+ * ¯ ¯
+ * ° °
+ * ± ±
+ * ² ²
+ * ³ ³
+ * ´ ´
+ * µ µ
+ * ¶ ¶
+ * · ·
+ * ¸ ¸
+ * ¹ ¹
+ * º º
+ * » »
+ * ¼ ¼
+ * ½ ½
+ * ¾ ¾
+ * ¿ ¿
+ * À À
+ * Á Á
+ * Â Â
+ * Ã Ã
+ * Ä Ä
+ * Å Å
+ * Æ Æ
+ * Ç Ç
+ * È È
+ * É É
+ * Ê Ê
+ * Ë Ë
+ * Ì Ì
+ * Í Í
+ * Î Î
+ * Ï Ï
+ * Ð Ð
+ * Ñ Ñ
+ * Ò Ò
+ * Ó Ó
+ * Ô Ô
+ * Õ Õ
+ * Ö Ö
+ * × ×
+ * Ø Ø
+ * Ù Ù
+ * Ú Ú
+ * Û Û
+ * Ü Ü
+ * Ý Ý
+ * Þ Þ
+ * ß ß
+ * à à
+ * á á
+ * â â
+ * ã ã
+ * ä ä
+ * å å
+ * æ æ
+ * ç ç
+ * è è
+ * é é
+ * ê ê
+ * ë ë
+ * ì ì
+ * í í
+ * î î
+ * ï ï
+ * ð ð
+ * ñ ñ
+ * ò ò
+ * ó ó
+ * ô ô
+ * õ õ
+ * ö ö
+ * ÷ ÷
+ * ø ø
+ * ù ù
+ * ú ú
+ * û û
+ * ü ü
+ * ý ý
+ * þ þ
+ * ÿ ÿ
+ * ƒ ƒ
+ * Α Α
+ * Β Β
+ * Γ Γ
+ * Δ Δ
+ * Ε Ε
+ * Ζ Ζ
+ * Η Η
+ * Θ Θ
+ * Ι Ι
+ * Κ Κ
+ * Λ Λ
+ * Μ Μ
+ * Ν Ν
+ * Ξ Ξ
+ * Ο Ο
+ * Π Π
+ * Ρ Ρ
+ * Σ Σ
+ * Τ Τ
+ * Υ Υ
+ * Φ Φ
+ * Χ Χ
+ * Ψ Ψ
+ * Ω Ω
+ * α α
+ * β β
+ * γ γ
+ * δ δ
+ * ε ε
+ * ζ ζ
+ * η η
+ * θ θ
+ * ι ι
+ * κ κ
+ * λ λ
+ * μ μ
+ * ν ν
+ * ξ ξ
+ * ο ο
+ * π π
+ * ρ ρ
+ * ς ς
+ * σ σ
+ * τ τ
+ * υ υ
+ * φ φ
+ * χ χ
+ * ψ ψ
+ * ω ω
+ * ϑ ϑ
+ * ϒ ϒ
+ * ϖ ϖ
+ * • •
+ * … …
+ * ′ ′
+ * ″ ″
+ * ‾ ‾
+ * ⁄ ⁄
+ * ℘ ℘
+ * ℑ ℑ
+ * ℜ ℜ
+ * ™ ™
+ * ℵ ℵ
+ * ← ←
+ * ↑ ↑
+ * → →
+ * ↓ ↓
+ * ↔ ↔
+ * ↵ ↵
+ * ⇐ ⇐
+ * ⇑ ⇑
+ * ⇒ ⇒
+ * ⇓ ⇓
+ * ⇔ ⇔
+ * ∀ ∀
+ * ∂ ∂
+ * ∃ ∃
+ * ∅ ∅
+ * ∇ ∇
+ * ∈ ∈
+ * ∉ ∉
+ * ∋ ∋
+ * ∏ ∏
+ * ∑ ∑
+ * − −
+ * ∗ ∗
+ * √ √
+ * ∝ ∝
+ * ∞ ∞
+ * ∠ ∠
+ * ∧ ∧
+ * ∨ ∨
+ * ∩ ∩
+ * ∪ ∪
+ * &_int; ∫
+ * ∴ ∴
+ * ∼ ∼
+ * ≅ ≅
+ * ≈ ≈
+ * ≠ ≠
+ * ≡ ≡
+ * ≤ ≤
+ * ≥ ≥
+ * ⊂ ⊂
+ * ⊃ ⊃
+ * ⊄ ⊄
+ * ⊆ ⊆
+ * ⊇ ⊇
+ * ⊕ ⊕
+ * ⊗ ⊗
+ * ⊥ ⊥
+ * ⋅ ⋅
+ * ⌈ ⌈
+ * ⌉ ⌉
+ * ⌊ ⌊
+ * ⌋ ⌋
+ * ⟨ 〈
+ * ⟩ 〉
+ * ◊ ◊
+ * ♠ ♠
+ * ♣ ♣
+ * ♥ ♥
+ * ♦ ♦
+ * " "
+ * & &
+ * < <
+ * > >
+ * Œ Œ
+ * œ œ
+ * Š Š
+ * š š
+ * Ÿ Ÿ
+ * ˆ ˆ
+ * ˜ ˜
+ *    
+ *    
+ *    
+ * ‌ ‌
+ * ‍ ‍
+ * ‎ ‎
+ * ‏ ‏
+ * – –
+ * — —
+ * ‘ ‘
+ * ’ ’
+ * ‚ ‚
+ * “ “
+ * ” ”
+ * „ „
+ * † †
+ * ‡ ‡
+ * ‰ ‰
+ * ‹ ‹
+ * › ›
+ * € €
+ */
+ void symbolic_entities() { }
+
+ /**
+ * &bad;
+ */
+ void bad_name() { }
+
+ /**
+ * 
+ * ࡏ
+ */
+ void out_of_range() { }
+
+ /**
+ * ―
+ * ⌫
+ * 
+ */
+ void sparse_negative() { }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/html/EntitiesTest.out Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,19 @@
+EntitiesTest.java:300: error: invalid entity &bad;
+ * &bad;
+ ^
+EntitiesTest.java:305: error: invalid entity 
+ * 
+ ^
+EntitiesTest.java:306: error: invalid entity ࡏ
+ * ࡏ
+ ^
+EntitiesTest.java:311: error: invalid entity ―
+ * ―
+ ^
+EntitiesTest.java:312: error: invalid entity ⌫
+ * ⌫
+ ^
+EntitiesTest.java:313: error: invalid entity 
+ * 
+ ^
+6 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/HelpTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ * @library ..
+ * @build DocLintTester
+ * @run main DocLintTester -ref HelpTest.out
+ * @run main DocLintTester -ref HelpTest.out -h
+ * @run main DocLintTester -ref HelpTest.out -help
+ * @run main DocLintTester -ref HelpTest.out --help
+ * @run main DocLintTester -ref HelpTest.out -usage
+ * @run main DocLintTester -ref HelpTest.out -?
+ */
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/HelpTest.out Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,43 @@
+Usage:
+ doclint [options] source-files...
+
+Options:
+ -Xmsgs
+ Same as -Xmsgs:all
+ -Xmsgs:values
+ Specify categories of issues to be checked, where 'values'
+ is a comma-separated list of any of the following:
+ reference show places where comments contain incorrect
+ references to Java source code elements
+ syntax show basic syntax errors within comments
+ html show issues with HTML tags and attributes
+ accessibility show issues for accessibility
+ missing show issues with missing documentation
+ all all of the above
+ Precede a value with '-' to negate it
+ Categories may be qualified by one of:
+ /public /protected /package /private
+ For positive categories (not beginning with '-')
+ the qualifier applies to that access level and above.
+ For negative categories (beginning with '-')
+ the qualifier applies to that access level and below.
+ If a qualifier is missing, the category applies to
+ all access levels.
+ For example, -Xmsgs:all,-syntax/private
+ This will enable all messages, except syntax errors
+ in the doc comments of private methods.
+ If no -Xmsgs options are provided, the default is
+ equivalent to -Xmsgs:all/protected, meaning that
+ all messages are reported for protected and public
+ declarations only.
+ -stats
+ Report statistics on the reported issues.
+ -h -help --help -usage -?
+ Show this message.
+
+The following javac options are also supported
+ -bootclasspath, -classpath, -sourcepath, -Xmaxerrs, -Xmaxwarns
+
+To run doclint on part of a project, put the compiled classes for your
+project on the classpath (or bootclasspath), then specify the source files
+to be checked on the command line.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/MaxDiagsTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ * @library ..
+ * @build DocLintTester
+ * @run main DocLintTester -ref MaxDiagsTest.out -Xmaxerrs 2 -Xmaxwarns 2 MaxDiagsTest.java
+ * @run main DocLintTester -badargs -Xmaxerrs
+ * @run main DocLintTester -badargs -Xmaxwarns
+ * @run main DocLintTester -badargs -Xmaxerrs two -Xmaxwarns two MaxDiagsTest.java
+ */
+
+public class MaxDiagsTest {
+ /**
+ * � � � �
+ */
+ public void errors() { }
+
+ /** 4 undocumented signature items */
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/MaxDiagsTest.out Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,14 @@
+MaxDiagsTest.java:13: warning: no comment
+public class MaxDiagsTest {
+ ^
+MaxDiagsTest.java:15: error: invalid entity �
+ * � � � �
+ ^
+MaxDiagsTest.java:15: error: invalid entity �
+ * � � � �
+ ^
+MaxDiagsTest.java:20: warning: no @param for a1
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+ ^
+2 errors
+2 warnings
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/PathsTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ */
+
+import com.sun.tools.doclint.DocLint;
+import com.sun.tools.doclint.DocLint.BadArgs;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.regex.Pattern;
+
+public class PathsTest {
+ public static void main(String... args) throws Exception {
+ new PathsTest().run();
+ }
+
+ void run() throws Exception {
+ String PS = File.pathSeparator;
+ writeFile("src1/p/A.java",
+ "package p; public class A { }");
+ compile("-d", "classes1", "src1/p/A.java");
+
+ writeFile("src2/q/B.java",
+ "package q; public class B extends p.A { }");
+ compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java");
+
+ writeFile("src/Test.java",
+ "/** &0; */ class Test extends q.B { }");
+
+ test("src/Test.java", "-sourcepath", "src1" + PS + "src2");
+ test("src/Test.java", "-classpath", "classes1" + PS + "classes2");
+ String sysBootClassPath = System.getProperty("sun.boot.class.path");
+ test("src/Test.java", "-bootclasspath",
+ sysBootClassPath + PS + "classes1" + PS + "classes2");
+
+ if (errors > 0)
+ throw new Exception(errors + " errors found");
+ }
+
+ Pattern pkgNotFound = Pattern.compile("package [a-z]+ does not exist");
+ Pattern badHtmlEntity = Pattern.compile("bad HTML entity");
+
+ void test(String file, String pathOpt, String path) throws BadArgs, IOException {
+ System.err.println("test " + pathOpt);
+ String out1 = doclint("-Xmsgs", file);
+ if (!pkgNotFound.matcher(out1).find())
+ error("message not found: " + pkgNotFound);
+
+ String out2 = doclint("-Xmsgs", pathOpt, path, file);
+ if (pkgNotFound.matcher(out2).find())
+ error("unexpected message found: " + pkgNotFound);
+ if (!badHtmlEntity.matcher(out1).find())
+ error("message not found: " + badHtmlEntity);
+
+ try {
+ doclint("-Xmsgs", pathOpt);
+ error("expected exception not thrown");
+ } catch (BadArgs e) {
+ System.err.println(e);
+ }
+ }
+
+ void compile(String... args) {
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("-d")) {
+ new File(args[++i]).mkdirs();
+ break;
+ }
+ }
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ int rc = com.sun.tools.javac.Main.compile(args, pw);
+ pw.close();
+ String out = sw.toString();
+ if (!out.isEmpty())
+ System.err.println(out);
+ if (rc != 0)
+ error("compilation failed: rc=" + rc);
+ }
+
+ String doclint(String... args) throws BadArgs, IOException {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ DocLint dl = new DocLint();
+ dl.run(pw, args);
+ pw.close();
+ String out = sw.toString();
+ if (!out.isEmpty())
+ System.err.println(out);
+ return out;
+ }
+
+ File writeFile(String path, String body) throws IOException {
+ File f = new File(path);
+ f.getParentFile().mkdirs();
+ try (FileWriter fw = new FileWriter(path)) {
+ fw.write(body);
+ }
+ return f;
+ }
+
+ void error(String msg) {
+ System.err.println("Error: " + msg);
+ errors++;
+ }
+
+ int errors;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/RunTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ */
+
+import com.sun.source.util.JavacTask;
+import com.sun.tools.doclint.DocLint;
+import com.sun.tools.doclint.DocLint.BadArgs;
+import com.sun.tools.javac.api.JavacTool;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URI;
+import java.security.Permission;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+
+public class RunTest {
+ static class SimpleSecurityManager extends SecurityManager {
+ boolean allowExit = false;
+
+ @Override
+ public void checkExit(int status) {
+ if (!allowExit)
+ throw new SecurityException("System.exit(" + status + ")");
+ }
+ @Override
+ public void checkPermission(Permission perm) { }
+
+ }
+
+ public static void main(String... args) throws Exception {
+ // if no security manager already installed, install one to
+ // prevent System.exit
+ SimpleSecurityManager secmgr = null;
+ if (System.getSecurityManager() == null) {
+ System.setSecurityManager(secmgr = new SimpleSecurityManager() { });
+ }
+
+ try {
+ new RunTest().run();
+ } finally {
+ if (secmgr != null)
+ secmgr.allowExit = true;
+ }
+ }
+
+ void run() throws Exception {
+ testMain();
+ testRun();
+ testInit();
+ testArgsNoFiles();
+
+ if (errors > 0)
+ throw new Exception(errors + " errors found");
+ }
+
+ void testMain() {
+ System.err.println("test main(String[])");
+ testMain(true, "-help");
+ testMain(false, "-unknownOption");
+ }
+
+ void testMain(boolean expectOK, String... args) {
+ try {
+ DocLint.main(args);
+ if (!expectOK)
+ error("expected SecurityException (from System.exit) not thrown");
+ } catch (SecurityException e) {
+ System.err.println(e);
+ if (expectOK)
+ error("unexpected SecurityException caught");
+ }
+ }
+
+ void testRun() throws BadArgs, IOException {
+ System.err.println("test run(String[])");
+ DocLint dl = new DocLint();
+ String[] args = { "-help" };
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ PrintStream prev = System.out;
+ try {
+ System.setOut(ps);
+ dl.run(args);
+ } finally {
+ System.setOut(prev);
+ }
+ ps.close();
+ String stdout = baos.toString();
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ dl.run(pw, args);
+ pw.close();
+ String direct = sw.toString();
+
+ if (!stdout.equals(direct)) {
+ error("unexpected output");
+ System.err.println("EXPECT>>" + direct + "<<");
+ System.err.println("FOUND>>" + stdout + "<<");
+ }
+ }
+
+ void testInit() {
+ System.err.println("test init");
+ DocLint dl = new DocLint();
+ String name = dl.getName();
+ if (!Objects.equals(name, "doclint"))
+ error("unexpected result for DocLint.getName()");
+
+ List<? extends JavaFileObject> files =
+ Arrays.asList(createFile("Test.java", "/** &0; */ class Test{ }"));
+ String[] goodArgs = { "-Xmsgs" };
+ testInit(true, goodArgs, files);
+
+ String[] badArgs = { "-unknown" };
+ testInit(false, badArgs, files);
+ }
+
+ void testInit(boolean expectOK, String[] args, List<? extends JavaFileObject> files) {
+ JavacTool javac = JavacTool.create();
+ JavacTask task = javac.getTask(null, null, null, null, null, files);
+ try {
+ DocLint dl = new DocLint();
+ dl.init(task, args, true);
+ if (!expectOK)
+ error("expected IllegalArgumentException not thrown");
+ task.call();
+ } catch (IllegalArgumentException e) {
+ System.err.println(e);
+ if (expectOK)
+ error("unexpected IllegalArgumentException caught");
+ }
+ }
+
+ void testArgsNoFiles() throws BadArgs, IOException {
+ System.err.println("test args, no files");
+ DocLint dl = new DocLint();
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ dl.run(pw, "-Xmsgs");
+ pw.close();
+ String out = sw.toString();
+
+ String expect = "no files given";
+ if (!Objects.equals(out.trim(), expect)) {
+ error("unexpected output");
+ System.err.println("EXPECT>>" + expect + "<<");
+ System.err.println("FOUND>>" + out + "<<");
+ }
+
+ }
+
+ JavaFileObject createFile(String name, final String body) {
+ return new SimpleJavaFileObject(URI.create(name), JavaFileObject.Kind.SOURCE) {
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ return body;
+ }
+ };
+ }
+
+ void error(String msg) {
+ System.err.println("Error: " + msg);
+ errors++;
+ }
+
+ int errors;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/StatsTest.java Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,19 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8006263
+ * @summary Supplementary test cases needed for doclint
+ * @library ..
+ * @build DocLintTester
+ * @run main DocLintTester -ref StatsTest.out -stats -Xmsgs:all StatsTest.java
+ */
+
+// warning: missing comment
+public class StatsTest {
+ /**
+ * � � � �
+ */
+ public void errors() { }
+
+ /** 4 undocumented signature items */
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/tool/StatsTest.out Mon Jan 21 10:00:46 2013 -0800
@@ -0,0 +1,43 @@
+StatsTest.java:11: warning: no comment
+public class StatsTest {
+ ^
+StatsTest.java:13: error: invalid entity �
+ * � � � �
+ ^
+StatsTest.java:13: error: invalid entity �
+ * � � � �
+ ^
+StatsTest.java:13: error: invalid entity �
+ * � � � �
+ ^
+StatsTest.java:13: error: invalid entity �
+ * � � � �
+ ^
+StatsTest.java:18: warning: no @param for a1
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+ ^
+StatsTest.java:18: warning: no @param for a2
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+ ^
+StatsTest.java:18: warning: no @return
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+ ^
+StatsTest.java:18: warning: no @throws for java.lang.Exception
+ public int warnings(int a1, int a2) throws Exception { return 0; }
+ ^
+By group...
+ 5: missing
+ 4: html
+
+By diagnostic kind...
+ 5: warning
+ 4: error
+
+By message kind...
+ 4: invalid entity &{0};
+ 2: no @param for {0}
+ 1: no @return
+ 1: no @throws for {0}
+ 1: no comment
+4 errors
+5 warnings