mirror of
https://github.com/unclebob/crapper.git
synced 2026-11-26 18:18:49 +00:00
Cover the mutation sites the suite never reached.
git status can fail after rev-parse succeeds, and that empty-stderr message was never executed. A non-numeric LCOV branch count never reaches the hit check, so the dead handler is gone and the record ignores it. JaCoCo's missing counter field and the Go report paths were split onto lines the coverage report records. A callback stored in a binding or passed to new stays inside its function, and an npm coverage script does not install Vitest. mutator --mutate-all on the changed Python files: 709 killed, 0 survived, 0 uncovered. Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
co-authored by
Robert C. Martin
parent
c0ba1e13ba
commit
8e491a636a
+16
-12
@@ -233,10 +233,7 @@ def parse_form_coverage(html: str) -> dict[int, tuple[int, int]]:
|
|||||||
def _branch_hit(taken: str) -> bool:
|
def _branch_hit(taken: str) -> bool:
|
||||||
if taken == "-":
|
if taken == "-":
|
||||||
return False
|
return False
|
||||||
try:
|
return int(taken) > 0
|
||||||
return int(taken) > 0
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _add_branch(record: FileCoverage, line: int, taken: str) -> None:
|
def _add_branch(record: FileCoverage, line: int, taken: str) -> None:
|
||||||
@@ -653,6 +650,10 @@ def _method_line(method) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _counter_value(counter, name: str) -> int:
|
||||||
|
return int(counter.get(name) or "0")
|
||||||
|
|
||||||
|
|
||||||
def _record_jacoco_method(found: dict[str, list[JacocoMethod]], class_name: str, method) -> None:
|
def _record_jacoco_method(found: dict[str, list[JacocoMethod]], class_name: str, method) -> None:
|
||||||
if method.tag != "method":
|
if method.tag != "method":
|
||||||
return
|
return
|
||||||
@@ -662,8 +663,8 @@ def _record_jacoco_method(found: dict[str, list[JacocoMethod]], class_name: str,
|
|||||||
key = f"{class_name}#{method.get('name', '')}"
|
key = f"{class_name}#{method.get('name', '')}"
|
||||||
found.setdefault(key, []).append(
|
found.setdefault(key, []).append(
|
||||||
JacocoMethod(
|
JacocoMethod(
|
||||||
missed=int(counter.get("missed") or "0"),
|
missed=_counter_value(counter, "missed"),
|
||||||
covered=int(counter.get("covered") or "0"),
|
covered=_counter_value(counter, "covered"),
|
||||||
line=_method_line(method),
|
line=_method_line(method),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -770,14 +771,17 @@ def _merge_lcov(root: Path) -> dict[str, dict[int, tuple[int, int]]]:
|
|||||||
return merged
|
return merged
|
||||||
|
|
||||||
|
|
||||||
def _merge_go(root: Path) -> dict[str, list[tuple[int, int, int, int]]]:
|
def _go_report_paths(root: Path) -> list[Path]:
|
||||||
paths = [
|
paths = [root / "target" / "coverage" / "coverage.out"]
|
||||||
root / "target" / "coverage" / "coverage.out",
|
paths.append(root / "target" / "coverage" / "go" / "coverage.out")
|
||||||
root / "target" / "coverage" / "go" / "coverage.out",
|
paths.append(root / "coverage.out")
|
||||||
root / "coverage.out",
|
|
||||||
]
|
|
||||||
paths.extend(root.glob("*/target/coverage/go/coverage.out"))
|
paths.extend(root.glob("*/target/coverage/go/coverage.out"))
|
||||||
paths.extend(root.glob("*/*/target/coverage/go/coverage.out"))
|
paths.extend(root.glob("*/*/target/coverage/go/coverage.out"))
|
||||||
|
return paths
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_go(root: Path) -> dict[str, list[tuple[int, int, int, int]]]:
|
||||||
|
paths = _go_report_paths(root)
|
||||||
merged: dict[str, list[tuple[int, int, int, int]]] = {}
|
merged: dict[str, list[tuple[int, int, int, int]]] = {}
|
||||||
for text in _merge_texts(paths):
|
for text in _merge_texts(paths):
|
||||||
for key, segments in parse_go_profile(text).items():
|
for key, segments in parse_go_profile(text).items():
|
||||||
|
|||||||
@@ -273,6 +273,16 @@ def test_changed_files_follow_git_status(tmp_path, monkeypatch, capsys):
|
|||||||
_changed_files(tmp_path)
|
_changed_files(tmp_path)
|
||||||
assert silent.value.code == 128
|
assert silent.value.code == 128
|
||||||
|
|
||||||
|
def status_fails(args, **kwargs):
|
||||||
|
if "rev-parse" in args:
|
||||||
|
return _Completed(0, f"{tmp_path.resolve()}\n")
|
||||||
|
return _Completed(1, "", "")
|
||||||
|
|
||||||
|
monkeypatch.setattr("crapper.cli.subprocess.run", status_fails)
|
||||||
|
with pytest.raises(GitError, match="git status failed") as status:
|
||||||
|
_changed_files(tmp_path)
|
||||||
|
assert status.value.code == 1
|
||||||
|
|
||||||
|
|
||||||
def test_relative_paths_are_resolved_under_the_project_root(tmp_path):
|
def test_relative_paths_are_resolved_under_the_project_root(tmp_path):
|
||||||
_write(tmp_path, "src/demo/core.clj", "(ns demo.core)\n\n(defn choose [x]\n (if x 1 0))\n")
|
_write(tmp_path, "src/demo/core.clj", "(ns demo.core)\n\n(defn choose [x]\n (if x 1 0))\n")
|
||||||
|
|||||||
@@ -58,6 +58,13 @@ def test_lcov_branch_records_override_line_hits():
|
|||||||
assert bundle.percent_for(scored) == 50.0
|
assert bundle.percent_for(scored) == 50.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_branch_count_that_is_not_a_number_is_ignored():
|
||||||
|
text = "SF:src/demo/app.ts\nDA:3,1\nBRDA:3,0,0,nope\nend_of_record\n"
|
||||||
|
parsed = parse_lcov(text)["src/demo/app.ts"]
|
||||||
|
assert parsed[3] == (1, 1)
|
||||||
|
assert 3 not in parsed.branches
|
||||||
|
|
||||||
|
|
||||||
def test_a_branchless_span_keeps_line_coverage():
|
def test_a_branchless_span_keeps_line_coverage():
|
||||||
text = "SF:src/demo/app.ts\nDA:2,1\nDA:3,0\nBRDA:8,0,0,1\nBRDA:8,0,1,0\nend_of_record\n"
|
text = "SF:src/demo/app.ts\nDA:2,1\nDA:3,0\nBRDA:8,0,0,1\nBRDA:8,0,1,0\nend_of_record\n"
|
||||||
bundle = CoverageBundle(lcov=parse_lcov(text))
|
bundle = CoverageBundle(lcov=parse_lcov(text))
|
||||||
|
|||||||
@@ -76,6 +76,26 @@ def test_existing_coverage_script_is_left_alone(tmp_path):
|
|||||||
assert command == ["npm", "run", "coverage"]
|
assert command == ["npm", "run", "coverage"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_an_npm_coverage_script_does_not_install_a_provider(tmp_path, monkeypatch):
|
||||||
|
_write(
|
||||||
|
tmp_path,
|
||||||
|
"package.json",
|
||||||
|
json.dumps({"scripts": {"coverage": "vitest run --coverage"}}),
|
||||||
|
)
|
||||||
|
source = _write(tmp_path, "src/app.ts", "export function view() { return 1 }\n")
|
||||||
|
commands = []
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"crapper.runners.run_shell",
|
||||||
|
lambda command, cwd: commands.append(list(command)) or 0,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"crapper.runners._ensure_vitest_coverage",
|
||||||
|
lambda package: (_ for _ in ()).throw(AssertionError(package)),
|
||||||
|
)
|
||||||
|
assert run_coverage(tmp_path, [source], None) == 0
|
||||||
|
assert commands == [["npm", "run", "coverage"]]
|
||||||
|
|
||||||
|
|
||||||
def test_node_test_script_still_uses_c8(tmp_path):
|
def test_node_test_script_still_uses_c8(tmp_path):
|
||||||
_write(tmp_path, "package.json", json.dumps({"scripts": {"test": "node --test"}}))
|
_write(tmp_path, "package.json", json.dumps({"scripts": {"test": "node --test"}}))
|
||||||
report_dir = tmp_path / "target" / "coverage" / "typescript"
|
report_dir = tmp_path / "target" / "coverage" / "typescript"
|
||||||
|
|||||||
@@ -69,6 +69,20 @@ export function text() {
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_callback_outside_a_call_stays_inside_its_function():
|
||||||
|
source = """
|
||||||
|
export function outer(flag: boolean) {
|
||||||
|
const local = (n: number) => (n > 0 ? 1 : 0);
|
||||||
|
if (flag) return new Handler((req) => (req.ok ? 1 : 0));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
functions = functions_in_source(source, "src/demo/box.ts", "/proj")
|
||||||
|
assert [(fn.namespace, fn.name, fn.complexity) for fn in functions] == [
|
||||||
|
("demo.box", "outer", 4)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_express_handlers_are_entries_and_leave_the_parent():
|
def test_express_handlers_are_entries_and_leave_the_parent():
|
||||||
source = """
|
source = """
|
||||||
export function mount(app) {
|
export function mount(app) {
|
||||||
|
|||||||
Reference in New Issue
Block a user