A Swift package that test targets link to record which coverage counters each test moves (per-test coverage attribution). Tuist's CLI reduces the output to per-test evidence; the record layout is a contract with it (TuistKit.CoverageObserverOutput in tuist/tuist).
Sources/TestCoverageAttributionObserver- Objective-C, Foundation only. XCTest is looked up at run time (class, protocol and selectors by name), so nothing links XCTest. It reads each instrumented image's__llvm_prf_cntsdirectly and never calls the LLVM profile runtime. Registers its XCTest observer from a constructor when the test bundle loads, and hooks-[XCUIApplication launch]/-activateonce the bundle starts, to list the app processes UI tests launch. Its constructor also reads the skip list (TEST_COVERAGE_ATTRIBUTION_SKIP_FILE) and hooks+[XCTestCase defaultTestSuite]to remove the listed tests; it lives in this file because-ObjCloads only archive members that define a class. A class keeps listed tests it marks unskippable with class methods looked up by name (unskippableTests,isUnskippable,skippableTests), and the observer lists the unskippable tests that run inunskippable.tsv.Sources/TestCoverageAttribution- the Swift Testing trait (.coverageAttribution) that callstest_coverage_attribution_scope_begin/endaround each test, and cancels the teststest_coverage_attribution_is_skippedfinds in the skip list, unless the most specific.unskippable/.skippabletrait (SkippabilityTrait) says they're unskippable; it reports those throughtest_coverage_attribution_report_unskippable. Cancelling needsTest.cancel, so it's compiled only with Swift 6.3 or later; before, listed tests run, since a test a trait doesn't run is reported as passed.Tests/TestCoverageAttributionTests- runs the fixtures with attribution on and parses what the observer wrote:Records.swiftmirrors therecords.binlayout andFunctionTable.swiftmaps counters to function names as Tuist's reader does.Fixtures/Example- with SwiftPM, xcodebuild on macOS and xcodebuild on an iOS simulator.Fixtures/Concurrency- the overlapping, nested-trait and failure cases, in a package of their own since Swift Testing runs suites in parallel across the process.Fixtures/StaticArchive- links the observer from a static archive, with and without-ObjC, into a bundle with a Swift and an Objective-C test class.Fixtures/UITests- an app, its UI tests and its hosted unit tests. It's a Tuist project (Project.swift), because a UI test needs an app target and SwiftPM can't build apps;Launches.swiftreadslaunches.tsv, andSkipListTests.swiftruns theSkipListscheme serially, in parallel and as a shard and reads the result bundle.
- Never crash or block the test process: every failure path returns and the tests run as if nothing were linked.
- Never reset or write the counters.
- Changing
records.bin: updatewrite_record(),Records.swift, the README and Tuist's reader together, and bumpkRecordVersionwhen a record gains a field. - Changing
launches.tsv: updatewrite_launch(),Launches.swift, the README and Tuist's reader (CoverageObserverOutput.parseLaunches) together. - Changing the skip list format: update
load_skip_list(),SkipListTests.swift, the README and Tuist's writer together. - Changing
unskippable.tsvor the XCTest marker names: updatewrite_unskippable()/xctest_is_unskippable(),SkipListTests.swift, the README and Tuist's reader together. - No
unsafeFlagsinPackage.swift: they make the package unusable as a versioned dependency.
mise run build,mise run test,mise run lint(--fix).