Skip to content

test: collect coverage from DocExamples and Fuzz and bring both to 100% - #314

Merged
Chris-Wolfgang merged 2 commits into
mainfrom
test/coverage-every-test-assembly
Oct 12, 2026
Merged

Chris-Wolfgang merged 2 commits into
mainfrom
test/coverage-every-test-assembly

Conversation

@Chris-Wolfgang

@Chris-Wolfgang Chris-Wolfgang commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Makes every test assembly report coverage at 100%, so Stage 1 on the sync PR stops failing with "tests ran but no coverage was recorded".

Unblocks #313; part of #307.

Per assembly

Assembly Cause (evidence) Fix Before After
Tests.DocExamples No coverlet.collector reference (#313's Stage 1: Coverage: none collected) Add coverlet.collector 10.0.1 (same as Tests.Unit), then cover the gaps below no row 100%
Tests.Fuzz No coverlet.collector reference (same log) Add coverlet.collector 10.0.1, then cover the gaps below no row 100%
Tests.Unit already collected unchanged 100% 100%
Wolfgang.Extensions.IComparable (src) unchanged 100% 100%

Once collected, DocExamples measured 90.1% and Fuzz 96%. The uncovered lines and what changed:

  • Fuzz (IComparableExtensionsProperties.cs): the two null-receiver properties used try { call; return false; } catch (ArgumentNullException) { return true; }. return false cannot run on a passing run. They now use Assert.Throws<ArgumentNullException> (which fails the property when nothing is thrown) and return whether ParamName is value, which is a slightly stronger check than before.
  • DocExamples (DocExampleRotTests.cs):
    • The failure message built its list with a lambda that only ran when an example failed to compile. It now joins the diagnostics directly (string.Join(NewLine, errors)); the message still names the example's file:line and each diagnostic.
    • FindSrcDirectory now takes its start directory (production call passes AppContext.BaseDirectory, as before), so the "src not found" throw is tested.
    • The library reference was added behind if (... && seen.Add(lib)), which was always false because the test host's TPA list already contains the library. It is now added first, unconditionally, and the TPA loop skips it as already seen.
    • DocExample's parameterless constructor and Deserialize (used by xunit when discovery and execution are split) are exercised by a serialization round-trip through xunit's real SerializationHelper.
  • Tests.Unit csproj: SuppressTfmSupportBuildWarnings added. dotnet nuget why shows System.IO.Hashing 10.0.12 comes in through Microsoft.SourceLink.GitHub 10.0.401, and its buildTransitive targets warn on net5.0/6.0/7.0. This was 3 warnings in a Release build before the change and 0 after.

Exclusions removed

None. There were no [ExcludeFromCodeCoverage] attributes under tests/, and none were added.

Test changes (for review)

  • Added: tests/Wolfgang.Extensions.IComparable.Tests.DocExamples/DocExampleInfrastructureTests.cs with 2 tests: FindSrcDirectory_when_no_ancestor_contains_the_src_project_throws_DirectoryNotFoundException and DocExample_when_round_tripped_through_xunit_serialization_preserves_every_property.
  • Changed: DocExampleRotTests.cs (failure-message lambda, FindSrcDirectory(string), library-reference ordering).
  • Changed: IComparableExtensionsProperties.cs (two null-receiver properties, as described above).
  • csproj: DocExamples and Fuzz add coverlet.collector; Unit adds SuppressTfmSupportBuildWarnings.

Verified locally (Windows, this branch)

  • dotnet build IComparable-Extensions.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test on the slnx: all green. Unit had 117 tests on each of net5.0 through net10.0 and 111 on net462/472/48/481. Fuzz had 12 and DocExamples 5, both on net10.0.
  • Reproduced Stage 1 as the sync branch runs it: each test project on its net5.0–net10.0 TFMs with --collect:"XPlat Code Coverage" --settings coverlet.runsettings, then dotnet reportgenerator. Summary.txt has a row for every test assembly that ran (DocExamples, Fuzz, Unit; AotSmoke is not a test project and is skipped there too). Every row is at 100%, and src is at 100%.

No changelog fragment: nothing under src/ changed.

Round 2 (2026-10-04)

Re-measured with #313's Round 2 config (repo-template#701 Stage 2 integration skip, and #702 coverlet.runsettings with comma-separated lists and <Exclude> limited to [*]AutoGeneratedProgram). Local run: this PR's head a1aa6ef, Release, net8.0 + net10.0. Every assembly stays at 100%: src, Tests.DocExamples, Tests.Fuzz and Tests.Unit, under both the old and the new runsettings. No further test changes were needed.

Merge order: this PR first, then #313.

🤖 Generated with Claude Code

The DocExamples and Fuzz test projects had no coverlet.collector, so Stage 1
ran their tests but recorded no coverage row for either assembly. Add the
collector at the version the Unit project uses (10.0.1) and cover the lines
that a passing run never reached:

- Fuzz: the null-receiver properties used try { call; return false; } catch,
  so `return false` could never run on a pass. Assert.Throws now fails the
  property when nothing is thrown, and the property also checks ParamName.
- DocExamples: the failure-message lambda ran only on a failing example
  (join the diagnostics directly); FindSrcDirectory takes its start
  directory so its not-found throw is tested; the library reference is
  added before the TPA loop instead of behind a branch the TPA list always
  short-circuited; DocExample's parameterless ctor and Deserialize are
  exercised through xunit's SerializationHelper round-trip.
- Unit: SuppressTfmSupportBuildWarnings for the System.IO.Hashing
  net5.0-net7.0 warning from Microsoft.SourceLink.GitHub, so Release builds
  are warning-free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The changes correctly close the stated coverage gaps without altering production behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Ensures all test assemblies participate in the repository’s 100% coverage gate.

Changes:

  • Adds Coverlet collection to DocExamples and Fuzz tests.
  • Covers previously unreachable infrastructure paths.
  • Suppresses known legacy-TFM dependency warnings.
File Description
tests/​Wolfgang.Extensions.IComparable.Tests.Unit/​Wolfgang.Extensions.IComparable.Tests.Unit.csproj Suppresses known TFM support warnings.
tests/​Wolfgang.Extensions.IComparable.Tests.Fuzz/​Wolfgang.Extensions.IComparable.Tests.Fuzz.csproj Enables coverage collection.
tests/​Wolfgang.Extensions.IComparable.Tests.Fuzz/​IComparableExtensionsProperties.cs Strengthens null-receiver properties.
tests/​Wolfgang.Extensions.IComparable.Tests.DocExamples/​Wolfgang.Extensions.IComparable.Tests.DocExamples.csproj Enables coverage collection.
tests/​Wolfgang.Extensions.IComparable.Tests.DocExamples/​DocExampleRotTests.cs Makes harness paths testable and reliably references the library.
tests/​Wolfgang.Extensions.IComparable.Tests.DocExamples/​DocExampleInfrastructureTests.cs Tests source lookup failure and serialization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Chris-Wolfgang
Chris-Wolfgang merged commit 2c4995f into main Oct 12, 2026
24 checks passed
@Chris-Wolfgang
Chris-Wolfgang deleted the test/coverage-every-test-assembly branch October 12, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants