dotnet-tarp
0.2.0
See the version list below for details.
dotnet tool install --global dotnet-tarp --version 0.2.0
dotnet new tool-manifest
dotnet tool install --local dotnet-tarp --version 0.2.0
#tool dotnet:?package=dotnet-tarp&version=0.2.0
nuke :add-package dotnet-tarp --version 0.2.0
McDcTestCoverage
Tarp is a test coverage measurement tool for C#.
What Tarp measures
From one run of your tests, in source terms (what you wrote, not the compiled IL):
- Lines: a probe runs right before each statement, and a statement's lines count as run once it
has started, so a call that throws doesn't make the lines after it look run. A compound statement's
probe covers its header (
if (...),switch (...)); its body has probes of its own. So do the condition of ado ... while, lambda bodies, switch expression arms, and field and property initializers: a line belongs to the innermost probe around it, so a lambda or an arm that never ran shows as not run even when the statement around it did. - Functions: entered or not, and which exits were taken:
returnandthrowstatements, and the end of the body when it can be reached. Methods, constructors, accessors, operators, local functions and top-level statements count; lambdas don't (their statements are still lines). - Branches: both outcomes of every decision (including
whenguards andcatchfilters), everyswitchsection (including "no case matched" for a switch without adefault), every switch expression arm, both sides of??, null and not null for?.and?[], and whether aforeachiterated at all. - Conditions: each condition of each decision seen both true and false. A decision is a boolean
expression with
&&,||,!, and on bools&,|,^,==,!=and?:(as DO-178C counts them), and the primitive patterns of aniswithand/or/not(x is > 0 and < 10has two conditions). - MC/DC: each condition shown to independently affect its decision's outcome (masking MC/DC).
MC/DC
Tarp measures masking MC/DC (modified condition/decision coverage) of the code your tests run.
In an existing solution
Install the tool and run your tests through it:
dotnet tool install -g dotnet-tarp # from nuget.org, once a release is published there
dotnet tarp test # takes the same arguments as dotnet test
Without nuget.org, download dotnet-tarp.<version>.nupkg from a GitHub release into a directory
and add --add-source <directory> to the install command. dotnet pack Tarp.BuildTool makes the
package from a checkout.
No change to the projects is needed. dotnet tarp test runs dotnet test with
Tarp.BuildTool/Tarp.targets imported into every project of the build, then prints the report.
For each C# project that isn't a test project, right before it compiles:
- Tarp builds the same compilation the compiler is about to build (sources, references,
defines, language version, source generators), rewrites every decision (
&&/||/!expressions, and the conditions ofif/while/do/for/?:) so that each evaluation records which conditions were evaluated, their values and the outcome (Tarp/McDc/DecisionRewriter.cs), and checks that the result still compiles: a decision whose instrumentation would break the build is left alone and reported (Tarp/McDc/McDcBuildInstrumenter.cs). - The rewritten sources (in
obj/.../tarp/) and the runtime (Tarp/GenerationTemplates/McDcRuntime.cs) replace the project's sources for the compiler only.#linedirectives keep errors, stack traces and the debugger on the original files. A normal build afterwards compiles the original sources again. - The instrumented code writes the distinct evaluations to
TestResults/tarp/*.hitswhen the test host exits, next to each project's map (<assembly>.<target framework>.map.json). - The report replays the evaluations through the monitor algorithm (
McDcFunctions) and lists, per decision, the evaluations seen, the conditions shown, and a test for every missing value.dotnet tarp mcdc-reportprints it again fromTestResults/tarp.
Options: --tarp-results <dir> (instead of TestResults/tarp), --tarp-report <file> (instead of the
console). In a project: <TarpExclude>true</TarpExclude> to leave it out; [ExcludeFromCodeCoverage]
leaves out a member or type.
A single project, without a build
dotnet tarp mcdc-instrument -p MyProject.csproj -o Instrumented writes an instrumented copy of the
project; build and run it, then dotnet tarp mcdc-report -d Instrumented. The copy only builds for
SDK-style projects whose sources are under the project directory, without project references.
Not instrumented
Listed in the report with the reason: decisions in expression-tree lambdas or in queries that
become expression trees (IQueryable), constant ones, ones with a condition that isn't a bool (e.g. dynamic) or with more than 16
conditions, ones in projects older than C# 7.3, and ones whose instrumentation breaks compilation.
Pattern variables (o is string s && s.Length > 0), assignments in conditions and await are fine:
each condition gets markers that keep what the compiler knows after it (see DecisionRewriter), and
the evaluation in progress is a local, so it survives an await. Files
that are generated (in obj/, *.g.cs, *.designer.cs, or marked <auto-generated>) aren't
instrumented.
How the MC/DC verdicts are checked
crosscheck/crosscheck.py runs Tarp (through crosscheck/tarp-runner) on decisions with given tests,
and compares its verdict for every condition with:
- the worked examples of A Practical Tutorial on Modified Condition/Decision Coverage (Hayhurst, Veerhusen, Chilenski, Rierson; NASA/TM-2001-210876), where the tutorial states the answer: the building blocks (and, or, xor, not), examples 1-3 and 7, and the solutions to exercises 3.3a-d and 3.5;
- clang's MC/DC (
-fcoverage-mcdc,llvm-cov show --show-mcdc), for decisions C can express (&&,||,!), including 300 random ones: clang computes unique-cause MC/DC, so it may show fewer conditions than Tarp's masking MC/DC, never more; - two checkers written from the definitions, independent of Tarp's code: masking MC/DC (a condition shows a value if flipping it alone can change the outcome) and unique-cause MC/DC with short circuit.
python3 crosscheck/crosscheck.py crosscheck/tarp-runner /tmp/crosscheck
CI runs it on Linux with LLVM 18 (set CLANG, LLVM_PROFDATA and LLVM_COV to choose the tools).
Building and releasing
CI (.github/workflows/ci.yml) builds and tests on Linux and Windows, and runs samples/e2e.sh:
it packs the tool, installs it into a copy of samples/Shop, runs dotnet tarp test, and checks the
report.
To release, push a tag: git tag v0.1.0 && git push origin v0.1.0. The release workflow
(.github/workflows/release.yml) takes the version from the tag, tests, packs, checks the package
with samples/e2e.sh, and creates a GitHub release with the package.
It also publishes the package to nuget.org, with trusted publishing (no API key to store), once that is set up:
- On nuget.org, under your user name → Trusted Publishing, add a policy: repository owner
ashalkhakov, repositoryTarp, workflow filerelease.yml, no environment. - In the GitHub repository, add a
NUGET_USERsecret with your nuget.org profile name (not your email).
To publish a tag that was released before that, run the Release workflow by hand (Actions → Release → Run workflow) with the tag: it checks the package attached to the tag's release and pushes that one.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.