llvm-cov region[5] indexes that function's filenames, not unit["files"].
On Apple LLVM 21 those orders differ, so the span covering Place.swift line 5
was stored on test_entry_point.swift and the return stayed uncovered.
Proved by tests/fixtures/swift/function-filenames.json, which failed before
the fix (Place.swift received (1, 1, 1) instead of (4, 5, 1)). 226 pytest
tests passed. crapper worst CRAP on coverage.py is 9.0. dryer found no
candidates at 0.8 in coverage.py. mutator on coverage.py: 237 killed,
0 survived, 0 uncovered.
Co-authored-by: Robert C. Martin <[email protected]>
The Swift fixes left the changed files with 33 survivors. Tests now
distinguish an empty suffix, an equal path, a segment that starts on the
function's last line, the shorter extra prefix, an equal report key that
blocks a longer file, a blank candidate, a repeated source, form-html keys,
a short llvm-cov segment, a Swift export that has a profile but no binary,
and the quiet success paths for Java, Go, Rust, Python, Vitest, rustup,
and a custom coverage command.
Proved by mutator on runners.py and coverage.py: 432 killed, 0 survived,
0 uncovered.
Co-authored-by: Robert C. Martin <[email protected]>
The manual export no longer passes -format=json, finds llvm-cov with xcrun,
and looks for the test binary under swift build --show-bin-path. The region
shape is (start_line, end_line, count), and line_covered uses the innermost
region so a nested zero count leaves those lines uncovered.
Proved by reading the README against the commands and SwiftFile docstring.
Co-authored-by: Robert C. Martin <[email protected]>
A region was only (start line, count), so a span of lines 4-5 with count 1
never marked line 5 covered. Regions are now (start_line, end_line, count).
SwiftFile.line_covered(line) is true when the innermost region containing
that line has a count above zero, so a nested zero-count region leaves its
lines uncovered. A segment is still one line. CRAP still counts each region
once, when its start line lies in the function.
Proved by the span, innermost-region, segment, xccov, and CRAP snapshot tests.
The choose fixture stays at 50% coverage and CRAP 2.5.
Co-authored-by: Robert C. Martin <[email protected]>
Current Xcode puts NameTests inside NameTests.xctest/Contents/MacOS.
Older toolchains use PackageTests, and on Linux the .xctest file is the
executable. swift_test_binary searches both, and prefers the directory
from `swift build --show-bin-path` when that command prints one.
Proved by the xctest bundle, Linux .xctest, show-bin-path preference,
relative path, and fallback tests. The dSYM is still ignored.
Co-authored-by: Robert C. Martin <[email protected]>
On a Mac, swift is /usr/bin/swift and llvm-cov lives in the Xcode toolchain.
llvm_cov_tool now falls back to `xcrun --find llvm-cov` after the PATH and
sibling lookups. A missing xcrun, a non-zero exit, an empty or missing path,
or a failure to start leaves the tool unset.
Proved by test_xcrun_finds_llvm_cov_when_it_is_not_beside_swift and
test_a_missing_or_failing_xcrun_leaves_llvm_cov_unset. The sibling still wins
when both are present.
Co-authored-by: Robert C. Martin <[email protected]>
Apple's llvm-cov rejects -format=json with "Cannot find option named 'json'".
The default export is already JSON, so swift_export_command omits the flag.
Proved by test_swift_export_uses_the_default_json_format and the package export test.
Co-authored-by: Robert C. Martin <[email protected]>
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]>
dryer scored _binding_name and _argument_label at 1.00. Both read one
child and then its simple_identifier. Callers now use _named_child.
Swift tests still pass, and dryer --threshold 0.8 reports no candidates.
Co-authored-by: Robert C. Martin <[email protected]>
A failed swift test, llvm-cov export, or xcodebuild left the previous
JSON in place, so the next score reused it. The warning says that
language scores 0%. The report is removed before the command and again
when export exits non-zero. Each failure test starts from the fixture
that scores choose at 50% and then sees 0%.
Co-authored-by: Robert C. Martin <[email protected]>
The first sorted `*PackageTests` file is the Mach-O inside a .dSYM, and
the Linux executable is named `*PackageTests.xctest`, so llvm-cov was
pointed at debug info or at nothing. Paths under a `.dSYM` bundle are
skipped, and the `.xctest` file is accepted. One test expects the
Contents/MacOS executable when a dSYM is beside it; the other expects
the Linux file.
Co-authored-by: Robert C. Martin <[email protected]>
Coverage already runs the .xcworkspace instead of the .xcodeproj beside
it, but the module name came from the project. A file next to
Proj.xcodeproj and Work.xcworkspace was Demo'd as Proj.ContentView.
The namer now checks the workspace first, and that test expects
Work.ContentView. A directory with only a project is unchanged.
Co-authored-by: Robert C. Martin <[email protected]>
A commented `.target` was a real module, so `// .target(name: "Stale"...)`
renamed Sources that the live target owns. Parentheses inside a setting
string could also end the target early. The manifest is parsed instead,
and a fragment's later calls are navigation suffixes ordered by their
end byte. The new test failed with namespace Stale, then passed for a
comment, a test target, an executable target, a string containing `)`,
and a multiline path.
Co-authored-by: Robert C. Martin <[email protected]>
Protocol subscripts and `{ get set }` properties were scored as functions
even though they contain no executable body, unlike protocol methods.
The new test lists those requirements and a real subscript, and failed
until entries required a statements node. Accessor tests still pass.
Co-authored-by: Robert C. Martin <[email protected]>
Swift packages and iOS apps had no per-function complexity or coverage join, so crapper could not write a .metrics/crap.edn entry that uml-viewer and mutator can attach to a function. The Swift reader scores top-level functions, methods, initializers, subscripts, computed properties, and closures bound with let or var. Nested closures stay inside the enclosing function. Decision points match the other languages: if, guard, loops, catch, ternary, each switch case, &&, ||, ??, and optional chaining.
Coverage reads llvm-cov JSON from swift test and xccov JSON from xcodebuild, joined on the file suffix and the function's line span. A package runs swift test --enable-code-coverage; an Xcode project runs xcodebuild and xcrun xccov view --report --json.
Proved by tests/test_swift.py against checked-in llvm-cov and xccov fixtures, the existing suite (174 passed), crapper with every function under CRAP 10, dryer with no duplicate at 0.8 or above, and mutator killing every mutant in the Swift reader.
Co-authored-by: Robert C. Martin <[email protected]>
Why: `go test -coverprofile` names each file by its module import path.
crapper found it only by path suffix, which works when the module path
happens to end with the project-relative path. A module in a subdirectory
whose name differs from its directory (`svc/go.mod` declaring
`module example.com/api`) scored 0% for every function.
What: `go_import_name` builds the profile's name for a file from the
nearest go.mod's module line and the path inside the module. The bundle
remembers its root and looks a Go file up by that name first, then by the
old suffix match. `_nearest` becomes the shared `nearest_marker` so
coverage and the runners find go.mod the same way. mutator uses
`go_import_name` so the two tools cannot drift.
Proof: three new coverage specs (nested module with a different name,
quoted module path, fallback without a module line) failed first, now
pass; 147 pass, the 2 bb/uml environment failures are unchanged.
crapper on changed code: max CRAP 9.0 (percent_for, unchanged), new
functions <= 7.0. dryer: no candidates in changed files. mutator on the
changed lines: 13/13 killed.
Why: for a top-level file like carddav.py, crapper passed --source=carddav.py
to coverage.py, which expects a module name, so the file always scored 0%.
What: python_sources now converts files to module names via _source_name.
Proof: new failing test in tests/test_runners.py, then fix; suite 146/146;
carddav.py now measured at 100% in family-and-friends-store.
A path in a built-in coverage command is one argument, a failed custom coverage command does not read a stale report, and git failures exit with git's status. The Clojure reader honors discards, metadata, and character literals. Long functions are split so every score is under 10 except the option switch.