Skip to content

feat(analyzers): read skips in same-file helpers (spec 015 phase 3) - #196

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

adrian-xping merged 3 commits into
feat/spec-015-csharp-skip-extractionfrom
phase/spec-015-csharp-skip-extraction/3-helpers

Conversation

@adrian-xping

Copy link
Copy Markdown
Contributor

Spec 015 (docs/specs/core/015-csharp-skip-extraction.md), phase 3: Helpers.

Spec 015 §9: skips in same-file helpers. SkipExtractor.Extract now receives the test's ExtractedAssertions (as TimeoutExtractor does) and reads each helper Spec 013 followed, once per call site. Reasons fold helper parameters through Spec 014's FoldScope; skipWhen…/makesConditional arguments that name a parameter are read as the call's argument, so SkipOn(true) around Skip.If(flag, …) is unconditional. §7 rule 4's reach is checked in the helper and at the call site. The reach fixture gains the helper cases (top-level skip, skip under if, call under if, swallowing try at the call site, awaited helper with ConfigureAwait, nested helper, literal substitution into Skip.If), and AHelperSkipIsConditionalWhenItsCallIs plus two companion tests cover the rest.

Notes

  • Spec §9 gains an 'as built' paragraph, mirroring Spec 014 §10: Spec 013 already follows every single-candidate same-file helper whatever it holds, so the shared resolver needed no 'holds something' parameter. Skip extraction reuses ExtractedAssertions.FollowedHelpers.
  • A helper's skip sorts (§8.1) at its call site's position; its span stays in the helper.
  • Literal substitution for skipWhen/makesConditional is one level only: a parameter the helper reassigns, or one that can't be mapped (params, unbindable), is read as written (so it makes the skip conditional).
  • The reach fixture now has a second class (XunitReachTests, [SkippableFact]) for the Skip.If substitution case; the file is syntax-only and doesn't need to compile.
  • Added tests beyond the one named in §14: AHelperSkipThatDoesntReachTheTestIsNothing (swallowing catch at call site or in the helper, nested helper, call on another type) and AHelperConditionIsReadAfterSubstitution (literal, default value, non-literal argument).

Spec updated: yes

Phase row
Phase Branch suffix Covers Tests Depends on
3. Helpers 3-helpers §9: helper skips through Spec 013's resolver; the helper cases of reach. AHelperSkipIsConditionalWhenItsCallIs. 1 (Spec 013 merged into main)

Opened by spec-runner.

SkipExtractor now takes the test's ExtractedAssertions and reads the bodies of the
helpers Spec 013 followed, once per call site. Reasons fold helper parameters in the
caller's scope; skipWhen literals are read after substitution; reach is read inside
the helper and at the call site (a swallowing catch at either means no skip). A
helper's skip keeps its span in the helper and sorts at its call site.

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

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 3, round 1

Finding Severity Where Summary Decision Reason
R1-1 nit src/Xping.Analyzers.CSharp/Skips/SkipExtractor.cs:246 An async helper called without await is read as reached on every run. An exception thrown in an async method always goes into the Task it returns and is never thrown at the call site. So a call that isn't awaited (IgnoreSandboxAsync();, or a call to an async void helper) never skips the test. The call-site reach still treats the bare expression statement as reached, and the skip is reported as unconditional. §7 rule 3 lists only await around the call and says nothing about async helpers that aren't awaited, so the spec doesn't cover this case either. fix Real and in phase 3's scope (§9 helper reach, the call-site half of §7 rule 4). An exception in an async helper goes into its returned Task, so a call that isn't awaited can't skip the test, yet the extractor reports an unconditional skip. When the followed helper is async and its call isn't under an await, treat the skip as swallowed. Add a fixture case to samples/skips/reach and a line to §9 and §7 rule 4.

…pec 015 phase 3)

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

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 3, round 2

Finding Severity Where Summary Decision Reason
R2-1 nit src/Xping.Analyzers.CSharp/Skips/SkipExtractor.cs:410 Unobserved treats a Task as dropped only when the call is an expression statement or _ = …. It misses an expression-bodied test whose arrow body throws the value away: a void method, or an async one. In those, the async helper's Task is dropped exactly as in IgnoreSandboxAsync();. fix Real and in scope (§9 / §7 rule 4, added in this phase). In Unobserved, a call whose parent is the => clause of a void or async method drops the Task just like an expression statement, but only ExpressionStatement and _ = … are recognised. Treat the call as dropped when it is the whole => body of a void or async test method, and add a reach case plus a unit test. Update the §7 rule 4 wording to match.

… body as no skip (spec 015 phase 3)

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

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 3, round 3

Finding Severity Where Summary Decision Reason
R3-1 nit src/Xping.Analyzers.CSharp/Skips/SkipExtractor.cs:436 Unobserved only treats a => body as dropping the Task when its parent is a MethodDeclarationSyntax. A void or async local function or lambda with a => body (void Local() => IgnoreSandboxAsync();, Func<Task> f = async () => IgnoreSandboxAsync();) also drops the Task, but the code doesn't see it. reject Spec 015 §7 rule 3 lists lambdas, anonymous methods and local functions as conditions, and rule 4 names only the => body of a void or async test as dropping the Task. A skip inside a local function or lambda reads as conditional by the spec, which is the safe reading. The code matches the spec; no change.
R3-2 nit src/Xping.Analyzers.CSharp/Skips/SkipExtractor.cs:251 A block-bodied test that returns an async helper's Task (public Task T() { return IgnoreSandboxAsync(); }) is read as conditional. The call-site Reach treats ReturnStatementSyntax as a condition. The => form of the same test (public Task T() => IgnoreSandboxAsync();) is unconditional. §7 rule 4 says a Task handed back to the runner keeps the skip, yet only the => spelling gets that reading. reject §7 rule 4 says only a plain Task-returning => body hands the Task to the runner. A return statement is not in rule 3's list of always-reached ancestors, so return IgnoreSandboxAsync(); is conditional by the spec as written. The code follows the spec; no change.

@adrian-xping
adrian-xping merged commit e21bca8 into feat/spec-015-csharp-skip-extraction Dec 4, 2026
3 checks passed
@adrian-xping
adrian-xping deleted the phase/spec-015-csharp-skip-extraction/3-helpers branch December 4, 2026 03:19
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