8024096: some javadoc tests may contain false positive results

Reviewed-by: jjg
This commit is contained in:
Bhavesh Patel 2013-09-18 22:47:06 -07:00
parent 484e378a9d
commit 2be05076f8
6 changed files with 104 additions and 54 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,6 +57,7 @@ public abstract class JavadocTester {
protected static final String SRC_DIR = System.getProperty("test.src", "."); protected static final String SRC_DIR = System.getProperty("test.src", ".");
protected static final String JAVA_VERSION = System.getProperty("java.version"); protected static final String JAVA_VERSION = System.getProperty("java.version");
protected static final String[][] NO_TEST = new String[][] {}; protected static final String[][] NO_TEST = new String[][] {};
protected static final String[] NO_FILE_TEST = new String[] {};
/** /**
* Use this as the file name in the test array when you want to search * Use this as the file name in the test array when you want to search
@ -165,6 +166,26 @@ public abstract class JavadocTester {
return returnCode; return returnCode;
} }
/**
* Execute the tests.
*
* @param tester the tester to execute
* @param args the arguments to pass to Javadoc
* @param testArray the array of tests
* @param negatedTestArray the array of negated tests
* @param fileTestArray the array of file tests
* @param negatedFileTestArray the array of negated file tests
* @return the return code for the execution of Javadoc
*/
public static int run(JavadocTester tester, String[] args,
String[][] testArray, String[][] negatedTestArray, String[] fileTestArray,
String[] negatedFileTestArray) {
int returnCode = tester.runJavadoc(args);
tester.runTestsOnHTML(testArray, negatedTestArray);
tester.runTestsOnFile(fileTestArray, negatedFileTestArray);
return returnCode;
}
/** /**
* Execute Javadoc using the default doclet. * Execute Javadoc using the default doclet.
* *
@ -243,6 +264,19 @@ public abstract class JavadocTester {
runTestsOnHTML(negatedTestArray, true); runTestsOnHTML(negatedTestArray, true);
} }
/**
* Run array of tests on the generated files.
* This method accepts a fileTestArray for testing if a file is generated
* and a negatedFileTestArray for testing if a file is not found.
*
* @param testArray the array of file tests
* @param negatedTestArray the array of negated file tests
*/
public void runTestsOnFile(String[] fileTestArray, String[] negatedFileTestArray) {
runTestsOnFile(fileTestArray, false);
runTestsOnFile(negatedFileTestArray, true);
}
/** /**
* Run the array of tests on the resulting HTML. * Run the array of tests on the resulting HTML.
* *
@ -265,9 +299,11 @@ public abstract class JavadocTester {
fileString = readFileToString(testArray[i][0]); fileString = readFileToString(testArray[i][0]);
} catch (Error e) { } catch (Error e) {
if (isNegated) { if (isNegated) {
numTestsPassed += 1; System.out.println( "FAILED" + "\n"
System.out.println("Passed\n not found:\n" + "for bug " + getBugId()
+ stringToFind + " in non-existent " + testArray[i][0] + "\n"); + " (" + getBugName() + ") "
+ "due to "
+ e + "\n");
continue; continue;
} }
throw e; throw e;
@ -290,6 +326,39 @@ public abstract class JavadocTester {
} }
} }
/**
* Run the array of file tests on the generated files.
*
* @param testArray the array of file tests
* @param isNegated true if test is negated; false otherwise
*/
private void runTestsOnFile(String[] testArray, boolean isNegated) {
String fileName;
String failedString;
String passedString;
for (int i = 0; i < testArray.length; i++) {
numTestsRun++;
fileName = testArray[i];
failedString = "FAILED" + "\n"
+ "for bug " + getBugId() + " (" + getBugName() + ") "
+ "file (" + fileName + ") found" + "\n";
passedString = "Passed" + "\n" +
"file (" + fileName + ") not found" + "\n";
System.out.print("Running subtest #" + numTestsRun + "... ");
try {
File file = new File(fileName);
if ((file.exists() && !isNegated) || (!file.exists() && isNegated)) {
numTestsPassed += 1;
System.out.println(passedString);
} else {
System.out.println(failedString);
}
} catch (Error e) {
System.err.println(e);
}
}
}
/** /**
* Iterate through the list of given file pairs and diff each file. * Iterate through the list of given file pairs and diff each file.
* *

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@ import java.io.File;
/* /*
* @test * @test
* @bug 4258405 4973606 * @bug 4258405 4973606 8024096
* @summary This test verifies that the doc-file directory does not * @summary This test verifies that the doc-file directory does not
* get overwritten when the sourcepath is equal to the destination * get overwritten when the sourcepath is equal to the destination
* directory. * directory.
@ -47,25 +47,17 @@ public class TestDocFileDir extends JavadocTester {
}; };
private static final String[][] NEGATED_TEST1 = NO_TEST; private static final String[][] NEGATED_TEST1 = NO_TEST;
private static final String[][] TEST2 = { private static final String[] FILE_TEST2 = {
{BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-used1" + BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-used1" +
FS + "testfile.txt", FS + "testfile.txt",
"passed" BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-used2" +
}, FS + "testfile.txt"
{BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-used2" +
FS + "testfile.txt",
"passed"
},
}; };
private static final String[][] NEGATED_TEST2 = { private static final String[] FILE_NEGATED_TEST2 = {
{BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-excluded1" + BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-excluded1" +
FS + "testfile.txt", FS + "testfile.txt",
"passed" BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-excluded2" +
}, FS + "testfile.txt"
{BUG_ID + "-2" + FS + "pkg" + FS + "doc-files" + FS + "subdir-excluded2" +
FS + "testfile.txt",
"passed"
},
}; };
private static final String[][] TEST0 = { private static final String[][] TEST0 = {
@ -106,7 +98,7 @@ public class TestDocFileDir extends JavadocTester {
run(tester, ARGS0, TEST0, NEGATED_TEST0); run(tester, ARGS0, TEST0, NEGATED_TEST0);
copyDir(SRC_DIR + FS + "pkg", BUG_ID + "-1"); copyDir(SRC_DIR + FS + "pkg", BUG_ID + "-1");
run(tester, ARGS1, TEST1, NEGATED_TEST1); run(tester, ARGS1, TEST1, NEGATED_TEST1);
run(tester, ARGS2, TEST2, NEGATED_TEST2); run(tester, ARGS2, NO_TEST, NO_TEST, FILE_TEST2, FILE_NEGATED_TEST2);
tester.printSummary(); tester.printSummary();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,9 @@
/** /**
* ±ñÉ¿í ¹©¢! * Testing en\u00e7\u00f4ded string.
* In the encoded comment string, Unicode U+00E7 is "Latin small letter C with cedilla"
* and Unicode U+00F4 is "Latin small letter O with circumflex"
*/ */
public class EncodeTest { public class EncodeTest {
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4661481 * @bug 4661481 8024096
* @summary This test determines if the value of the -encoding option is * @summary This test determines if the value of the -encoding option is
* properly passed from Javadoc to the source file parser. * properly passed from Javadoc to the source file parser.
* @author jamieh * @author jamieh
@ -40,12 +40,12 @@ public class TestEncoding extends JavadocTester {
//If ??? is found in the output, the source file was not read with the correct encoding setting. //If ??? is found in the output, the source file was not read with the correct encoding setting.
private static final String[][] NEGATED_TEST = { private static final String[][] NEGATED_TEST = {
{BUG_ID + FS + "EncodeTest.html", "???"} {BUG_ID + FS + "EncodeTest.html", "??"}
}; };
private static final String[] ARGS = private static final String[] ARGS =
new String[] { new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "-d", BUG_ID, "-sourcepath", SRC_DIR,
"-encoding", "SJIS", SRC_DIR + FS + "EncodeTest.java" "-encoding", "iso-8859-1", SRC_DIR + FS + "EncodeTest.java"
}; };
/** /**

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8002304 * @bug 8002304 8024096
* @summary Test for various method types in the method summary table * @summary Test for various method types in the method summary table
* @author Bhavesh Patel * @author Bhavesh Patel
* @library ../lib/ * @library ../lib/
@ -107,7 +107,7 @@ public class TestMethodTypes extends JavadocTester {
"</caption>" "</caption>"
}, },
{BUG_ID + FS + "pkg" + FS + "D.html", {BUG_ID + FS + "pkg1" + FS + "D.html",
"<caption><span>Methods</span><span class=\"tabEnd\">&nbsp;</span>" + "<caption><span>Methods</span><span class=\"tabEnd\">&nbsp;</span>" +
"</caption>" "</caption>"
}, },

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8006124 8009684 8016921 8023700 * @bug 8006124 8009684 8016921 8023700 8024096
* @summary Test javadoc support for profiles. * @summary Test javadoc support for profiles.
* @author Bhavesh Patel, Evgeniya Stepanova * @author Bhavesh Patel, Evgeniya Stepanova
* @library ../lib/ * @library ../lib/
@ -187,26 +187,6 @@ public class TestProfiles extends JavadocTester {
} }
}; };
private static final String[][] PACKAGES_NEGATED_TEST = { private static final String[][] PACKAGES_NEGATED_TEST = {
{PACKAGE_BUG_ID + FS + "profile-overview-frame.html",
"<span><a href=\"overview-frame.html\" "
+ "target=\"packageListFrame\">All&nbsp;Packages</a></span>"
},
{PACKAGE_BUG_ID + FS + "compact2-frame.html",
"<span><a href=\"overview-frame.html\" target=\"packageListFrame\">"
+ "All&nbsp;Packages</a></span><span><a href=\"profile-overview-frame.html\" "
+ "target=\"packageListFrame\">All&nbsp;Profiles</a></span>"
},
{PACKAGE_BUG_ID + FS + "pkg2" + FS + "compact2-package-frame.html",
"<a href=\"../compact2-summary.html\" target=\"classFrame\">"
+ "compact2</a> - <a href=\"../pkg2/compact2-package-summary.html\" "
+ "target=\"classFrame\">pkg2</a>"
},
{PACKAGE_BUG_ID + FS + "compact2-summary.html",
"<h1 title=\"Profile\" class=\"title\">Profile&nbsp;compact2</h1>"
},
{PACKAGE_BUG_ID + FS + "pkg5" + FS + "compact3-package-summary.html",
"<div class=\"subTitle\">compact3</div>"
},
{PACKAGE_BUG_ID + FS + "overview-frame.html", {PACKAGE_BUG_ID + FS + "overview-frame.html",
"<span><a href=\"profile-overview-frame.html\" " "<span><a href=\"profile-overview-frame.html\" "
+ "target=\"packageListFrame\">All&nbsp;Profiles</a></span>" + "target=\"packageListFrame\">All&nbsp;Profiles</a></span>"
@ -222,6 +202,13 @@ public class TestProfiles extends JavadocTester {
"</ul>" "</ul>"
} }
}; };
private static final String[] PACKAGES_NEGATED_FILE_TEST = {
PACKAGE_BUG_ID + FS + "profile-overview-frame.html",
PACKAGE_BUG_ID + FS + "compact2-frame.html",
PACKAGE_BUG_ID + FS + "pkg2" + FS + "compact2-package-frame.html",
PACKAGE_BUG_ID + FS + "compact2-summary.html",
PACKAGE_BUG_ID + FS + "pkg5" + FS + "compact3-package-summary.html"
};
/** /**
* The entry point of the test. * The entry point of the test.
@ -231,7 +218,7 @@ public class TestProfiles extends JavadocTester {
public static void main(String[] args) { public static void main(String[] args) {
TestProfiles tester = new TestProfiles(); TestProfiles tester = new TestProfiles();
run(tester, ARGS1, PROFILES_TEST, PROFILES_NEGATED_TEST); run(tester, ARGS1, PROFILES_TEST, PROFILES_NEGATED_TEST);
run(tester, ARGS2, PACKAGES_TEST, PACKAGES_NEGATED_TEST); run(tester, ARGS2, PACKAGES_TEST, PACKAGES_NEGATED_TEST, NO_FILE_TEST, PACKAGES_NEGATED_FILE_TEST);
tester.printSummary(); tester.printSummary();
} }