Skip to content

Commit

Permalink
Merge branch 'main-eisop' of github.com:jspecify/jspecify-reference-c…
Browse files Browse the repository at this point in the history
…hecker into issue-159-again
  • Loading branch information
wmdietl committed Apr 17, 2024
2 parents 55b243d + 0c36cdf commit 2eecb6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/test/java/tests/ConformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
Expand Down Expand Up @@ -143,7 +142,6 @@ private static ImmutableSet<ReportedFact> analyze(
TypecheckResult result = new TypecheckExecutor().runTest(config);
return result.getUnexpectedDiagnostics().stream()
.map(d -> DetailMessage.parse(d, testDirectory))
.filter(Objects::nonNull)
// Do not filter out messages without details.
// .filter(DetailMessage::hasDetails)
.map(DetailMessageReportedFact::new)
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/tests/DetailMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ final class DetailMessage extends TestDiagnostic {
final String readableMessage;

/**
* Returns an object parsed from a diagnostic message, or {@code null} if the message doesn't
* match the expected format.
* Returns an object parsed from a diagnostic message.
*
* @param rootDirectory if not null, a root directory prefix to remove from the file part of the
* message
*/
static @Nullable DetailMessage parse(TestDiagnostic input, @Nullable Path rootDirectory) {
static DetailMessage parse(TestDiagnostic input, @Nullable Path rootDirectory) {
Path file = input.getFile();
if (rootDirectory != null && file.startsWith(rootDirectory)) {
file = rootDirectory.relativize(file);
}

Matcher detailsMatcher = DETAIL_MESSAGE_PATTERN.matcher(input.getMessage());
if (!detailsMatcher.matches()) {
// Return a message with no key or parts.
return new DetailMessage(
input.getFile(),
file,
input.getLineNumber(),
input.getKind(),
"",
Expand All @@ -75,10 +79,6 @@ final class DetailMessage extends TestDiagnostic {
null,
input.getMessage());
}
Path file = input.getFile();
if (rootDirectory != null) {
file = rootDirectory.relativize(file);
}

int messagePartCount = parseInt(detailsMatcher.group("messagePartCount"));
List<String> messageParts =
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/tests/NullSpecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public TypecheckResult adjustTypecheckResult(TypecheckResult testResult) {
for (ListIterator<TestDiagnostic> i = unexpected.listIterator(); i.hasNext(); ) {
TestDiagnostic diagnostic = i.next();
DetailMessage detailMessage = DetailMessage.parse(diagnostic, null);
if (detailMessage != null && detailMessage.hasDetails()) {
if (detailMessage.hasDetails()) {
// Replace diagnostics that can be parsed with DetailMessage diagnostics.
i.set(detailMessage);
} else if (diagnostic.getKind() != DiagnosticKind.Error) {
Expand Down

0 comments on commit 2eecb6e

Please sign in to comment.