Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d6d3bd
refactor(abc): drop the init_declarator guard in the C and Objective-…
dekobon Nov 12, 2026
074e726
ci(mutation): stop mutating the derived-parity test modules
dekobon Nov 12, 2026
db1b7bb
test(npm): read a Ruby class body where a keyword's name is not the k…
dekobon Nov 13, 2026
f6a76fe
test(npa): pin three attribute paths no fixture could tell from a con…
dekobon Nov 13, 2026
04c8cb1
ci(mutation): exclude seven equivalent npa mutants
dekobon Nov 13, 2026
3d7542f
test(loc): pin three bare-row helpers no fixture could tell from a mu…
dekobon Nov 13, 2026
8d46621
test(loc): pin the bare row that joins a comment a NUL cuts short
dekobon Nov 13, 2026
d38d32f
ci(mutation): exclude ten loc row-scan mutants no test can kill
dekobon Nov 13, 2026
739fd3b
test(loc): cover the descent level of a Python bare run after a docst…
dekobon Nov 13, 2026
bd90da6
test(loc): cover the multi-row string arms of five languages
dekobon Nov 13, 2026
683160d
test(loc): cover Mozcpp's for-header gate and Groovy's closure carve-out
dekobon Nov 13, 2026
5cb2a9e
test(nargs): tell a Go parameter's names from its other children
dekobon Nov 13, 2026
c0b57d2
test(loc): pin three guards that only recovery input separates
dekobon Nov 13, 2026
cefb8f1
ci(mutation): exclude five mutants that select between equal values
dekobon Nov 13, 2026
baa82d6
test(abc): pin that a C-family compound assignment is not peeled
dekobon Nov 13, 2026
09a5e84
test(abc): pin the C# null-forgiving peel and the preprocessor's fields
dekobon Nov 13, 2026
fdf5232
test(abc): pin the parenthesised ternary slots of Tcl and iRules
dekobon Nov 13, 2026
99b202e
test(abc): pin that a Rust block ending in `;` yields no operand
dekobon Nov 13, 2026
0c655c4
test(cognitive): pin closure nesting, a def boundary, a sequence reset
dekobon Nov 13, 2026
394fba5
test(cognitive): pin that a Bash jump level is a named argument
dekobon Nov 13, 2026
7677123
test(abc): pin the stranded C# `?` that only recovery input reaches
dekobon Nov 13, 2026
82f93e3
ci(mutation): exclude the Groovy and Ruby ternary-walk guard mutants
dekobon Nov 13, 2026
63da44a
test(nexits): pin the text half of the Go and Ruby exit gates
dekobon Nov 13, 2026
c6f6b8c
test(nargs): pin a variable-arity parameter in Java's canonical rule
dekobon Nov 13, 2026
eb77bd9
test(halstead): pin how Perl spells a dash key and the "[]" pair
dekobon Nov 13, 2026
8255475
test(halstead): pin that a plain PHP heredoc is one operand
dekobon Nov 13, 2026
aa850c1
test(halstead): pin two Kotlin boundaries valid source reaches
dekobon Nov 13, 2026
293db69
test(getter): ask four readings directly that no walk can show
dekobon Nov 13, 2026
050f7c5
test(roles): pin the gate on the Rust Guard row's owner
dekobon Nov 13, 2026
e2bbeb7
test(halstead): pin two getter arms only recovery input reaches
dekobon Nov 13, 2026
63ee0b9
ci(mutation): exclude four ast mutants on code that cannot answer oth…
dekobon Nov 13, 2026
8c7bfe0
test(find): pin the error filter on a clean and a broken source
dekobon Nov 13, 2026
2957ead
test(checker): pin the byte a run verdict's reach ends on
dekobon Nov 13, 2026
08d5181
test(spaces): prune a test module that starts where a reach ends
dekobon Nov 13, 2026
7499130
test(roles): pin Groovy's byte-less is_primitive on the other nodes
dekobon Nov 13, 2026
bb1df43
test(comment_rm): keep a Python encoding declaration when stripping
dekobon Nov 13, 2026
5730698
test(dloc): pin three doc-comment readings no fixture exercised
dekobon Nov 13, 2026
d3d7e3d
ci(mutation): exclude seven checker mutants on bodies no language rea…
dekobon Nov 13, 2026
6651984
ci(mutation): split the run across eighteen shards
dekobon Nov 13, 2026
5ca41cb
ci(mutation): withdraw four exclusions the review could not accept
dekobon Nov 13, 2026
8458283
test(loc): assert the recovered shape before the NUL fixture's rows
dekobon Nov 13, 2026
ab731b0
docs(npa,getter): correct two comments the new tests made wrong
dekobon Nov 13, 2026
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
124 changes: 109 additions & 15 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ output = "target/mutants"
# runs both suites.
test_package = ["big-code-analysis", "big-code-analysis-ast"]

# Test modules are not the subject. cargo-mutants skips a module
# declared under a bare `#[cfg(test)]`, and reads
# `#[cfg(all(test, any(feature = …)))]` as ordinary code: the two
# `derived_parity_tests.rs` suites are gated that way, and their helpers
# were being mutated as if they were classifiers. An exclusion, unlike
# `examine_globs`, cannot widen a single-file local run.
exclude_globs = ["**/*_tests.rs"]

# Mutants no run tests. Each entry is one mutant shown to behave
# identically on every reachable input, panics and side effects
# included, or one that never terminates; the reason sits above it. A
Expand All @@ -44,21 +52,107 @@ exclude_re = [
# the upward one, which does nothing there either, since `words` is
# non-empty and `word - first_word >= words.len()` reads `0 >= len`.
'^src/metrics/loc/line_set\.rs:\d+:\d+: replace < with <= in LineSet::reserve$',
# Equivalent while tree-sitter-c is pinned at 0.24.2, whose one
# `init_declarator` production is `declarator = value`. Every such node
# holds an `=` child (one the parser inserted in recovery is still that
# kind) and a child that is not `=`, so the guard's one child scan
# finds a match whether it looks for the `=` or for anything else.
# Re-derive on a grammar bump: the C++ grammar also has `int x(5);` and
# `int x{5};`, which keep this mutant live there.
'^src/metrics/abc/c\.rs:\d+:\d+: replace == with != in <impl Abc for CCode>::compute$',
# The same mutant in the Objective-C impl, equivalent for the same
# reason while tree-sitter-objc is pinned at 3.0.2: its one
# `init_declarator` production is `declarator [attribute] = value`.
# `compute` has a second `==`, in `kind == MessageExpression`, whose
# mutant is live and caught; the column (56 against 25) is what tells
# this one from it.
'^src/metrics/abc/objc\.rs:\d+:56: replace == with != in <impl Abc for ObjcCode>::compute$',
# Equivalent. The deleted arm answers `true`, and so does the `_`
# arm the three kinds then fall to: `is_assignment` is false for a
# rescue modifier, so the guarded arm between them does not take them.
'^src/metrics/npa/ruby_body\.rs:\d+:\d+: delete match arm RescueModifier \| RescueModifier2 \| RescueModifier3 in is_statement_of$',
# Equivalent. With `&&` the class body's frame and an argument frame
# are read through `is_statement_of`, whose answer for a parent that
# is a class body or an argument list is `child.is_named()`, the test the
# original applies to those two frames itself. No frame is both.
'''^src/metrics/npa/ruby_body\.rs:\d+:\d+: replace \|\| with && in RubyBodyState<'a, 'chain>::read_body$''',
# Equivalent while tree-sitter-kotlin's `property_declaration` holds
# exactly one of `variable_declaration` and
# `multi_variable_declaration`: without the arm a single binding sums
# to 0, and the `.max(1)` on the sum makes it 1 again.
'^src/metrics/npa/kotlin\.rs:\d+:\d+: delete match arm VariableDeclaration in kotlin_count_property_attrs$',
# Equivalent. `<=` differs only when the last row starts at the end
# of the file, where the row is empty: its shape is blank, it pushes
# one `None` and leaves nothing pending, as the original does.
'^src/metrics/loc/continuation\.rs:\d+:\d+: replace < with <= in BareRowIndex::build$',
# Equivalent. The branch is reached only when `after && diff == 0` is
# false, so with `after` true `diff` is positive and both spellings
# read `after`.
'^src/metrics/loc/shared\.rs:\d+:\d+: replace > with >= in add_cloc_lines$',
# The next five rest on one fact about the grammars whose bare rows
# reach the gap scan (Bash, Tcl, iRules, Ruby, Elixir, Python; the C
# family answers every row from its index): `comment` is a childless
# terminal that ends only before a newline, a NUL or the end of the
# file. Read from each pinned grammar's lexer, and re-derived on a
# bump. A differential run over close to a million generated sources,
# malformed ones included, showed no output difference for any of them.
#
# `holder_of`: where the mutant answers a node and the original none,
# that node has children, or is one no comment can end against, so
# `in_comment` reads false either way. `<=` is both boundary tests.
'''^src/metrics/loc/shared\.rs:\d+:\d+: replace && with \|\| in GapScan<'_, 'a>::holder_of$''',
'''^src/metrics/loc/shared\.rs:\d+:\d+: replace < with <= in GapScan<'_, 'a>::holder_of$''',
# The sibling step of `only_comments_after` runs only for a comment a
# NUL cuts short. No comment starts at a NUL, so its guard is never
# true and the sibling list feeding it is never read; the NUL is a
# leaf of its own, so a next sibling starts exactly at `after`.
# `opens_comment_only_line` has a second, live `==` at column 33; the
# column is what tells this one from it.
'^src/metrics/loc/shared\.rs:\d+:37: replace == with != in opens_comment_only_line$',
'^src/metrics/loc/shared\.rs:\d+:\d+: replace match guard sibling\.start_byte\(\) == after && comments\.lists\(sibling\) with false in only_comments_after$',
'^src/metrics/loc/shared\.rs:\d+:\d+: replace == with != in only_comments_after$',
# Non-terminating under mutation. With `||` a node that is not a
# comment short-circuits past `goto_first_child`, and the `continue`
# reads the same node again; the root is never a comment, so every
# `BareRowIndex::build` spins on its first step.
'^src/metrics/loc/continuation\.rs:\d+:\d+: replace && with \|\| in comment_spans$',
# Non-terminating under mutation. `past_line_padding` re-reads its
# position through this function; answering 0 for a source that opens
# with a backslash and a newline sends it back to the start for ever.
'^src/metrics/loc/shared\.rs:\d+:\d+: replace past_horizontal_space -> usize with 0$',
# Equivalent. `PYTHON_COMMENTS` is a constant whose `continued` is
# false, so the guard reads false for every input before the mutant
# says so.
'^src/metrics/loc/python\.rs:\d+:\d+: replace match guard in_comment && PYTHON_COMMENTS\.continued with false in classify_python_run$',
# Equivalent. Each differs only when the two values compared are
# equal, and then keeps or assigns the other of two equal values. The
# one pair that is equal and distinguishable is `+0.0` and `-0.0`,
# and no population folds a negative zero: a `usize` has none, and
# every `f64` folded starts at 1 and only grows.
'^src/metrics/mod\.rs:\d+:\d+: replace < with <= in FunctionPopulation<T>::(fold|merge)$',
'^src/metrics/mod\.rs:\d+:\d+: replace > with >= in FunctionPopulation<T>::(fold|merge)$',
# Equivalent while the pinned Groovy and Ruby grammars give the
# `condition`, `consequence` and `alternative` fields to no kind but
# the ternary and the branch, guard and loop kinds an earlier arm of
# the same match has already taken. The mutant hands every node that
# reaches this arm to the ternary walk, which reads those three fields
# and does nothing when all are absent; an `ERROR` node has no fields.
# Re-derive on a grammar bump, and if a `Branch` or `Guard` row there
# gains a gate.
'^src/metrics/abc/groovy\.rs:\d+:\d+: replace match guard ternary::owns_kind\(kind, node, code, ancestors\) with true in groovy_walk_for_conditions$',
'^src/metrics/abc/ruby\.rs:\d+:\d+: replace match guard ternary::owns_kind\(kind, node, code, ancestors\) with true in <impl Abc for RubyCode>::compute$',
# Equivalent. The body forwards to the language's `opens_space`,
# which answers `SpaceKind::Unknown` unless a row's owner carries
# `opens` or `opens_by`. Neither the Ccomment nor the Preproc table has
# one, and `SpaceKind::default()` is `Unknown`.
'^big-code-analysis-ast/src/getter/(ccomment|preproc)\.rs:\d+:\d+: replace <impl Getter for (Ccomment|Preproc)Code>::get_space_kind_with_code -> SpaceKind with Default::default\(\)$',
# Equivalent. The outer loop's extra pass has `i == a.len()`, so the
# inner loop, the only place that indexes, starts past the end and
# does not run. The inner loop's own `<` is at column 17 and is live:
# the column tells the two apart.
'^big-code-analysis-ast/src/roles/mod\.rs:\d+:13: replace < with <= in kinds_repeat$',
# Unreachable. The helper's one caller reaches it only where
# `kotlin_is_short_interp_name` holds for the same bytes, which needs
# a leading identifier of at least one byte, so `prefix_len` is never
# 0 here and `>` and `>=` agree.
'''^big-code-analysis-ast/src/getter/kotlin\.rs:\d+:\d+: replace > with >= in kotlin_short_interp_operand_bytes$''',
# Unreachable. Every `impl Checker for` in `checker/` defines these
# three itself, through `impl_comment_from_rows!` or
# `impl_doc_comment_rows_in_bodies!` and through
# `impl_row_predicates!`, so the trait's default bodies run for no
# language. The only types that inherit them are two test probes in
# `cyclomatic.rs`, which call no `Checker` method. A language added
# without the macros would make them live.
'^big-code-analysis-ast/src/checker\.rs:\d+:\d+: replace Checker::(is_comment|is_call|is_string) -> bool with true$',
# Equivalent. Both bodies read a role table in which `FuncOpener` and
# `Container` are `absent`, so each already answers `false` for every
# node of a Ccomment or Preproc tree.
'^big-code-analysis-ast/src/checker/(ccomment|preproc)\.rs:\d+:\d+: replace <impl Checker for (Ccomment|Preproc)Code>::(is_func_space_with_code|is_func_with_code) -> bool with false$',
# Non-terminating under mutation. The loop then breaks when
# `goto_next_sibling` succeeds and repeats when it fails, so a list
# with one child is visited forever. Its one caller walks the values
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/mutation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ jobs:
# twice either. Widening the selection to the per-language checker/,
# getter/ and roles/ modules (#1728) took the census from 3673 to
# 5048 mutants (`cargo mutants --list`, 27.1.0, at 7008fdb3)
# and the ast share from 5 % to 31 %. Sixteen gives ~316 per shard,
# and the ast share from 5 % to 31 %. Sixteen gave ~316 per shard,
# about 165 min at those slow-runner rates; the margin to 270 is for
# the runner variance that made identical shards differ 1.6x.
# the runner variance that made identical shards differ 1.6x. The
# second complete run (43278927651, sixteen shards of 341 at
# 68b70b08) took 125 to 222 min, two shards past 200, so the count is
# eighteen: ~292 per shard of the 5249 the list holds once the test
# modules and the excluded mutants are out, about 190 min at that
# run's slowest rate of 39 s per mutant.
prepare:
name: shard list
runs-on: ubuntu-latest
Expand All @@ -56,7 +61,7 @@ jobs:
- id: define
run: |
set -euo pipefail
shards='[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]'
shards='[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]'
echo "shards=${shards}" >> "$GITHUB_OUTPUT"
echo "count=$(jq -n "${shards} | length")" >> "$GITHUB_OUTPUT"
Expand Down
57 changes: 57 additions & 0 deletions big-code-analysis-ast/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,63 @@ mod tests {
);
}

/// A run's verdict answers for the run and for the item it
/// decorates, and stops there: the item's first child starts at the
/// byte the reach ends on, and is asked about on its own (#1783).
///
/// A direct test of the reach, because no walk over a clean parse
/// shows where it ends: the only other nodes starting on that byte
/// are the item's own leading descendants, which the hook retains
/// whether it is asked or not, and a pruned item's are never
/// visited. Only a recovery tree puts a prunable node there.
#[cfg(feature = "rust")]
#[test]
fn a_run_verdict_answers_for_its_item_and_not_for_the_items_first_child() {
let code = b"#[inline]\nfn f() {}\n";
let mut verdict: Option<SubtreeSkip> = None;
let mut after_the_attribute = Vec::new();
for_each_node_with_chain::<RustCode>(code, |node, chain| {
if let Some(verdict) = verdict {
after_the_attribute.push((
node.kind(),
node.start_byte(),
verdict.answers_for(node),
));
} else if node.kind_id() == Rust::AttributeItem {
verdict = Some(RustCode::should_skip_subtree(
node,
code,
Ancestors::known(chain),
));
}
});
// expected: `#[inline]` is bytes 0..9 and `fn f() {}` starts at
// byte 10. The verdict answers for the attribute's five
// descendants, which start before byte 10, and for the
// `function_item`, which it names. The `fn` keyword starts at
// byte 10 as well and is not the named node, so it is not
// answered for, and nothing after it is.
assert_eq!(
after_the_attribute,
[
("#", 0, true),
("[", 1, true),
("attribute", 2, true),
("identifier", 2, true),
("]", 8, true),
("function_item", 10, true),
("fn", 10, false),
("identifier", 13, false),
("parameters", 14, false),
("(", 14, false),
(")", 15, false),
("block", 17, false),
("{", 17, false),
("}", 18, false),
]
);
}

#[cfg(feature = "groovy")]
#[test]
fn groovy_is_else_if_recognises_else_followed_by_if() {
Expand Down
39 changes: 38 additions & 1 deletion big-code-analysis-ast/src/comment_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ mod tests {
use std::path::PathBuf;

use crate::{
CParser, CcommentParser, CppParser, MozcppParser, ObjcParser, ParserTrait, RustParser,
CParser, CcommentParser, CppParser, MozcppParser, ObjcParser, ParserTrait, PythonParser,
RustParser,
};

use super::rm_comments;
Expand Down Expand Up @@ -322,6 +323,42 @@ mod tests {
);
}

/// Python's `Checker::is_useful_comment` keeps an encoding
/// declaration: a comment on the first or second line that names a
/// `coding`, the two lines PEP 263 reads one from. Stripping it
/// changes how the file decodes.
///
/// Each kept row sits beside rows that must go, so neither an
/// `is_useful_comment` that keeps nothing nor one that keeps every
/// comment passes: a trailing comment, a shebang on the first line,
/// and a `coding` comment on the third line, where it declares
/// nothing.
#[cfg(feature = "python")]
#[test]
fn python_keeps_an_encoding_declaration_on_the_first_two_lines_only() {
let strip = |source: &str| {
let path = PathBuf::from("foo.py");
let parser = PythonParser::new(source.as_bytes().to_vec(), &path, None);
let stripped = rm_comments(&parser).expect("each fixture has a removable comment");
String::from_utf8(stripped).expect("stripping preserves UTF-8")
};

// expected: the declaration on the first line stays; the
// trailing comment goes and leaves the two spaces before it.
assert_eq!(
strip("# coding: utf-8\nx = 1 # drop\n"),
"# coding: utf-8\nx = 1 \n"
);
// expected: the shebang names no `coding` and goes; the
// declaration on the second line stays; the same words on the
// third line are an ordinary comment and go. A removed
// one-line comment leaves its line break behind.
assert_eq!(
strip("#!/usr/bin/env python\n# -*- coding: latin-1 -*-\n# coding: utf-8\nx = 1\n"),
"\n# -*- coding: latin-1 -*-\n\nx = 1\n"
);
}

/// The C-family `Checker::is_useful_comment` impls (C, C++, Mozilla
/// C++, Objective-C, and the comment-only `Ccomment` grammar) all
/// delegate to one Aho-Corasick automaton whose single needle is
Expand Down
65 changes: 65 additions & 0 deletions big-code-analysis-ast/src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,68 @@ pub fn find<'a, T: ParserTrait>(
});
Ok(good)
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use super::find;
use crate::count::count;
use crate::langs::RustParser;
use crate::node::Node;
use crate::traits::ParserTrait;

// The `error` filter is `Checker::is_error`: a node that is a parse
// error or holds one. A clean source matches nothing, which an
// `is_error` answering `true` for every node fails. A broken one
// matches the path from the root down to its `ERROR` and nothing
// beside that path, which an `is_error` answering `false` fails. The
// second source is one rustc rejects, by necessity: a tree with no
// parse error gives the filter nothing to match.
#[cfg(feature = "rust")]
#[test]
fn the_error_filter_matches_the_path_to_a_parse_error_and_nothing_else() {
let error = ["error".to_owned()];
let parse = |source: &str| {
RustParser::new(source.as_bytes().to_vec(), &PathBuf::from("t.rs"), None)
};
let kind_and_row = |node: &Node| (node.kind(), node.start_row());

let clean = parse("fn ok() {}\nfn also() {}\n");
// expected: no node of a clean parse is or holds an error, so
// `find` returns nothing and `count` tallies none of the nodes.
let found = find(&clean, &error).expect("`find` is infallible");
assert_eq!(found.iter().map(kind_and_row).collect::<Vec<_>>(), []);
let (good, total) = count(&clean, &error);
assert_eq!(good, 0);
assert!(total > 1, "the clean fixture parsed to {total} nodes");

let broken = parse("fn ok() {}\nfn broken() { let = ; }\n");
// The recovered shape: `let =` is the tree's one `ERROR`, in
// the body of the second function, and no token is invented.
let errors: Vec<_> = broken.root().preorder().filter(Node::is_error).collect();
let [error_node] = errors[..] else {
panic!("the fixture must recover into one `ERROR`, got {errors:?}");
};
assert!(broken.root().preorder().all(|node| !node.is_missing()));
// expected: the `ERROR` and each of its ancestors, root first,
// which is the order `find` visits them in. `fn ok` on row 0
// holds no error and is on no such path.
let mut path: Vec<_> = std::iter::successors(Some(error_node), Node::parent)
.map(|node| kind_and_row(&node))
.collect();
path.reverse();
assert_eq!(
path,
[
("source_file", 0),
("function_item", 1),
("block", 1),
("ERROR", 1)
]
);
let found = find(&broken, &error).expect("`find` is infallible");
assert_eq!(found.iter().map(kind_and_row).collect::<Vec<_>>(), path);
assert_eq!(count(&broken, &error).0, path.len());
}
}
Loading
Loading