Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions test/hotspot/jtreg/sources/SortIncludes.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/// See [#main].
public class SortIncludes {
private static final String INCLUDE_LINE = "^ *# *include *(<[^>]+>|\"[^\"]+\") *$\\n";
private static final String BLANK_LINE = "^$\\n";
Expand Down Expand Up @@ -191,6 +193,12 @@ public static class UnsortedIncludesException extends Exception {
public UnsortedIncludesException(List<Path> files) {
this.files = files;
}

@Override
public String getMessage() {
String unsorted = files.stream().map(Path::toString).collect(Collectors.joining(System.lineSeparator()));
return String.format("%d files with unsorted headers found:%n%s", files.size(), unsorted);
}
}

/// Processes C++ files to check if their include statements are sorted.
Expand Down
6 changes: 1 addition & 5 deletions test/hotspot/jtreg/sources/TestIncludesAreSorted.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class TestIncludesAreSorted {
Expand Down Expand Up @@ -75,10 +74,7 @@ public static void main(String[] ignore) throws IOException {
try {
SortIncludes.main(args);
} catch (SortIncludes.UnsortedIncludesException e) {
String unsorted = e.files.stream().map(Path::toString).collect(Collectors.joining(System.lineSeparator()));
String msg = String.format("""
%d files with unsorted headers found:

%s

This should be fixable by running:
Expand All @@ -104,7 +100,7 @@ public static void main(String[] ignore) throws IOException {
#include "b.hpp"

""",
e.files.size(), unsorted,
e.getMessage(),
testSrcDir.resolve(SortIncludes.class.getSimpleName()),
String.join(" ", args));
throw new RuntimeException(msg);
Expand Down