8319139: Improve diagnosability of JavadocTester
output
Reviewed-by: hannesw
This commit is contained in:
parent
7f47c51ace
commit
3660a90ad8
test/langtools/jdk/javadoc
lib/javadoc/tester
testJavadocTester
@ -827,9 +827,9 @@ public abstract class JavadocTester {
|
||||
Path file = outputDir.resolve(path);
|
||||
boolean isFound = Files.exists(file);
|
||||
if (isFound == expectedFound) {
|
||||
passed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
|
||||
passed(file, "file " + (isFound ? "found:" : "not found:"));
|
||||
} else {
|
||||
failed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
|
||||
failed(file, "file " + (isFound ? "found:" : "not found:"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -946,9 +946,10 @@ public abstract class JavadocTester {
|
||||
*
|
||||
* @param file the file that was the focus of the check
|
||||
* @param message a short description of the outcome
|
||||
* @param details optional additional details
|
||||
*/
|
||||
protected void passed(Path file, String message) {
|
||||
passed(file + ": " + message);
|
||||
protected void passed(Path file, String message, String... details) {
|
||||
passed(file + ": " + message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -957,10 +958,14 @@ public abstract class JavadocTester {
|
||||
* <p>This method should be called after previously calling {@code checking(...)}.
|
||||
*
|
||||
* @param message a short description of the outcome
|
||||
* @param details optional additional details
|
||||
*/
|
||||
protected void passed(String message) {
|
||||
protected void passed(String message, String... details) {
|
||||
numTestsPassed++;
|
||||
print("Passed", message);
|
||||
for (var detail: details) {
|
||||
detail.lines().forEachOrdered(out::println);
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
@ -971,9 +976,10 @@ public abstract class JavadocTester {
|
||||
*
|
||||
* @param file the file that was the focus of the check
|
||||
* @param message a short description of the outcome
|
||||
* @param details optional additional details
|
||||
*/
|
||||
protected void failed(Path file, String message) {
|
||||
failed(file + ": " + message);
|
||||
protected void failed(Path file, String message, String... details) {
|
||||
failed(file + ": " + message, details);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -982,8 +988,9 @@ public abstract class JavadocTester {
|
||||
* <p>This method should be called after previously calling {@code checking(...)}.
|
||||
*
|
||||
* @param message a short description of the outcome
|
||||
* @param details optional additional details
|
||||
*/
|
||||
protected void failed(String message) {
|
||||
protected void failed(String message, String... details) {
|
||||
print("FAILED", message);
|
||||
StackWalker.getInstance().walk(s -> {
|
||||
s.dropWhile(f -> f.getMethodName().equals("failed"))
|
||||
@ -993,6 +1000,9 @@ public abstract class JavadocTester {
|
||||
+ "(" + f.getFileName() + ":" + f.getLineNumber() + ")"));
|
||||
return null;
|
||||
});
|
||||
for (var detail: details) {
|
||||
detail.lines().forEachOrdered(out::println);
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
@ -1002,10 +1012,7 @@ public abstract class JavadocTester {
|
||||
else {
|
||||
out.print(prefix);
|
||||
out.print(": ");
|
||||
out.print(message.replace("\n", NL));
|
||||
if (!(message.endsWith("\n") || message.endsWith(NL))) {
|
||||
out.println();
|
||||
}
|
||||
message.lines().forEachOrdered(out::println);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1219,25 +1226,28 @@ public abstract class JavadocTester {
|
||||
boolean isFound = r != null;
|
||||
if (isFound == expectFound) {
|
||||
matches.add(lastMatch = r);
|
||||
passed(name + ": following " + kind + " " + (isFound ? "found:" : "not found:") + "\n"
|
||||
+ s);
|
||||
passed(name + ": the following " + kind + " was " + (isFound ? "found:" : "not found:"),
|
||||
s);
|
||||
} else {
|
||||
// item not found in order, so check if the item is found out of order, to determine the best message
|
||||
if (expectFound && expectOrdered && start > 0) {
|
||||
Range r2 = finder.apply(0);
|
||||
if (r2 != null) {
|
||||
failed(name + ": following " + kind + " was found on line "
|
||||
failed(name + ": output not as expected",
|
||||
">> the following " + kind + " was found on line "
|
||||
+ getLineNumber(r2.start)
|
||||
+ ", but not in order as expected, on or after line "
|
||||
+ getLineNumber(start)
|
||||
+ ":\n"
|
||||
+ s);
|
||||
+ getLineNumber(start),
|
||||
">> " + kind + ":",
|
||||
s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
failed(name + ": following " + kind + " "
|
||||
+ (isFound ? "found:" : "not found:") + "\n"
|
||||
+ s + '\n' + "found \n" + content);
|
||||
failed(name + ": output not as expected",
|
||||
">> the following " + kind + " was " + (isFound ? "found:" : "not found:"),
|
||||
s,
|
||||
">> found",
|
||||
content);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1374,8 +1384,9 @@ public abstract class JavadocTester {
|
||||
if (uncovered.isEmpty()) {
|
||||
passed("All output matched");
|
||||
} else {
|
||||
failed("The following output was not matched: "
|
||||
+ uncovered.stream()
|
||||
failed("Output not as expected",
|
||||
">> The following output was not matched",
|
||||
uncovered.stream()
|
||||
.map(Range::toIntervalString)
|
||||
.collect(Collectors.joining(", ")));
|
||||
}
|
||||
@ -1395,8 +1406,9 @@ public abstract class JavadocTester {
|
||||
if (content == null || content.isEmpty()) {
|
||||
passed(name + " is empty, as expected");
|
||||
} else {
|
||||
failed(name + " is not empty; contains:\n"
|
||||
+ content);
|
||||
failed(name + " is not empty",
|
||||
">> found:",
|
||||
content);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -1444,7 +1456,8 @@ public abstract class JavadocTester {
|
||||
if (count == 0) {
|
||||
failed("no match found for any " + kind);
|
||||
} else {
|
||||
passed(count + " matches found; earliest is " + earliest.toIntervalString());
|
||||
passed(count + " matches found",
|
||||
">> the earliest is: " + earliest.toIntervalString());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ public class TestJavadocTester extends JavadocTester {
|
||||
* @param message a short description of the outcome
|
||||
*/
|
||||
@Override
|
||||
public void passed(String message) {
|
||||
super.passed(message);
|
||||
messages.add("Passed: " + message);
|
||||
public void passed(String message, String... details) {
|
||||
super.passed(message, details);
|
||||
messages.add("Passed: " + join(message, details));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,9 +85,13 @@ public class TestJavadocTester extends JavadocTester {
|
||||
* @param message a short description of the outcome
|
||||
*/
|
||||
@Override
|
||||
public void failed(String message) {
|
||||
super.failed(message);
|
||||
messages.add("FAILED: " + message);
|
||||
public void failed(String message, String... details) {
|
||||
super.failed(message, details);
|
||||
messages.add("FAILED: " + join(message, details));
|
||||
}
|
||||
|
||||
private String join(String message, String... details) {
|
||||
return details.length == 0 ? message : message + "\n" + String.join("\n", details);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,6 +142,8 @@ public class TestJavadocTester extends JavadocTester {
|
||||
testErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
messages.forEach(m -> out.println("MESSAGES: " + m));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +159,7 @@ public class TestJavadocTester extends JavadocTester {
|
||||
* @param message the message to be reported.
|
||||
*/
|
||||
private void report(String message) {
|
||||
message.lines().forEachOrdered(l -> out.println(">>> " + l));
|
||||
message.lines().forEachOrdered(l -> out.println(">>>> " + l));
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
@ -202,13 +208,13 @@ public class TestJavadocTester extends JavadocTester {
|
||||
messages.forEach(this::report);
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
Second sentence""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
abc123""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
def456""");
|
||||
}
|
||||
|
||||
@ -220,7 +226,7 @@ public class TestJavadocTester extends JavadocTester {
|
||||
.check("Third sentence.");
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following text not found:
|
||||
Passed: out/p/C.html: the following text was not found:
|
||||
Third sentence""");
|
||||
}
|
||||
|
||||
@ -231,7 +237,8 @@ public class TestJavadocTester extends JavadocTester {
|
||||
.check("Third sentence.");
|
||||
checkMessages(
|
||||
"""
|
||||
FAILED: out/p/C.html: following text not found:
|
||||
FAILED: out/p/C.html: output not as expected
|
||||
>> the following text was not found:
|
||||
Third sentence""");
|
||||
}
|
||||
|
||||
@ -244,13 +251,13 @@ public class TestJavadocTester extends JavadocTester {
|
||||
Pattern.compile("d.f4.6"));
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following pattern found:
|
||||
Passed: out/p/C.html: the following pattern was found:
|
||||
S.cond s.nt.nc.""",
|
||||
"""
|
||||
Passed: out/p/C.html: following pattern found:
|
||||
Passed: out/p/C.html: the following pattern was found:
|
||||
[abc]{3}[123]{3}""",
|
||||
"""
|
||||
Passed: out/p/C.html: following pattern found:
|
||||
Passed: out/p/C.html: the following pattern was found:
|
||||
d.f4.6""");
|
||||
}
|
||||
|
||||
@ -271,28 +278,28 @@ public class TestJavadocTester extends JavadocTester {
|
||||
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<h2>Method Summary</h2>""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<a href="#m1()" class="member-name-link">m1</a>""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<a href="#m2()" class="member-name-link">m2</a>""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<a href="#m3()" class="member-name-link">m3</a>""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<h2>Method Details</h2>""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<section class="detail" id="m3()">""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<section class="detail" id="m2()">""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
<section class="detail" id="m1()">"""
|
||||
);
|
||||
}
|
||||
@ -306,10 +313,10 @@ public class TestJavadocTester extends JavadocTester {
|
||||
"First sentence");
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
Second sentence""",
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
First sentence""");
|
||||
}
|
||||
|
||||
@ -321,10 +328,11 @@ public class TestJavadocTester extends JavadocTester {
|
||||
"First sentence");
|
||||
checkMessages(
|
||||
"""
|
||||
Passed: out/p/C.html: following text found:
|
||||
Passed: out/p/C.html: the following text was found:
|
||||
Second sentence""",
|
||||
"""
|
||||
FAILED: out/p/C.html: following text was found on line""");
|
||||
FAILED: out/p/C.html: output not as expected
|
||||
>> the following text was found on line""");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -86,7 +86,7 @@ public class TestJavadocTesterCrash extends TestJavadocTester {
|
||||
String s = tags.toString();
|
||||
if (s.contains("test")) {
|
||||
throw new Error("demo error");
|
||||
};
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@ -118,6 +118,8 @@ public class TestJavadocTesterCrash extends TestJavadocTester {
|
||||
"1 error");
|
||||
|
||||
// verify that JavadocTester detected the crash
|
||||
checkMessages("FAILED: STDERR: following text found:");
|
||||
checkMessages("""
|
||||
FAILED: STDERR: output not as expected
|
||||
>> the following text was found:""");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user