diff --git a/cribro-core/build.gradle.kts b/cribro-core/build.gradle.kts
index ac15906..af70854 100644
--- a/cribro-core/build.gradle.kts
+++ b/cribro-core/build.gradle.kts
@@ -5,7 +5,7 @@ plugins {
id("cribro.publish")
}
-description = "Git diff parsing, JaCoCo report reading, and the PIT interceptor shared by the cribro Gradle and Maven plugins"
+description = "Git diff parsing, JaCoCo report reading, and the PIT interceptor shared by the cribro Gradle and Maven plugins; not an API, as its classes change with each plugin release"
dependencies {
// PIT supplies these classes when it loads the interceptor; the jar has no runtime dependency.
diff --git a/cribro-core/src/main/java/io/github/cribrodev/EquivalentMarkers.java b/cribro-core/src/main/java/io/github/cribrodev/EquivalentMarkers.java
new file mode 100644
index 0000000..4fd2597
--- /dev/null
+++ b/cribro-core/src/main/java/io/github/cribrodev/EquivalentMarkers.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2026 cribro contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.cribrodev;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * The {@code mutant: equivalent} markers of one source line, such as {@code // mutant: equivalent
+ * RemoveConditionalMutator_EQUAL_ELSE#2 -- annotate only receives class and array types}.
+ *
+ *
A marker names one or more mutants of the line it sits on, by the ids the mutation report
+ * prints, separated by commas, and gives the reason after {@code --}. A marker starts at a comment
+ * opener, a {@code //} or a {@code /} followed by one or more {@code *}, where that opener starts a
+ * comment or lies inside a line comment, even where the line comment only quotes the syntax. Any
+ * other text, such as a string or anything inside a block comment, starts no marker. The reason
+ * runs to the end of the comment the marker is in or of the line, whichever comes first, except
+ * that a {@code /*} marker inside a line comment ends at the first {@code *}{@code /} before that.
+ * An id may name the mutator with its package, as PIT does, and the package is dropped.
+ *
+ *
Each line is read with the whole file around it, as {@link SourceFileKey#regions} splits it,
+ * so a line inside a text block, a Kotlin raw string, or a block comment opened on an earlier line
+ * is read as part of it.
+ */
+final class EquivalentMarkers {
+
+ /**
+ * The start of a marker: a comment opener, then {@code mutant: equivalent}. The run of {@code *}
+ * after a {@code /} is matched possessively, so a long run takes linear time.
+ */
+ private static final Pattern START =
+ Pattern.compile("(//|/\\*++)\\s*mutant:\\s*equivalent(?![\\w-])");
+
+ /** The {@code --} that ends the ids and starts the reason, with whitespace on both sides. */
+ private static final Pattern REASON = Pattern.compile("\\s--\\s");
+
+ /** One id, as the report prints it: any run of characters but whitespace and commas. */
+ private static final Pattern ID = Pattern.compile("[^\\s,]+");
+
+ /** How a marker is written, for a reader whose marker does not parse. */
+ static final String FORM = "// mutant: equivalent -- ";
+
+ private final Map reasons;
+ private final List problems;
+ private final String code;
+ private final String text;
+
+ private EquivalentMarkers(
+ Map reasons, List problems, String code, String text) {
+ this.reasons = reasons;
+ this.problems = problems;
+ this.code = code;
+ this.text = text;
+ }
+
+ /**
+ * Reads the markers of each line of a file, which may hold none.
+ *
+ * @param lines every line of the file, from the first
+ * @param kotlin whether the file is Kotlin, whose strings hold {@code ${...}} templates
+ * @return the markers of each line, in the order of the lines
+ */
+ static List parse(List lines, boolean kotlin) {
+ SourceFileKey.Region[] regions = SourceFileKey.regions(String.join("\n", lines), kotlin);
+ List parsed = new ArrayList<>(lines.size());
+ int start = 0;
+ for (String line : lines) {
+ parsed.add(parse(line, Arrays.copyOfRange(regions, start, start + line.length())));
+ start += line.length() + 1;
+ }
+ return parsed;
+ }
+
+ /**
+ * Reads the markers of a file that has one line.
+ *
+ * @param kotlin whether the line is Kotlin, whose strings hold {@code ${...}} templates
+ */
+ static EquivalentMarkers parse(String line, boolean kotlin) {
+ return parse(List.of(line), kotlin).get(0);
+ }
+
+ /**
+ * Reads the markers of one line.
+ *
+ * @param regions the region each character of the line lies in
+ */
+ private static EquivalentMarkers parse(String line, SourceFileKey.Region[] regions) {
+ Map reasons = new LinkedHashMap<>();
+ List problems = new ArrayList<>();
+ StringBuilder code = new StringBuilder();
+ Matcher start = START.matcher(line);
+ int copied = 0;
+ int from = 0;
+ while (from < line.length() && start.find(from)) {
+ if (!opensMarker(regions[start.start()])) {
+ from = start.start() + 1;
+ continue;
+ }
+ int bodyEnd = start.end();
+ int markerEnd;
+ if (regions[start.start()] == SourceFileKey.Region.LINE_COMMENT) {
+ while (bodyEnd < line.length() && regions[bodyEnd] == SourceFileKey.Region.LINE_COMMENT) {
+ bodyEnd++;
+ }
+ markerEnd = bodyEnd;
+ // A /* inside a line comment opens no comment, so its marker ends at the first */.
+ int close = start.group(1).equals("//") ? -1 : line.indexOf("*/", start.end());
+ if (close >= 0 && close + 2 <= bodyEnd) {
+ bodyEnd = close;
+ markerEnd = close + 2;
+ }
+ } else {
+ while (bodyEnd < line.length() && regions[bodyEnd] == SourceFileKey.Region.BLOCK_COMMENT) {
+ bodyEnd++;
+ }
+ markerEnd = bodyEnd;
+ while (markerEnd < line.length()
+ && regions[markerEnd] == SourceFileKey.Region.BLOCK_COMMENT_END) {
+ markerEnd++;
+ }
+ }
+ code.append(line, copied, start.start());
+ copied = markerEnd;
+ from = markerEnd;
+ if (!readBody(line.substring(start.end(), bodyEnd), reasons)) {
+ problems.add("the marker does not parse; write it as " + FORM);
+ }
+ }
+ code.append(line.substring(Math.min(copied, line.length())));
+ return new EquivalentMarkers(reasons, problems, code.toString().strip(), line.strip());
+ }
+
+ /** Returns whether a marker may start at a comment opener that lies in the given region. */
+ private static boolean opensMarker(SourceFileKey.Region region) {
+ return region == SourceFileKey.Region.LINE_COMMENT
+ || region == SourceFileKey.Region.BLOCK_COMMENT_START;
+ }
+
+ /**
+ * Adds the ids the body of one marker names, each with its reason, and returns whether the body
+ * holds at least one id, the {@code --}, and a reason.
+ */
+ private static boolean readBody(String body, Map reasons) {
+ Matcher separator = REASON.matcher(body);
+ if (!separator.find()) {
+ return false;
+ }
+ String reason = body.substring(separator.end()).strip();
+ String[] ids = body.substring(0, separator.start()).split(",", -1);
+ if (reason.isEmpty()) {
+ return false;
+ }
+ List named = new ArrayList<>();
+ for (String id : ids) {
+ String trimmed = id.strip();
+ if (!ID.matcher(trimmed).matches()) {
+ return false;
+ }
+ int hash = trimmed.indexOf('#');
+ int packageEnd = trimmed.lastIndexOf('.', hash < 0 ? trimmed.length() : hash);
+ String name = trimmed.substring(packageEnd + 1);
+ if (name.isEmpty() || name.startsWith("#")) {
+ return false;
+ }
+ named.add(name);
+ }
+ for (String id : named) {
+ reasons.putIfAbsent(id, reason);
+ }
+ return true;
+ }
+
+ /** Returns the reason given for each id the markers name, in the order they name them. */
+ Map reasons() {
+ return reasons;
+ }
+
+ /** Returns a sentence for each marker that does not parse. */
+ List problems() {
+ return problems;
+ }
+
+ /** Returns the line without its markers, stripped, as the lists of mutants quote it. */
+ String code() {
+ return code;
+ }
+
+ /** Returns the line with its markers, stripped, as the list of markers to correct quotes it. */
+ String text() {
+ return text;
+ }
+}
diff --git a/cribro-core/src/main/java/io/github/cribrodev/MutantsFile.java b/cribro-core/src/main/java/io/github/cribrodev/MutantsFile.java
index e597ce8..799b22f 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/MutantsFile.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/MutantsFile.java
@@ -27,9 +27,10 @@
* Writes and reads the mutants of one PIT run as a text file, one mutant per line.
*
* A line holds tab-separated fields: the status PIT gave the mutant, the mutated class, the
- * method, the source file the class records, the line number, the description, and then the tests
- * PIT recorded as covering the mutant, one per field. A tab or a line break inside a field is
- * written as a space.
+ * method, its descriptor, the source file the class records, the line number, the mutator, the
+ * index of the first instruction the mutant changes, the description, and then the tests PIT
+ * recorded as covering the mutant, one per field. A tab or a line break inside a field is written
+ * as a space.
*
*
The PIT listener in {@code io.github.cribrodev.pitest} writes the file inside the PIT
* process and the build reads it, so this class depends on nothing but the JDK.
@@ -52,8 +53,11 @@ public static final class Mutant {
private final String status;
private final String mutatedClass;
private final String method;
+ private final String methodDescriptor;
private final String sourceFile;
private final int lineNumber;
+ private final String mutator;
+ private final int firstIndex;
private final String description;
private final List tests;
@@ -61,15 +65,21 @@ public Mutant(
String status,
String mutatedClass,
String method,
+ String methodDescriptor,
String sourceFile,
int lineNumber,
+ String mutator,
+ int firstIndex,
String description,
List tests) {
this.status = status;
this.mutatedClass = mutatedClass;
this.method = method;
+ this.methodDescriptor = methodDescriptor;
this.sourceFile = sourceFile;
this.lineNumber = lineNumber;
+ this.mutator = mutator;
+ this.firstIndex = firstIndex;
this.description = description;
this.tests = tests;
}
@@ -88,6 +98,11 @@ public String method() {
return method;
}
+ /** Returns the descriptor of the method, such as {@code (I)Z}. */
+ public String methodDescriptor() {
+ return methodDescriptor;
+ }
+
public String sourceFile() {
return sourceFile;
}
@@ -96,6 +111,23 @@ public int lineNumber() {
return lineNumber;
}
+ /**
+ * Returns the mutator as PIT names it, such as {@code
+ * org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE}.
+ */
+ public String mutator() {
+ return mutator;
+ }
+
+ /**
+ * Returns the index of the first instruction the mutant changes, counted from the start of its
+ * method; of two mutants in one method, the one with the lower index comes first in its
+ * bytecode.
+ */
+ public int firstIndex() {
+ return firstIndex;
+ }
+
public String description() {
return description;
}
@@ -106,6 +138,9 @@ public List tests() {
}
}
+ /** The fields every line holds before the tests. */
+ private static final int FIXED_FIELDS = 9;
+
private MutantsFile() {}
/** Returns the line the file holds for one mutant, without the line break. */
@@ -114,8 +149,11 @@ public static String line(Mutant mutant) {
fields.add(mutant.status());
fields.add(mutant.mutatedClass());
fields.add(mutant.method());
+ fields.add(mutant.methodDescriptor());
fields.add(mutant.sourceFile());
fields.add(Integer.toString(mutant.lineNumber()));
+ fields.add(mutant.mutator());
+ fields.add(Integer.toString(mutant.firstIndex()));
fields.add(mutant.description());
fields.addAll(mutant.tests());
List cleaned = new ArrayList<>();
@@ -133,8 +171,9 @@ public static List read(Path file) throws IOException {
continue;
}
String[] fields = line.split("\t", -1);
- if (fields.length < 6) {
- throw new IOException("Fewer than 6 fields in " + file + " line: " + line);
+ if (fields.length < FIXED_FIELDS) {
+ throw new IOException(
+ "Fewer than " + FIXED_FIELDS + " fields in " + file + " line: " + line);
}
mutants.add(
new Mutant(
@@ -142,9 +181,12 @@ public static List read(Path file) throws IOException {
fields[1],
fields[2],
fields[3],
- Integer.parseInt(fields[4]),
- fields[5],
- List.copyOf(Arrays.asList(fields).subList(6, fields.length))));
+ fields[4],
+ Integer.parseInt(fields[5]),
+ fields[6],
+ Integer.parseInt(fields[7]),
+ fields[8],
+ List.copyOf(Arrays.asList(fields).subList(FIXED_FIELDS, fields.length))));
}
return mutants;
}
diff --git a/cribro-core/src/main/java/io/github/cribrodev/PitestRun.java b/cribro-core/src/main/java/io/github/cribrodev/PitestRun.java
index fc015b6..307da5a 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/PitestRun.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/PitestRun.java
@@ -346,6 +346,7 @@ public static String report(
repository,
sourceDirs,
ChangedLinesFile.readPaths(changedLines.toPath()),
+ ChangedLinesFile.read(changedLines.toPath()),
withBytecode.isFile() ? ChangedLinesFile.read(withBytecode.toPath()) : null);
return report.writeAndRender(
repository,
diff --git a/cribro-core/src/main/java/io/github/cribrodev/PitestSurvivors.java b/cribro-core/src/main/java/io/github/cribrodev/PitestSurvivors.java
index 720f7ea..bc76ddf 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/PitestSurvivors.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/PitestSurvivors.java
@@ -31,6 +31,8 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.function.BiConsumer;
+import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -45,11 +47,17 @@
* NON_VIABLE} for a mutant the JVM would not load, says nothing about the tests and is counted
* under its own name.
*
- * Each line is printed once, with its source text, every live mutant on it, the number of tests
- * PIT recorded as reaching it, and the few of them that reach the most live mutants of the report.
+ *
The list of live mutants prints each line once, with its source text, the live mutants on it
+ * that no marker acknowledges, the number of tests PIT recorded as reaching them, and the few of
+ * those tests that reach the most live mutants of the report.
* A parameterized or dynamic test counts as one test, and its name lists the invocations that
* reach the line, such as {@code CoreQuidemTest.test[1-3, 33]}. The mutants and their tests come
* from the {@link MutantsFile} the PIT listener writes.
+ *
+ *
A live mutant that an {@link EquivalentMarkers equivalent marker} on its changed line names is
+ * counted as it is and listed apart, with the reason, rather than among the live mutants. A marker
+ * on a changed line that does not parse, or has an id that names no live mutant of the line, is
+ * listed too.
*/
public final class PitestSurvivors {
@@ -64,7 +72,8 @@ public final class PitestSurvivors {
+ " - the tests miss behavior the change defines: add or strengthen a test,"
+ " next to the tests named for its line\n"
+ " - no caller can observe the difference, so the mutant is equivalent:"
- + " say so in the pull request\n"
+ + " add // mutant: equivalent -- to its line, where is the text in"
+ + " brackets after the mutant, and say so in the pull request\n"
+ " - you cannot tell: report it as unresolved";
/**
@@ -78,6 +87,20 @@ public final class PitestSurvivors {
+ " or the tests that do failed under PIT, which leaves them out silently; pit.log beside"
+ " the report names each test that failed.";
+ /**
+ * What the reader of a report with a marker to correct does with it.
+ *
+ * A marker records a verdict on the code its line held when the marker was written, so a
+ * marker the run cannot match asks for the line to be judged again rather than for the marker to
+ * be deleted unread.
+ */
+ static final String MARKERS_TO_CORRECT =
+ "For each marker listed, judge the mutants of its line again against the code as it is now:"
+ + " correct an id that names no mutant, remove an id whose mutant is not live, and complete"
+ + " a marker that does not parse. An id of a mutator this run did not use, such as"
+ + " RemoveConditionalMutator_EQUAL_ELSE in a run with DEFAULTS, names no mutant here:"
+ + " keep it, and check it in a run with the mutator group it was written for.";
+
/**
* Why a changed line can have no mutant, for a reader who expected one.
*
@@ -97,15 +120,26 @@ public final class PitestSurvivors {
private static final class Mutant {
private final String description;
private final String method;
+ private final String id;
+ private final String reason;
private final Map>> tests;
/**
+ * @param id the id that names the mutant in a marker, as {@link PitestSurvivors#ids} returns it
+ * @param reason the reason the marker on its line gives, or null where no marker names it
* @param tests the short name of each test that reaches the mutant, with the invocations of
* it PIT named; the set is empty for a test PIT names with no invocation
*/
- Mutant(String description, String method, Map>> tests) {
+ Mutant(
+ String description,
+ String method,
+ String id,
+ String reason,
+ Map>> tests) {
this.description = description;
this.method = method;
+ this.id = id;
+ this.reason = reason;
this.tests = tests;
}
@@ -117,26 +151,50 @@ String method() {
return method;
}
+ String id() {
+ return id;
+ }
+
+ String reason() {
+ return reason;
+ }
+
Map>> tests() {
return tests;
}
}
- /** The live mutants of one source line, and the tests that reach it. */
+ /**
+ * One changed line of the report: its live mutants and the tests that reach them, the live
+ * mutants a marker acknowledges, and what is wrong with the markers on it.
+ */
private static final class Line {
private final int number;
private final String source;
+ private final String text;
private final List mutants;
+ private final List acknowledged;
+ private final List markerProblems;
private final Map>> tests;
+ /**
+ * @param source the line without its markers, as the lists of mutants quote it
+ * @param text the line as written, as the list of markers to correct quotes it
+ */
Line(
int number,
String source,
+ String text,
List mutants,
+ List acknowledged,
+ List markerProblems,
Map>> tests) {
this.number = number;
this.source = source;
+ this.text = text;
this.mutants = mutants;
+ this.acknowledged = acknowledged;
+ this.markerProblems = markerProblems;
this.tests = tests;
}
@@ -148,16 +206,30 @@ String source() {
return source;
}
+ String text() {
+ return text;
+ }
+
+ /** Returns the live mutants no marker acknowledges. */
List mutants() {
return mutants;
}
+ List acknowledged() {
+ return acknowledged;
+ }
+
+ List markerProblems() {
+ return markerProblems;
+ }
+
+ /** Returns the tests that reach the mutants {@link #mutants()} returns. */
Map>> tests() {
return tests;
}
}
- /** The live mutants of one source file. */
+ /** The lines of one source file that one part of the report lists. */
private static final class FileMutants {
private final String path;
private final List lines;
@@ -177,6 +249,7 @@ List lines() {
return lines;
}
+ /** Returns the number of live mutants no marker acknowledges. */
int mutantCount() {
return mutantCount;
}
@@ -188,12 +261,20 @@ int mutantCount() {
private final int total;
private final int mutatedLines;
private final int linesWithBytecode;
+ private final int acknowledgedCount;
private final List files;
+ private final List acknowledgedFiles;
+ private final List markerProblemFiles;
/**
* @param mutatedLines the number of changed lines that carry at least one mutant
* @param linesWithBytecode the number of changed lines with bytecode, or -1 where the run did not
* record them
+ * @param files the files with live mutants no marker acknowledges, each with those lines alone
+ * @param acknowledgedFiles the files with live mutants a marker acknowledges, each with those
+ * lines alone
+ * @param markerProblemFiles the files with a marker that does not parse or has an id naming no
+ * live mutant of its line, each with those lines alone
*/
private PitestSurvivors(
String scope,
@@ -202,7 +283,9 @@ private PitestSurvivors(
int total,
int mutatedLines,
int linesWithBytecode,
- List files) {
+ List files,
+ List acknowledgedFiles,
+ List markerProblemFiles) {
this.scope = scope;
this.testOrder = testOrder;
this.statusCounts = statusCounts;
@@ -210,6 +293,13 @@ private PitestSurvivors(
this.mutatedLines = mutatedLines;
this.linesWithBytecode = linesWithBytecode;
this.files = files;
+ this.acknowledgedFiles = acknowledgedFiles;
+ this.markerProblemFiles = markerProblemFiles;
+ this.acknowledgedCount =
+ acknowledgedFiles.stream()
+ .flatMap(file -> file.lines().stream())
+ .mapToInt(line -> line.acknowledged().size())
+ .sum();
}
/**
@@ -224,6 +314,9 @@ private PitestSurvivors(
* @param paths the repository-relative path of each changed file, keyed by {@link
* SourceFileKey}, as the {@link ChangedLinesFile} of the run records them; a Kotlin file may
* lie in a directory that does not follow its package, so its key alone finds no file
+ * @param changedLines the changed lines, keyed by {@link SourceFileKey}, as the {@link
+ * ChangedLinesFile} of the run records them; a {@code mutant: equivalent} marker is read
+ * only on these lines
* @param linesWithBytecode the changed lines with bytecode that hold code, as {@link
* CodeLines#holdsCode} decides, keyed by {@link SourceFileKey}, as the run records them in
* the file {@link ChangedLinesFile#WITH_BYTECODE} names, or null
@@ -236,6 +329,7 @@ public static PitestSurvivors read(
File repository,
List sourceRoots,
Map paths,
+ Map> changedLines,
Map> linesWithBytecode)
throws IOException {
Set withBytecode = new HashSet<>();
@@ -243,23 +337,12 @@ public static PitestSurvivors read(
linesWithBytecode.forEach(
(key, lines) -> lines.forEach(line -> withBytecode.add(key + ":" + line)));
}
- if (!mutantsFile.isFile()) {
- return new PitestSurvivors(
- scope,
- Comparator.naturalOrder(),
- new LinkedHashMap<>(),
- 0,
- 0,
- linesWithBytecode == null ? -1 : withBytecode.size(),
- new ArrayList<>());
- }
- List reported = MutantsFile.read(mutantsFile.toPath());
+ List reported =
+ mutantsFile.isFile() ? MutantsFile.read(mutantsFile.toPath()) : List.of();
Set mutated = new HashSet<>();
Map statusCounts = new LinkedHashMap<>();
- Map>> byFile = new HashMap<>();
- // Every mutant of a line names the tests that reach the line, so the same test names repeat
- // once per mutant, and each is shortened once.
- Map shortTestNames = new HashMap<>();
+ // Every mutant of the run, whatever its status, since a marker may name a killed one.
+ Map>> byFile = new HashMap<>();
for (MutantsFile.Mutant mutant : reported) {
statusCounts.merge(mutant.status(), 1, Integer::sum);
int packageEnd = mutant.mutatedClass().lastIndexOf('.');
@@ -268,29 +351,26 @@ public static PitestSurvivors read(
packageEnd < 0 ? "" : mutant.mutatedClass().substring(0, packageEnd).replace('.', '/'),
mutant.sourceFile());
mutated.add(relative + ":" + mutant.lineNumber());
- if (!isLive(mutant.status())) {
- continue;
- }
- Map>> tests = new TreeMap<>();
- for (String test : mutant.tests()) {
- TestName name = shortTestNames.computeIfAbsent(test, PitestSurvivors::shortTestName);
- NavigableSet> invocations =
- tests.computeIfAbsent(name.name(), unused -> new TreeSet<>(INVOCATION_ORDER));
- if (!name.invocation().isEmpty()) {
- invocations.add(name.invocation());
- }
- }
- String description =
- (mutant.status().equals("NO_COVERAGE") ? "no test reaches it: " : "survived: ")
- + DESCRIPTION_SUFFIX.matcher(mutant.description()).replaceFirst("");
byFile
.computeIfAbsent(relative, unused -> new TreeMap<>())
.computeIfAbsent(mutant.lineNumber(), unused -> new ArrayList<>())
- .add(new Mutant(description, readableMethod(mutant.method()), tests));
+ .add(mutant);
}
+ // A marker on a changed line that carries no mutant names no mutant, and the report says so.
+ changedLines.forEach(
+ (key, lines) -> {
+ TreeMap> file =
+ byFile.computeIfAbsent(key, unused -> new TreeMap<>());
+ lines.forEach(line -> file.computeIfAbsent(line, unused -> new ArrayList<>()));
+ });
+ // Every mutant of a line names the tests that reach the line, so the same test names repeat
+ // once per mutant, and each is shortened once.
+ Map shortTestNames = new HashMap<>();
SourceLines sourceLines = SourceLines.under(repository);
List files = new ArrayList<>();
- for (Map.Entry>> file : byFile.entrySet()) {
+ List acknowledgedFiles = new ArrayList<>();
+ List markerProblemFiles = new ArrayList<>();
+ for (Map.Entry>> file : byFile.entrySet()) {
String known = paths.get(file.getKey());
File source =
known != null && new File(repository, known).isFile()
@@ -298,38 +378,39 @@ public static PitestSurvivors read(
: locate(sourceRoots, file.getKey());
String path =
source == null ? file.getKey() : SourceLines.relativize(repository, source);
+ List markers =
+ EquivalentMarkers.parse(
+ source == null ? List.of() : sourceLines.lines(path),
+ path.endsWith(".kt"));
List lines = new ArrayList<>();
- for (Map.Entry> line : file.getValue().entrySet()) {
+ for (Map.Entry> line : file.getValue().entrySet()) {
int number = line.getKey();
- Map>> tests = new TreeMap<>();
- for (Mutant mutant : line.getValue()) {
- mutant
- .tests()
- .forEach(
- (name, invocations) ->
- tests
- .computeIfAbsent(name, unused -> new TreeSet<>(INVOCATION_ORDER))
- .addAll(invocations));
- }
- lines.add(
- new Line(
+ Line read =
+ readLine(
number,
- source == null ? "" : sourceLines.get(path, number).trim(),
+ number >= 1 && number <= markers.size()
+ ? markers.get(number - 1)
+ : EquivalentMarkers.parse("", false),
line.getValue(),
- tests));
+ shortTestNames);
+ if (read != null) {
+ lines.add(read);
+ }
}
- files.add(new FileMutants(path, lines));
+ addLines(files, path, lines, line -> !line.mutants().isEmpty());
+ addLines(acknowledgedFiles, path, lines, line -> !line.acknowledged().isEmpty());
+ addLines(markerProblemFiles, path, lines, line -> !line.markerProblems().isEmpty());
}
- files.sort(
- Comparator.comparingInt(FileMutants::mutantCount)
- .reversed()
- .thenComparing(FileMutants::path));
+ Comparator byPath = Comparator.comparing(FileMutants::path);
+ files.sort(Comparator.comparingInt(FileMutants::mutantCount).reversed().thenComparing(byPath));
+ acknowledgedFiles.sort(byPath);
+ markerProblemFiles.sort(byPath);
// A line most of the suite reaches is reached by tests unrelated to the change, so the tests
// named for it are the ones that reach the most live mutants of the whole report.
Map liveMutantsReached = new HashMap<>();
- for (TreeMap> lines : byFile.values()) {
- for (List mutants : lines.values()) {
- for (Mutant mutant : mutants) {
+ for (FileMutants file : files) {
+ for (Line line : file.lines()) {
+ for (Mutant mutant : line.mutants()) {
mutant.tests().keySet().forEach(test -> liveMutantsReached.merge(test, 1, Integer::sum));
}
}
@@ -348,7 +429,203 @@ public static PitestSurvivors read(
reported.size(),
mutated.size(),
linesWithBytecode == null ? -1 : withBytecode.size(),
- files);
+ files,
+ acknowledgedFiles,
+ markerProblemFiles);
+ }
+
+ /**
+ * Returns one line of the report, or null where the line has no live mutant and no marker.
+ *
+ * @param markers the markers of the line, read from the working tree, and none where the working
+ * tree cannot show the line
+ * @param mutants every mutant PIT reported on the line, whatever its status
+ */
+ private static Line readLine(
+ int number,
+ EquivalentMarkers markers,
+ List mutants,
+ Map shortTestNames) {
+ Map ids = ids(mutants);
+ Map byId = new HashMap<>();
+ ids.forEach((mutant, id) -> byId.put(id, mutant));
+ List live = new ArrayList<>();
+ List acknowledged = new ArrayList<>();
+ for (MutantsFile.Mutant mutant : mutants) {
+ if (!isLive(mutant.status())) {
+ continue;
+ }
+ String id = ids.get(mutant);
+ String reason = markers.reasons().get(id);
+ Mutant row =
+ new Mutant(
+ (mutant.status().equals("NO_COVERAGE") ? "no test reaches it: " : "survived: ")
+ + DESCRIPTION_SUFFIX.matcher(mutant.description()).replaceFirst(""),
+ readableMethod(mutant.method()),
+ id,
+ reason,
+ tests(mutant, shortTestNames));
+ (reason == null ? live : acknowledged).add(row);
+ }
+ List problems = new ArrayList<>(markers.problems());
+ for (String id : markers.reasons().keySet()) {
+ MutantsFile.Mutant named = byId.get(id);
+ if (named == null) {
+ problems.add(id + ": no mutant on the line has this id");
+ } else if (named.status().equals("KILLED")) {
+ problems.add(id + ": the tests kill this mutant, so it is not equivalent");
+ } else if (!isLive(named.status())) {
+ problems.add(id + ": PIT reports this mutant as " + named.status());
+ }
+ }
+ if (!problems.isEmpty()) {
+ // The reader corrects the marker from the report alone, so the line's ids follow its
+ // problems, killed ones included, since the report lists those nowhere else.
+ problems.add(
+ ids.isEmpty()
+ ? "PIT generated no mutant on the line"
+ : "the line has "
+ + ids.entrySet().stream()
+ .map(
+ entry ->
+ entry.getValue()
+ + " ("
+ + entry.getKey().status()
+ + ")")
+ .collect(Collectors.joining(", ")));
+ }
+ if (live.isEmpty() && acknowledged.isEmpty() && problems.isEmpty()) {
+ return null;
+ }
+ Map>> tests = new TreeMap<>();
+ for (Mutant mutant : live) {
+ mutant
+ .tests()
+ .forEach(
+ (name, invocations) ->
+ tests
+ .computeIfAbsent(name, unused -> new TreeSet<>(INVOCATION_ORDER))
+ .addAll(invocations));
+ }
+ return new Line(number, markers.code(), markers.text(), live, acknowledged, problems, tests);
+ }
+
+ /**
+ * Returns the short name of each test PIT recorded as covering the mutant, with the invocations
+ * of it PIT named.
+ */
+ private static Map>> tests(
+ MutantsFile.Mutant mutant, Map shortTestNames) {
+ Map>> tests = new TreeMap<>();
+ for (String test : mutant.tests()) {
+ TestName name = shortTestNames.computeIfAbsent(test, PitestSurvivors::shortTestName);
+ NavigableSet> invocations =
+ tests.computeIfAbsent(name.name(), unused -> new TreeSet<>(INVOCATION_ORDER));
+ if (!name.invocation().isEmpty()) {
+ invocations.add(name.invocation());
+ }
+ }
+ return tests;
+ }
+
+ /** Adds a file with the lines that pass the filter, where any does. */
+ private static void addLines(
+ List files, String path, List lines, Predicate filter) {
+ List kept = lines.stream().filter(filter).collect(Collectors.toList());
+ if (!kept.isEmpty()) {
+ files.add(new FileMutants(path, kept));
+ }
+ }
+
+ /**
+ * Returns the id of each mutant of one line: the simple name of its mutator, such as {@code
+ * RemoveConditionalMutator_EQUAL_ELSE}, followed by {@code #} and a number where the mutator
+ * made more than one mutant on the line.
+ *
+ * The numbers count the mutants of that mutator from 1, by method name and descriptor, then by
+ * the class that declares the method, then by the first instruction each changes, then by its
+ * description. A run of digits in a method or class name compares as a number, so
+ * {@code lambda$run$9} comes before {@code lambda$run$10}, and a lambda added earlier in the
+ * class, which renumbers the later ones, leaves their order as it was. javac emits the jumps of
+ * {@code a || b} in source order, so on such a line {@code #1} is a mutant of {@code a} and
+ * {@code #2} one of {@code b}. The numbers count mutants of every status, so an id stays the
+ * same when a test starts killing another mutant of the line. The map iterates in the order of
+ * the mutator names and then of the numbers.
+ */
+ static Map ids(List mutants) {
+ Map> byMutator = new TreeMap<>();
+ for (MutantsFile.Mutant mutant : mutants) {
+ byMutator
+ .computeIfAbsent(simpleMutatorName(mutant.mutator()), unused -> new ArrayList<>())
+ .add(mutant);
+ }
+ // A mutant is a key by identity: the class does not override equals.
+ Map ids = new LinkedHashMap<>();
+ byMutator.forEach(
+ (mutator, same) -> {
+ if (same.size() == 1) {
+ ids.put(same.get(0), mutator);
+ return;
+ }
+ same.sort(
+ Comparator.comparing(MutantsFile.Mutant::method, PitestSurvivors::compareNames)
+ .thenComparing(MutantsFile.Mutant::methodDescriptor)
+ .thenComparing(MutantsFile.Mutant::mutatedClass, PitestSurvivors::compareNames)
+ .thenComparingInt(MutantsFile.Mutant::firstIndex)
+ .thenComparing(MutantsFile.Mutant::description));
+ for (int i = 0; i < same.size(); i++) {
+ ids.put(same.get(i), mutator + "#" + (i + 1));
+ }
+ });
+ return ids;
+ }
+
+ /**
+ * Compares two names character by character, except that a run of ASCII digits in both compares
+ * first by its length and then by its digits, so {@code a$9} sorts before {@code a$10}.
+ */
+ private static int compareNames(String a, String b) {
+ int i = 0;
+ int j = 0;
+ while (i < a.length() && j < b.length()) {
+ if (isDigit(a.charAt(i)) && isDigit(b.charAt(j))) {
+ int iEnd = digitsEnd(a, i);
+ int jEnd = digitsEnd(b, j);
+ int byLength = Integer.compare(iEnd - i, jEnd - j);
+ if (byLength != 0) {
+ return byLength;
+ }
+ int byDigits = a.substring(i, iEnd).compareTo(b.substring(j, jEnd));
+ if (byDigits != 0) {
+ return byDigits;
+ }
+ i = iEnd;
+ j = jEnd;
+ } else if (a.charAt(i) != b.charAt(j)) {
+ return Character.compare(a.charAt(i), b.charAt(j));
+ } else {
+ i++;
+ j++;
+ }
+ }
+ return Integer.compare(a.length() - i, b.length() - j);
+ }
+
+ private static boolean isDigit(char c) {
+ return c >= '0' && c <= '9';
+ }
+
+ /** Returns the index after the run of ASCII digits that starts at {@code at}. */
+ private static int digitsEnd(String text, int at) {
+ while (at < text.length() && isDigit(text.charAt(at))) {
+ at++;
+ }
+ return at;
+ }
+
+ /** Returns the mutator name without its package, as an id names it. */
+ private static String simpleMutatorName(String mutator) {
+ return mutator.substring(mutator.lastIndexOf('.') + 1);
}
/**
@@ -427,6 +704,11 @@ String render(DiffCoverageReport.Limits limits, List fullReportPaths) {
.append(changedLines(linesWithBytecode >= 0 ? linesWithBytecode : mutatedLines))
.append(": ")
.append(counts());
+ if (acknowledgedCount > 0) {
+ out.append("; ")
+ .append(acknowledgedCount)
+ .append(" of the live ones acknowledged as equivalent");
+ }
}
int liveLines = files.stream().mapToInt(file -> file.lines().size()).sum();
if (liveLines > 0) {
@@ -435,35 +717,9 @@ String render(DiffCoverageReport.Limits limits, List fullReportPaths) {
if (total > 0 && statusCounts.getOrDefault("NO_COVERAGE", 0) == total) {
out.append("\n\n").append(NOTHING_REACHED);
}
- int filesLeft = limits.files;
- int rowsLeft = limits.lines;
- int filesShown = 0;
- for (FileMutants file : files) {
- if (filesLeft == 0 || rowsLeft == 0) {
- break;
- }
- filesLeft--;
- filesShown++;
- out.append("\n\n ").append(file.path());
- int allowed = Math.min(limits.linesPerFile, rowsLeft);
- int shown = 0;
- for (Line line : file.lines()) {
- if (shown == allowed) {
- break;
- }
- shown++;
- appendLine(out, line);
- }
- rowsLeft -= shown;
- if (shown < file.lines().size()) {
- int more = file.lines().size() - shown;
- out.append("\n ").append(more).append(more == 1 ? " more line" : " more lines");
- }
- }
- if (filesShown < files.size()) {
- int more = files.size() - filesShown;
- out.append("\n\n ").append(more).append(more == 1 ? " more file" : " more files");
- }
+ // The console limits hold for the whole report, so the sections spend one budget in turn.
+ int[] budget = {limits.files, limits.lines};
+ appendFiles(out, files, limits.linesPerFile, budget, this::appendLine);
if (liveLines > 0) {
out.append("\n\nLive mutants on ")
.append(liveLines)
@@ -474,6 +730,21 @@ String render(DiffCoverageReport.Limits limits, List fullReportPaths) {
.append("\n\n")
.append(WHAT_TO_DO);
}
+ if (!markerProblemFiles.isEmpty()) {
+ out.append("\n\nMarkers to correct:");
+ appendFiles(
+ out, markerProblemFiles, limits.linesPerFile, budget, PitestSurvivors::appendProblems);
+ out.append("\n\n").append(MARKERS_TO_CORRECT);
+ }
+ if (!acknowledgedFiles.isEmpty()) {
+ out.append("\n\nLive mutants acknowledged as equivalent:");
+ appendFiles(
+ out,
+ acknowledgedFiles,
+ limits.linesPerFile,
+ budget,
+ PitestSurvivors::appendAcknowledged);
+ }
// The note explains a changed line with no mutant. Where the run did not record the lines with
// bytecode, any changed line may lack one, so the note goes only with a report that already
// asks the reader to act: a mutant survived, or none was generated.
@@ -537,10 +808,65 @@ private String counts() {
return String.join(", ", parts);
}
+ /**
+ * Appends the files of one section, as many as the budget allows.
+ *
+ * @param budget the files and the lines the console may still show, spent by this call
+ */
+ private static void appendFiles(
+ StringBuilder out,
+ List files,
+ int linesPerFile,
+ int[] budget,
+ BiConsumer lineWriter) {
+ int filesShown = 0;
+ for (FileMutants file : files) {
+ if (budget[0] == 0 || budget[1] == 0) {
+ break;
+ }
+ budget[0]--;
+ filesShown++;
+ out.append("\n\n ").append(file.path());
+ int allowed = Math.min(linesPerFile, budget[1]);
+ int shown = 0;
+ for (Line line : file.lines()) {
+ if (shown == allowed) {
+ break;
+ }
+ shown++;
+ lineWriter.accept(out, line);
+ }
+ budget[1] -= shown;
+ if (shown < file.lines().size()) {
+ int more = file.lines().size() - shown;
+ out.append("\n ").append(more).append(more == 1 ? " more line" : " more lines");
+ }
+ }
+ if (filesShown < files.size()) {
+ int more = files.size() - filesShown;
+ out.append("\n\n ").append(more).append(more == 1 ? " more file" : " more files");
+ }
+ }
+
+ private static void appendProblems(StringBuilder out, Line line) {
+ out.append("\n ").append(line.number()).append(": ").append(line.text());
+ for (String problem : line.markerProblems()) {
+ out.append("\n ").append(problem);
+ }
+ }
+
+ private static void appendAcknowledged(StringBuilder out, Line line) {
+ out.append("\n ").append(line.number()).append(": ").append(line.source());
+ for (Mutant mutant : line.acknowledged()) {
+ appendMutant(out, mutant);
+ out.append("\n reason: ").append(mutant.reason());
+ }
+ }
+
private void appendLine(StringBuilder out, Line line) {
out.append("\n ").append(line.number()).append(": ").append(line.source());
for (Mutant mutant : line.mutants()) {
- out.append("\n ").append(mutant.description()).append(", in ").append(mutant.method());
+ appendMutant(out, mutant);
}
if (!line.tests().isEmpty()) {
List tests = new ArrayList<>(line.tests().keySet());
@@ -555,6 +881,16 @@ private void appendLine(StringBuilder out, Line line) {
}
}
+ private static void appendMutant(StringBuilder out, Mutant mutant) {
+ out.append("\n ")
+ .append(mutant.description())
+ .append(", in ")
+ .append(mutant.method())
+ .append(" [")
+ .append(mutant.id())
+ .append(']');
+ }
+
/** Returns the method name as a reader finds it in the source. */
static String readableMethod(String method) {
if (method.equals("")) {
diff --git a/cribro-core/src/main/java/io/github/cribrodev/SourceFileKey.java b/cribro-core/src/main/java/io/github/cribrodev/SourceFileKey.java
index b54cdd0..65ad935 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/SourceFileKey.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/SourceFileKey.java
@@ -20,6 +20,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -139,6 +141,87 @@ static String declaredPackage(String text, boolean kotlin) {
return at < 0 ? null : name.toString();
}
+ /** Whether a character of a Java or Kotlin source lies in a comment, and in which kind. */
+ enum Region {
+ /** Code, whitespace, a string or character literal, or a Kotlin name in backticks. */
+ CODE,
+ /** A line comment, from its {@code //} to the end of its line. */
+ LINE_COMMENT,
+ /** The first character of a block comment, the {@code /} of its {@code /*}. */
+ BLOCK_COMMENT_START,
+ /**
+ * A character of a block comment other than its first and the {@code *}{@code /} that closes
+ * it, a nested Kotlin comment included.
+ */
+ BLOCK_COMMENT,
+ /** A character of the {@code *}{@code /} that closes a block comment. */
+ BLOCK_COMMENT_END
+ }
+
+ /**
+ * Returns the region each character of a Java or Kotlin source lies in, by the lexical rules of
+ * the language, so a comment opener inside a literal opens no comment. A Java text is split after
+ * its Unicode escapes are replaced, and each character of an escape gets the region of the
+ * character it stands for. The code of a Kotlin template is split as code, so a comment in it is
+ * a comment. A text block, a raw string, or a block comment that never closes runs to the end of
+ * the text, and any other literal that never closes to the end of its line.
+ */
+ static Region[] regions(String text, boolean kotlin) {
+ Region[] regions = new Region[text.length()];
+ if (kotlin) {
+ fill(text, 0, text.length(), true, regions);
+ return regions;
+ }
+ int[] origin = new int[text.length() + 1];
+ String read = translateUnicodeEscapes(text, origin);
+ Region[] readRegions = new Region[read.length()];
+ fill(read, 0, read.length(), false, readRegions);
+ for (int at = 0; at < read.length(); at++) {
+ Arrays.fill(regions, origin[at], origin[at + 1], readRegions[at]);
+ }
+ return regions;
+ }
+
+ /** Sets the region of each character from {@code from} to {@code to}, the code of a text. */
+ private static void fill(String text, int from, int to, boolean kotlin, Region[] regions) {
+ Arrays.fill(regions, from, to, Region.CODE);
+ int dollars = 0;
+ int at = from;
+ while (at < to) {
+ char c = text.charAt(at);
+ int next;
+ if (text.startsWith("//", at)) {
+ next = skipLineComment(text, at);
+ Arrays.fill(regions, at, Math.min(next, to), Region.LINE_COMMENT);
+ } else if (text.startsWith("/*", at)) {
+ next = skipBlockComment(text, at, kotlin);
+ Arrays.fill(regions, at + 1, next < 0 ? to : Math.min(next, to), Region.BLOCK_COMMENT);
+ regions[at] = Region.BLOCK_COMMENT_START;
+ if (next >= 0 && next <= to) {
+ Arrays.fill(regions, next - 2, next, Region.BLOCK_COMMENT_END);
+ }
+ } else if (c == '"' || c == '\'') {
+ List templates = new ArrayList<>();
+ next = skipLiteral(text, at, kotlin, dollars, templates);
+ if (next < 0) {
+ if (!text.startsWith("\"\"\"", at)) {
+ next = skipLineComment(text, at);
+ }
+ } else {
+ for (int[] template : templates) {
+ fill(text, template[0], template[1], kotlin, regions);
+ }
+ }
+ } else if (kotlin && c == '`') {
+ next = skipIdentifier(text, at);
+ } else {
+ next = at + 1;
+ }
+ dollars = c == '$' ? dollars + 1 : 0;
+ at = next < 0 ? to : Math.max(next, at + 1);
+ }
+ }
+
/**
* Returns the text with each Unicode escape replaced by the character it stands for, as javac
* reads a source before it splits it into tokens (JLS ยง3.3). A backslash begins an escape only
@@ -146,6 +229,18 @@ static String declaredPackage(String text, boolean kotlin) {
* none. A backslash and {@code u} that no four hexadecimal digits follow stay as they are.
*/
private static String translateUnicodeEscapes(String text) {
+ return translateUnicodeEscapes(text, null);
+ }
+
+ /**
+ * Returns the text with each Unicode escape replaced, as {@link #translateUnicodeEscapes(String)}
+ * does.
+ *
+ * @param origin receives, for each character of the result, the index in {@code text} where it
+ * starts, and after the last of them the length of {@code text}; it holds at least {@code
+ * text.length() + 1} elements, or is null where only the result matters
+ */
+ private static String translateUnicodeEscapes(String text, int[] origin) {
StringBuilder out = new StringBuilder(text.length());
int backslashes = 0;
int at = 0;
@@ -157,6 +252,9 @@ private static String translateUnicodeEscapes(String text) {
digits++;
}
if (digits > at + 1 && isHex(text, digits, digits + 4)) {
+ if (origin != null) {
+ origin[out.length()] = at;
+ }
out.append((char) Integer.parseInt(text, digits, digits + 4, 16));
at = digits + 4;
backslashes = 0;
@@ -164,9 +262,15 @@ private static String translateUnicodeEscapes(String text) {
}
}
backslashes = c == '\\' ? backslashes + 1 : 0;
+ if (origin != null) {
+ origin[out.length()] = at;
+ }
out.append(c);
at++;
}
+ if (origin != null) {
+ origin[out.length()] = text.length();
+ }
return out.toString();
}
@@ -415,6 +519,18 @@ private static int skipBalanced(String text, int at, char open, char close, bool
* of a Kotlin string
*/
private static int skipLiteral(String text, int at, boolean kotlin, int dollars) {
+ return skipLiteral(text, at, kotlin, dollars, null);
+ }
+
+ /**
+ * Returns the index after the literal that opens at {@code at}, as {@link #skipLiteral(String,
+ * int, boolean, int)} does.
+ *
+ * @param templateCode receives the start and the end of the code of each template the literal
+ * holds, the text between its braces; null where only the end of the literal matters
+ */
+ private static int skipLiteral(
+ String text, int at, boolean kotlin, int dollars, List templateCode) {
char quote = text.charAt(at);
boolean multiline = quote == '"' && text.startsWith("\"\"\"", at);
boolean escapes = !(kotlin && multiline);
@@ -438,10 +554,14 @@ private static int skipLiteral(String text, int at, boolean kotlin, int dollars)
at += 2;
run = 0;
} else if (c == '{' && templates && run >= prefix) {
+ int open = at;
at = skipBalanced(text, at, '{', '}', true);
if (at < 0) {
return -1;
}
+ if (templateCode != null) {
+ templateCode.add(new int[] {open + 1, at - 1});
+ }
run = 0;
} else {
run = c == '$' ? run + 1 : 0;
diff --git a/cribro-core/src/main/java/io/github/cribrodev/SourceLines.java b/cribro-core/src/main/java/io/github/cribrodev/SourceLines.java
index 8595886..253a65d 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/SourceLines.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/SourceLines.java
@@ -86,6 +86,17 @@ String get(String path, int number) {
return text.decoded ? text.line(number) : "";
}
+ /**
+ * Returns every line of a file as the working tree holds it, or no line where the file cannot be
+ * read or decoded, as {@link #get} treats it.
+ *
+ * @param path repository-relative path, as a git diff spells it
+ */
+ List lines(String path) {
+ Text text = text(path);
+ return text.decoded ? text.lines : List.of();
+ }
+
/**
* Returns one line with each byte sequence that is not UTF-8 replaced by {@code U+FFFD}, or an
* empty string where the file cannot be read or has no such line.
diff --git a/cribro-core/src/main/java/io/github/cribrodev/pitest/MutantsFileListenerFactory.java b/cribro-core/src/main/java/io/github/cribrodev/pitest/MutantsFileListenerFactory.java
index 79f4e25..c898e35 100644
--- a/cribro-core/src/main/java/io/github/cribrodev/pitest/MutantsFileListenerFactory.java
+++ b/cribro-core/src/main/java/io/github/cribrodev/pitest/MutantsFileListenerFactory.java
@@ -75,8 +75,11 @@ public void handleMutationResult(ClassMutationResults results) {
result.getStatus().name(),
details.getClassName().asJavaName(),
details.getMethod(),
+ details.getId().getLocation().getMethodDesc(),
details.getFilename(),
details.getLineNumber(),
+ details.getMutator(),
+ details.getFirstIndex(),
details.getDescription(),
result.getCoveringTests())));
out.write('\n');
diff --git a/cribro-core/src/test/java/io/github/cribrodev/EquivalentMarkersTest.java b/cribro-core/src/test/java/io/github/cribrodev/EquivalentMarkersTest.java
new file mode 100644
index 0000000..adcc0e0
--- /dev/null
+++ b/cribro-core/src/test/java/io/github/cribrodev/EquivalentMarkersTest.java
@@ -0,0 +1,474 @@
+/*
+ * Copyright (C) 2026 cribro contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.github.cribrodev;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class EquivalentMarkersTest {
+
+ private static final String MALFORMED =
+ "the marker does not parse; write it as " + EquivalentMarkers.FORM;
+
+ private static EquivalentMarkers java(String line) {
+ return EquivalentMarkers.parse(line, false);
+ }
+
+ private static EquivalentMarkers kotlin(String line) {
+ return EquivalentMarkers.parse(line, true);
+ }
+
+ @Test
+ void aLineCommentGivesEachIdItNamesTheReasonThatRunsToTheEndOfTheLine() {
+ EquivalentMarkers markers =
+ java(
+ " if (a || b) { // mutant: equivalent NegateConditionalsMutator#2,"
+ + " RemoveConditionalMutator_EQUAL_ELSE -- b is false, see https://x/1 // more");
+
+ assertAll(
+ () ->
+ assertEquals(
+ Map.of(
+ "NegateConditionalsMutator#2", "b is false, see https://x/1 // more",
+ "RemoveConditionalMutator_EQUAL_ELSE", "b is false, see https://x/1 // more"),
+ markers.reasons(),
+ "reasons"),
+ () -> assertEquals(List.of(), markers.problems(), "problems"),
+ () -> assertEquals("if (a || b) {", markers.code(), "code"));
+ }
+
+ @Test
+ void aBlockCommentEndsTheReasonAndKeepsTheCodeAfterIt() {
+ EquivalentMarkers markers =
+ java("if (a /* mutant: equivalent MathMutator -- a is never 0 */ > 0) { // done");
+
+ assertAll(
+ () -> assertEquals(Map.of("MathMutator", "a is never 0"), markers.reasons(), "reasons"),
+ () -> assertEquals("if (a > 0) { // done", markers.code(), "code"));
+ }
+
+ @Test
+ void anIdWithThePackageOfItsMutatorNamesTheMutatorAlone() {
+ assertEquals(
+ Map.of("RemoveConditionalMutator_EQUAL_ELSE#1", "why"),
+ java("// mutant: equivalent"
+ + " org.pitest.mutationtest.engine.gregor.mutators."
+ + "RemoveConditionalMutator_EQUAL_ELSE#1 -- why")
+ .reasons());
+ }
+
+ @Test
+ void anIdMayHoldAnyCharacterButWhitespaceAndComma() {
+ assertEquals(
+ Map.of("remove-check", "why", "Kotlin$Null#2", "why", "Check#fast#2", "why"),
+ java("x(); // mutant: equivalent custom.remove-check, Kotlin$Null#2, custom.Check#fast#2"
+ + " -- why")
+ .reasons());
+ }
+
+ @Test
+ void aLongListOfIdsIsRead() {
+ StringBuilder line = new StringBuilder("x(); // mutant: equivalent M0");
+ for (int i = 1; i < 5000; i++) {
+ line.append(", M").append(i);
+ }
+ line.append(" -- why");
+
+ assertEquals(5000, java(line.toString()).reasons().size(), "ids read from 5000 named");
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "return b; // mutant: equivalent",
+ "return b; // mutant: equivalent MathMutator",
+ "return b; // mutant: equivalent MathMutator --",
+ "return b; // mutant: equivalent -- why",
+ "return b; // mutant: equivalent Math Mutator -- why",
+ "return b; // mutant: equivalent MathMutator. -- why",
+ "return b; // mutant: equivalent pkg.#2 -- why",
+ "return b; // mutant: equivalent MathMutator, -- why",
+ "return b; // mutant: equivalent #2.MathMutator -- why",
+ "return b; // mutant: equivalent MathMutator -- ",
+ "return b; /* mutant: equivalent MathMutator -- */",
+ })
+ void aMarkerThatDoesNotParseAcknowledgesNothingAndIsReported(String line) {
+ EquivalentMarkers markers = java(line);
+
+ assertAll(
+ () -> assertEquals(Map.of(), markers.reasons(), "reasons"),
+ () -> assertEquals(List.of(MALFORMED), markers.problems(), "problems"),
+ () -> assertEquals("return b;", markers.code(), "code"));
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "String s = \"// mutant: equivalent MathMutator -- why\";",
+ "String s = \"a\\\" // mutant: equivalent MathMutator -- why\";",
+ "x(); // mutant: equivalents MathMutator -- why",
+ "x(); // a mutant: equivalent? no",
+ "x(); /* see // mutant: equivalent MathMutator -- why */",
+ "x(); /* see * mutant: equivalent MathMutator -- why */",
+ "x(); /* see ** mutant: equivalent MathMutator -- why */",
+ "x() * mutant: equivalent MathMutator -- why",
+ "x(); // a * mutant: equivalent MathMutator -- why",
+ })
+ void textThatIsNoMarkerIsLeftInTheCode(String line) {
+ EquivalentMarkers markers = java(line);
+
+ assertAll(
+ () -> assertEquals(Map.of(), markers.reasons(), "reasons"),
+ () -> assertEquals(List.of(), markers.problems(), "problems"),
+ () -> assertEquals(line, markers.code(), "code"));
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "s(\"a\\\"b\"); // mutant: equivalent MathMutator -- why",
+ "c('\"'); // mutant: equivalent MathMutator -- why",
+ "c('\\''); s(\"x\"); // mutant: equivalent MathMutator -- why",
+ "/* don't say \"a */ y(); // mutant: equivalent MathMutator -- why",
+ "s(\"x\") /* mutant: equivalent MathMutator -- why */;",
+ "s(\"${\"); // mutant: equivalent MathMutator -- why",
+ })
+ void aMarkerAfterALiteralThatClosesOnTheLineCountsInJava(String line) {
+ assertEquals(Map.of("MathMutator", "why"), java(line).reasons(), line);
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "val s = \"\"\"a\"b\"\"\" // mutant: equivalent MathMutator -- why",
+ "val s = \"\"\"C:\\\"\"\" // mutant: equivalent MathMutator -- why",
+ "val s = \"\"\"a\"\"\"\" // mutant: equivalent MathMutator -- why",
+ "val s = \"${'\"'}\" // mutant: equivalent MathMutator -- why",
+ "val s = \"${f(\"}\")}\" // mutant: equivalent MathMutator -- why",
+ "val s = \"$x\" // mutant: equivalent MathMutator -- why",
+ })
+ void aMarkerAfterAKotlinStringThatClosesOnTheLineCounts(String line) {
+ assertEquals(Map.of("MathMutator", "why"), kotlin(line).reasons(), line);
+ }
+
+ @Test
+ void aKotlinNameInBackticksMayHoldAQuote() {
+ assertEquals(
+ Map.of("MathMutator", "why"),
+ kotlin("fun `doesn't change`(x: Int) = x + 1 // mutant: equivalent MathMutator -- why")
+ .reasons());
+ }
+
+ @Test
+ void aKotlinBlockCommentEndsAtTheCloseThatMatchesItsOpen() {
+ String line = "/* a /* b */ \" */ x() // mutant: equivalent MathMutator -- why";
+ assertAll(
+ () -> assertEquals(Map.of("MathMutator", "why"), kotlin(line).reasons(), "Kotlin"),
+ () -> assertEquals(Map.of(), java(line).reasons(), "Java, whose comments do not nest"));
+ }
+
+ /** Returns the reasons each line of the file gives, one map per line. */
+ private static List