Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ public void checkFiles(boolean expectedFound, Collection<String> paths) {
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:"));
}
}
}
Expand Down Expand Up @@ -946,9 +946,10 @@ protected void checking(String message) {
*
* @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);
}

/**
Expand All @@ -957,10 +958,14 @@ protected void passed(Path file, String message) {
* <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();
}

Expand All @@ -971,9 +976,10 @@ protected void passed(String message) {
*
* @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);
}

/**
Expand All @@ -982,8 +988,9 @@ protected void failed(Path file, String message) {
* <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"))
Expand All @@ -993,6 +1000,9 @@ protected void failed(String message) {
+ "(" + f.getFileName() + ":" + f.getLineNumber() + ")"));
return null;
});
for (var detail: details) {
detail.lines().forEachOrdered(out::println);
}
out.println();
}

Expand All @@ -1002,10 +1012,7 @@ private void print(String prefix, String message) {
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);
}
}

Expand Down Expand Up @@ -1219,25 +1226,28 @@ private void check(Function<Integer, Range> finder, SearchKind kind, String s) {
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);
}

}
Expand Down Expand Up @@ -1374,8 +1384,9 @@ public OutputChecker checkComplete() {
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(", ")));
}
Expand All @@ -1395,8 +1406,9 @@ public OutputChecker checkEmpty() {
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;
}
Expand Down Expand Up @@ -1444,7 +1456,8 @@ private <T> OutputChecker checkAnyOf(SearchKind kind, List<T> items, BiFunction<
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;
}
Expand Down
62 changes: 35 additions & 27 deletions test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public static void main(String... args) throws Exception {
* @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));
}

/**
Expand All @@ -85,9 +85,13 @@ public void passed(String message) {
* @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);
}

/**
Expand Down Expand Up @@ -138,6 +142,8 @@ void checkMessages(String... expect) {
testErrors++;
}
}

messages.forEach(m -> out.println("MESSAGES: " + m));
}

/**
Expand All @@ -153,7 +159,7 @@ void checkMessages(String... expect) {
* @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));
}

//-------------------------------------------------
Expand Down Expand Up @@ -202,13 +208,13 @@ public void testSimpleStringCheck() {
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""");
}

Expand All @@ -220,7 +226,7 @@ public void testSimpleNegativeStringCheck_expected() {
.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""");
}

Expand All @@ -231,7 +237,8 @@ public void testSimpleNegativeStringCheck_unexpected() {
.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""");
}

Expand All @@ -244,13 +251,13 @@ public void testSimpleRegexCheck() {
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""");
}

Expand All @@ -271,28 +278,28 @@ public void testOrdered() {

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()">"""
);
}
Expand All @@ -306,10 +313,10 @@ public void testUnordered_expected() {
"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""");
}

Expand All @@ -321,10 +328,11 @@ public void testUnordered_unexpected() {
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String toString(List<? extends DocTree> tags, Element element) {
String s = tags.toString();
if (s.contains("test")) {
throw new Error("demo error");
};
}
return s;
}
}
Expand Down Expand Up @@ -118,6 +118,8 @@ public class C { }""");
"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:""");
}
}