Answer stability round 1: 0 🔴, 5 🟡 (0 misread); run both tools in a scratch copy, read Infection's two sources, end PHPUnit's list, spell glob characters
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import typing
|
||||
|
||||
from mutate_changes.changed_lines import by_folder, label, runs
|
||||
@@ -14,7 +15,7 @@ CARGO_FINISHED = frozenset({0, 2, 3})
|
||||
CARGO_OUTCOMES = ("caught", "missed", "timeout", "unviable")
|
||||
INFECTION = "vendor/bin/infection" # the project's own, as Composer installs it
|
||||
# npx runs the project's own @stryker-mutator/core, else one an earlier npx run cached, and installs none.
|
||||
STRYKER = ["npx", "--no", "--package=@stryker-mutator/core", "stryker", "run"]
|
||||
STRYKER_RUN = ["npx", "--no", "--package=@stryker-mutator/core", "stryker", "run"]
|
||||
GREMLINS_UNKILLED = frozenset({"LIVED", "NOT COVERED"})
|
||||
# What Gremlins v0.6.0 needs of the diff it reads from git: one run of lines per hunk is all it mutates, so a hunk holds the changed
|
||||
# lines and none around them, nor a neighbouring change; it takes each file's path after a b/; and it reads no colour codes. A user's git
|
||||
@@ -117,6 +118,13 @@ def outcome_lines(path: pathlib.Path) -> list[str]:
|
||||
|
||||
# Stryker and Infection also exit nonzero on a mutation score below a threshold the project sets, which their exit code doesn't
|
||||
# tell from a run that broke, so either fails the run.
|
||||
def glob_escaped(path: str) -> str:
|
||||
"""A path as a glob that matches it. Stryker 10.1.1 reads each entry of --mutate as a glob, in which `app/[slug]/page.tsx`
|
||||
matches `app/s/page.tsx` and not the file of that name. It reads a backslash as a slash, so no character can be escaped: a `?`
|
||||
stands for each one a glob gives a meaning, and matches it."""
|
||||
return re.sub(r"[][!()*+@{}]", "?", path)
|
||||
|
||||
|
||||
def run_stryker(top: str, changed: dict[str, frozenset[int]], run: Run, jobs: int) -> list[str] | Failure:
|
||||
"""For each folder Stryker runs in, a line naming it, then Stryker's own report of the mutants on the changed lines. Last, a line
|
||||
naming the files with no package.json above them, if any.
|
||||
@@ -129,8 +137,8 @@ def run_stryker(top: str, changed: dict[str, frozenset[int]], run: Run, jobs: in
|
||||
if not os.path.isfile(os.path.join(top, folder, "package.json")):
|
||||
unplaced = sorted(files)
|
||||
continue
|
||||
mutate = ",".join(f"{path}:{first}-{last}" for path, lines in sorted(files.items()) for first, last in runs(lines))
|
||||
ran = run([*STRYKER, "--mutate", mutate, "--concurrency", str(jobs), "--reporters", "clear-text"], os.path.join(top, folder))
|
||||
mutate = ",".join(f"{glob_escaped(path)}:{first}-{last}" for path, lines in sorted(files.items()) for first, last in runs(lines))
|
||||
ran = run([*STRYKER_RUN, "--mutate", mutate, "--concurrency", str(jobs), "--reporters", "clear-text"], os.path.join(top, folder))
|
||||
if isinstance(ran, Failure) or ran.code:
|
||||
return ran if isinstance(ran, Failure) else whole_output(f"Stryker in {label(folder)}", ran)
|
||||
report.extend([f"Stryker in {label(folder)}:", *ran.output.splitlines()])
|
||||
|
||||
Reference in New Issue
Block a user