Skip to content

feat(analyzers): read disabled C# tests: commented out, compiled out, attribute removed (spec 015 phase 2) - #195

Merged
adrian-xping merged 5 commits into
feat/spec-015-csharp-skip-extractionfrom
phase/spec-015-csharp-skip-extraction/2-disabled
Dec 4, 2026
Merged

adrian-xping merged 5 commits into
feat/spec-015-csharp-skip-extractionfrom
phase/spec-015-csharp-skip-extraction/2-disabled

Conversation

@adrian-xping

Copy link
Copy Markdown
Contributor

Spec 015 (docs/specs/core/015-csharp-skip-extraction.md), phase 2: Disabled tests.

Implements Spec 015 phase 2 (§10, §11 disabled, §12). New Skips/CommentFragments (comment runs, pre-filter, member-by-member parse with columns preserved), Skips/PreprocessorRegions (branch conditions, constant-false by enumeration up to 12 symbols, outermost regions), Skips/DeclarationScope (namespaces and types at a position, test methods in a fragment) and Skips/DisabledTests (compiled-out regions, attributeRemoved). CSharpTestDiscovery now exposes per-member framework and marker reading and stops the attached-block walk at lines owned by commented-out members (the scan parses only runs ending directly above a test). CSharpTestAnalyzer analyzes the old side first, writes disabled tests, converts MSTest tests whose class lost its marker, and drops disabled copies of live tests. Adds the commented-out, preprocessor and attribute-removed fixtures, switches the skip fixtures and the facts golden check to analyze each pair as a change set so attributeRemoved sees the old side, and makes the facts check compare every field of every disabled test.

Notes

  • Spec 015 updated: §10.2 says a /* */ run must start its line and that // becomes two spaces (columns map back as is); §10.3 says how a region is parsed (inside a class written around it, which must end where the region does); §13's attribute-removed row moves the renamed-file and added-file cases to the unit test ARemovedAttributeNeedsTheOldTest, since a fixture folder has no pair status; §15 lists the two extra files (CommentFragments, DeclarationScope).
  • The existing skip fixtures' expected.json files are unchanged after switching SkipFixtureTests to the full analyzer on a modified pair.
  • Scan cost: discovery now classifies every line of every scanned file to find comment runs, but parses only runs that pass the test-attribute pre-filter and end directly above a live test. The explicit budget test AScanOfTwentyThousandTestsFitsTheBudget was not run.
  • Known approximations: a comment run's namespace line sets the namespace for the rest of the run (a block namespace's closing //} doesn't pop it); a comment inside an enum gets the enclosing class as scope; block comments that don't start their line are not read.
  • Extra unit tests beyond §14's list: spans from the // column, a commented test outside a class, a whole commented file, elif/else ruled out by earlier branches, a region starting inside a method, overloads, a class still run by a marked derived class, and the scan not attaching a commented test's marker to the live test below.

Spec updated: yes

Phase row
Phase Branch suffix Covers Tests Depends on
2. Disabled tests 2-disabled §10, §11 (disabled), §12: comment runs and fragments, constant-false regions, attribute removed; the commented-out, preprocessor, attribute-removed folders; the golden check. Disabled tests, §12. 1

Opened by spec-runner.

… attribute removed (spec 015 phase 2)

Comment runs between members are uncommented and parsed one member at a time; outermost
constant-false #if branches are parsed as class members; a method that lost its test
attribute (or an MSTest class that lost [TestClass]) is attributeRemoved against the old side.
Disabled tests carry name, fingerprint, span, disabled, suppressions and body only, and a
disabled copy next to a live test of the same name is dropped. The attached-block walk stops
at members kept from comment runs, in the facts and the identity scan alike.

Spec-Runner: spec=015 phase=2 step=implement
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 1

Finding Severity Where Summary Decision Reason
R1-1 nit src/Xping.Analyzers.CSharp/CSharpTestAnalyzer.cs:88 On the new side, every discovery diagnostic is reported, including XPD007/XPD026 for MSTest tests that LostItsClassMarker now writes as disabled (attributeRemoved). Spec 015 §10.1 says disabled tests get no XPD007 or XPD026, because those are for live tests. The diagnostics should leave out the notLive positions. fix Confirmed: CSharpTestAnalyzer.cs:88 adds every discovery diagnostic on the new side, including those for tests in notLive that are written as disabled. Spec 015 §10.1 says disabled tests get no XPD007 or XPD026. Drop diagnostics that belong to notLive positions.
R1-2 nit src/Xping.Analyzers.CSharp/Skips/CommentFragments.cs:128 A marker loses its commented-out test when a prose line sits between them. The marker line stays a comment, but the prose line below it is uncommented into plain text. So the attempt that starts at the marker fails to parse, and the next attempt starts at [Fact] without the marker. A live test keeps a marker across prose comments (Spec 012 §6.2), and §10.2 says the marker line starts the attempt so it stays in the member's attached block. fix Confirmed in CommentFragments.Lines: a marker line stays a comment but a prose line below it is uncommented to plain text, so the attempt that starts at the marker fails to parse and the marker is lost. Spec 015 §10.2 says prose lines are skipped, not fatal, and that the marker stays attached. Keep prose lines between a marker and the member as comments (or equivalent) so the attempt parses.
R1-3 nit src/Xping.Analyzers.CSharp/Skips/CommentFragments.cs:52 A line that starts with /* is assumed to open a block comment, and the closing */ is found with a plain text search. That is before checking that the /* is really comment trivia. If no */ follows, the scan breaks and reads no more of the file. If one does follow, everything up to it is skipped. Such a line can be text inside a multi-line verbatim or raw string, which is common in analyzer and SQL tests. fix Confirmed: Read treats a line starting with /* as a block comment and looks for */ by text search, without checking it is comment trivia, and breaks the whole scan when none is found. Text inside a multi-line string can trigger this. Verify the position is real comment trivia (or skip the line and continue) instead of breaking.

…drop fingerprint diagnostics of disabled tests (spec 015 phase 2)

Spec-Runner: spec=015 phase=2 step=fix-1
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 2

Finding Severity Where Summary Decision Reason
R2-1 important src/Xping.Analyzers.CSharp/Skips/DisabledTests.cs:82 A compiled-out region's scope (namespaces, containing types, whether it is in a class) is always read from source.First, the tree with no symbols defined. When the region sits inside an outer #if SYMBOL branch, that branch is disabled text in the first tree, so the class around the region is missing there. The comment-run path picks the tree where the text is live (FreeIn), but this path does not. So §10.1's name, 'the namespaces and containing types at the declaration's position', comes out wrong, or the test is dropped because InClass is false. fix Confirmed in code: DisabledTests.CompiledOut calls DeclarationScope.At(source.First, region.Start), and DeclarationScope.At only walks the tree's live members. A region inside an outer #if SYMBOL branch is disabled text in the first tree, so the enclosing namespace/class is missing there (InClass false, or the wrong containing types). CommentFragments already picks the live tree with FreeIn. This is §10.1/§10.3 in phase 2's scope. Read the scope from the tree (First, then Second) in which the region start is inside the live enclosing members, and add a fixture or test for a region nested in an outer #if.

…rective is live (spec 015 phase 2)

Spec-Runner: spec=015 phase=2 step=fix-2
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 3

Finding Severity Where Summary Decision Reason
R3-1 important src/Xping.Analyzers.CSharp/CSharpTestDiscovery.cs:96 The identity scan (CSharpIdentityScanner, everyCommentRun: false) parses only comment runs whose last line is the line directly above a test's first attribute. But the attached-block walk (AttachedComments) also passes over /// doc-comment lines. A // run doesn't include those lines: Classify marks them Doc and the run ends there. So when a doc comment sits between a commented-out test and a live test, the scan never parses the run and its OwnedLines stay empty, while the facts (everyCommentRun: true) parse it. The two then compute different attached blocks for the same live test. Spec 015 §15 says the walk stops at the commented member's last line "in the facts and the scan alike". fix Confirmed in CSharpTestDiscovery.cs:95-97: above holds only the line directly above the declaration, but AttachedComments (line 533) also walks over /// lines. A // run ending above a doc block is never parsed in the scan, so OwnedLines is empty there and the scan and the facts compute different attached blocks. Spec 015 §10.2/§17 says the walk stops at the commented member's last line in the facts and the scan alike, which is this phase's scope. Fix: compute above from the top of the attached comment/doc block.

…entity scan

The attached-block walk passes over /// lines, so the scan must parse a
commented member that ends above them, as the facts do; otherwise the
live test took the commented test's fingerprint in the scan only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 3

Finding Severity Where Summary Decision Reason
R3-1 important src/Xping.Analyzers.CSharp/CSharpTestDiscovery.cs:97 The R3-1 fix only partly works. LineAboveDocs skips /// lines only when they sit directly above the declaration. But the attached-block walk (AttachedComments) passes over any mix of // and /// lines up to a blank line. If a // marker sits between a doc block and the test, above is the marker line. That marker line is its own one-line run, because Classify ends a run at a Doc line. So the run above the doc block, which holds the commented-out member, is never parsed in the scan. The facts parse it (everyCommentRun: true), so the scan and the facts still compute different attached blocks for the same live test. Spec 015 §10.2/§15 says the walk must stop at the commented member's last line in the facts and the scan alike. fix Confirmed in CSharpTestDiscovery.cs:97. LineAboveDocs only skips /// lines directly above the declaration, but AttachedComments passes over any mix of // and /// lines up to a blank line. With a // marker between a doc block and the test, the run above the doc block is never marked wanted in the scan, though the facts (everyCommentRun) parse it. Scan and facts then compute different attached blocks. Spec 015 §10.2/§15 requires both to stop at the commented member's last line. In scope for phase 2. Fix: in scan mode, mark every line of the contiguous ////// block above each test (up to the first blank or non-comment line) as wanted, and add a test for the marker-between-doc-and-test case.

…he identity scan

The attached-block walk crosses any mix of // and /// lines, so a run
ending anywhere in that block must be parsed in the scan, as in the
facts; a marker between a doc comment and the test hid the commented
test above them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 3

No findings.

@adrian-xping
adrian-xping merged commit b2bd7e3 into feat/spec-015-csharp-skip-extraction Dec 4, 2026
5 checks passed
@adrian-xping
adrian-xping deleted the phase/spec-015-csharp-skip-extraction/2-disabled branch December 4, 2026 03:02
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.

1 participant