Answer stability round 1: 3 🔴, 5 🟡 (0 misread); run only a Stryker the project installed, tell mutmut's setup fault from no test, pin cargo-mutants' diff prefixes, keep -x, end the tool and report its scratch folder on SIGTERM, and test option-like names; with product-owner's and prose's code fixes
This commit is contained in:
+44
-33
@@ -12,25 +12,38 @@ or __tests__/ folder.
|
||||
folder's setup.cfg settings stay, but source_paths and also_copy are set, and pytest leaves out each test that fails without a
|
||||
mutant; the report names their files. mutmut sees only the code a test runs in its own process, so a mutant that only a child
|
||||
process reaches, such as a tool a test starts, shows as `no tests`. A pyproject.toml with a [tool.mutmut] section fails the run.
|
||||
- .rs: cargo-mutants, with --in-diff.
|
||||
- .cjs, .cts, .js, .jsx, .mjs, .mts, .ts, .tsx: Stryker, with --mutate on the changed lines.
|
||||
- .php: Infection, with --git-diff-lines.
|
||||
- .rs: cargo-mutants, as `cargo mutants --in-diff`, in the checkout's top.
|
||||
- .cjs, .cts, .js, .jsx, .mjs, .mts, .ts, .tsx: Stryker, as `npx --no stryker run --mutate` on the changed lines, in the nearest
|
||||
folder above the file that holds a package.json, else in the checkout's top. Through --no, npx runs only a Stryker the project
|
||||
installed.
|
||||
- .php: Infection, as `vendor/bin/infection --git-diff-lines`, in the checkout's top.
|
||||
|
||||
--prefix is shell text put before each tool's command, such as 'uvx --from "mutmut>=3,<4"' or 'docker compose run --rm app'.
|
||||
Without it, each tool must be on PATH. mutmut runs in its scratch copy, a folder in the checkout's top, and every other tool in
|
||||
the checkout's top; in the prefix, $PWD names that folder. --jobs sets how many tests each tool runs at once, 4 by default: one
|
||||
heavy slot's CPUs.
|
||||
--prefix is shell text that runs each tool: sh runs `<prefix> "$@"` in the tool's folder, which $PWD names, with the tool's command
|
||||
as "$@". For example, 'uvx --from "mutmut>=3,<4"'. Without --prefix, the command runs as it is. A container must mount $PWD and
|
||||
run there, as 'docker compose -f "$(git rev-parse --show-toplevel)/compose.yaml" run --rm -v "$PWD:$PWD" -w "$PWD" app' does. "$1"
|
||||
is the command's first word, mutmut, cargo, npx or vendor/bin/infection, so a prefix can pick what to run per tool:
|
||||
'case "$1" in mutmut) set -- uvx --from "mutmut>=3,<4" "$@";; esac;'.
|
||||
|
||||
For mutmut and cargo-mutants, it prints a line with the mutant count, then a line per mutant on a changed line that is not
|
||||
killed: `<path>:<line>: <status>: <the line as mutated>`. Stryker and Infection print their own report, after their exit code.
|
||||
The last line gives the wall time.
|
||||
--jobs sets how many tests each tool runs at once, 4 by default: one heavy slot's CPUs. Under run-heavy, a container that sets
|
||||
neither memory limit gets the slot's share, in MiB in RUN_HEAVY_MEMORY; set --jobs so that that many test runs fit in it.
|
||||
|
||||
Exit 1, saying why, on unknown arguments, or when git fails, a tool cannot start, or mutmut or cargo-mutants fails before it reports.
|
||||
It prints:
|
||||
- for mutmut, per folder, a line with the mutant count, then a line per mutant on a changed line that is not killed, as
|
||||
`<path>:<line>: <status>: <the line as mutated>`, or `<path>: <status>: <name>, on a line mutate-changes cannot find`;
|
||||
- for cargo-mutants, a line with the mutant count, then a line per mutant it missed or that timed out, as
|
||||
`<path>:<line>:<column>: <outcome>: <mutation>`;
|
||||
- for Stryker and Infection, a line naming the folder the tool ran in, then the tool's own report;
|
||||
- a line naming the changed files in a language no tool covers, then one naming the changed test files, none of which it mutates;
|
||||
- last, the wall time.
|
||||
|
||||
Exit 1, saying why, on an unknown or repeated argument, an option without its value, or a --jobs that is no whole number from 1.
|
||||
Exit 1 too when git fails, a file cannot be read or copied, a tool cannot start, or a tool fails before it reports. Stryker and
|
||||
Infection also exit nonzero on a mutation score below a threshold the project sets, which fails the run as well.
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
|
||||
from mutate_changes.changed_lines import added_lines, tool_for
|
||||
from mutate_changes.changed_lines import added_lines, not_mutated, tool_for
|
||||
from machine_load.slots import CPUS_PER_SLOT
|
||||
from git_cli.git_repo import default_ref, git, top
|
||||
from failure import Failure
|
||||
@@ -55,11 +68,7 @@ def main(argv: list[str]) -> int:
|
||||
if isinstance(report, Failure):
|
||||
print(report.reason, file=sys.stderr)
|
||||
return 1
|
||||
if not report:
|
||||
print("No line the branch changes is in a language mutate-changes mutates.")
|
||||
return 0
|
||||
print("\n".join(report))
|
||||
print(f"mutate-changes took {took(time.monotonic() - started)}.")
|
||||
print("\n".join([*report, f"mutate-changes took {took(time.monotonic() - started)}."]))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -73,32 +82,37 @@ def options(argv: list[str]) -> dict[str, str] | Failure:
|
||||
if not equals and not rest:
|
||||
return Failure(f"{name} needs a value")
|
||||
given[name] = value if equals else rest.pop(0)
|
||||
if not given.get("--jobs", "1").isdigit() or int(given.get("--jobs", "1")) < 1:
|
||||
if not given.get("--jobs", "1").isdecimal() or int(given.get("--jobs", "1")) < 1:
|
||||
return Failure(f"--jobs takes a whole number from 1, not {given['--jobs']}")
|
||||
return given
|
||||
|
||||
|
||||
def mutate(given: dict[str, str]) -> list[str] | Failure:
|
||||
"""Each tool's report on the branch's changed lines; empty where none of them is in a language a tool covers."""
|
||||
"""Each tool's report on the lines the branch adds, then the lines naming the changed files no tool mutates."""
|
||||
checkout = top()
|
||||
if isinstance(checkout, Failure):
|
||||
return checkout
|
||||
base = given.get("--base") or default_ref(cwd=checkout)
|
||||
if isinstance(base, Failure):
|
||||
return base
|
||||
merge_base = git("merge-base", base, "HEAD", cwd=checkout)
|
||||
if isinstance(merge_base, Failure):
|
||||
return merge_base
|
||||
changed = changed_by_tool(checkout, merge_base.strip())
|
||||
found = git("merge-base", base, "HEAD", cwd=checkout)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
merge_base = found.strip()
|
||||
names = git("diff", "--name-only", "-z", "--diff-filter=d", merge_base, cwd=checkout)
|
||||
if isinstance(names, Failure):
|
||||
return names
|
||||
paths = list(filter(None, names.split("\0")))
|
||||
changed = changed_by_tool(checkout, merge_base, paths)
|
||||
if isinstance(changed, Failure):
|
||||
return changed
|
||||
prefix, jobs = given.get("--prefix"), int(given.get("--jobs", CPUS_PER_SLOT))
|
||||
report: list[str] = []
|
||||
report = [] if changed else ["No tool ran: the branch adds no line to a file that a tool mutates."]
|
||||
for tool, files in sorted(changed.items()):
|
||||
if tool == "cargo-mutants":
|
||||
lines = run_cargo_mutants(checkout, merge_base.strip(), sorted(files), prefix, jobs)
|
||||
lines = run_cargo_mutants(checkout, merge_base, sorted(files), prefix, jobs)
|
||||
elif tool == "infection":
|
||||
lines = run_infection(checkout, merge_base.strip(), prefix, jobs)
|
||||
lines = run_infection(checkout, merge_base, prefix, jobs)
|
||||
elif tool == "stryker":
|
||||
lines = run_stryker(checkout, files, prefix, jobs)
|
||||
else:
|
||||
@@ -106,16 +120,13 @@ def mutate(given: dict[str, str]) -> list[str] | Failure:
|
||||
if isinstance(lines, Failure):
|
||||
return lines
|
||||
report.extend(lines)
|
||||
return report
|
||||
return [*report, *not_mutated(paths)]
|
||||
|
||||
|
||||
def changed_by_tool(checkout: str, merge_base: str) -> dict[str, dict[str, frozenset[int]]] | Failure:
|
||||
"""Each tool's files that the working tree changes since merge_base, by path from the checkout's top, with their changed lines."""
|
||||
names = git("diff", "--name-only", "-z", "--diff-filter=d", merge_base, cwd=checkout)
|
||||
if isinstance(names, Failure):
|
||||
return names
|
||||
def changed_by_tool(checkout: str, merge_base: str, paths: list[str]) -> dict[str, dict[str, frozenset[int]]] | Failure:
|
||||
"""Each tool's files among paths, by path from the checkout's top, with the lines the working tree adds since merge_base."""
|
||||
changed: dict[str, dict[str, frozenset[int]]] = {}
|
||||
for path in filter(None, names.split("\0")):
|
||||
for path in paths:
|
||||
if (tool := tool_for(path)) is None:
|
||||
continue
|
||||
diff = git("diff", "-U0", "--no-color", "--no-ext-diff", "--no-textconv", merge_base, "--", path, cwd=checkout, errors="replace")
|
||||
|
||||
Reference in New Issue
Block a user