Skip to content

Add StackTraceRegexHelper unit tests - #10655

Open
Amaury Levé (Evangelink) wants to merge 2 commits into
mainfrom
dev/amauryleve/test-stacktrace-regex-helper
Open

Add StackTraceRegexHelper unit tests#10655
Amaury Levé (Evangelink) wants to merge 2 commits into
mainfrom
dev/amauryleve/test-stacktrace-regex-helper

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

  • add focused coverage for located and locationless stack-frame regex branches
  • validate localized runtime tokens and file/line formats with Windows and Unix paths, generic and async frames, named captures, and false-positive resistance
  • verify NET7+ generated-regex location captures, pre-.NET7 fallback behavior, and the actual MSBuild helper's cached bounded-timeout regex

Validation

  • clean multi-target builds with binlogs for Microsoft.Testing.Platform.UnitTests and Microsoft.Testing.Platform.MSBuild.UnitTests
  • Platform full suite: 2,214 passed on net8.0; 2,215 passed on net9.0; 2,164 passed on net462
  • MSBuild full suite: 35 passed on net8.0; 35 passed on net9.0

Closes #10653

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 20, 2026 02:05
@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Aug 20, 2026
@github-actions

This comment has been minimized.

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.

Pull request overview

Adds focused unit coverage for stack-frame regex parsing and configuration.

Changes:

  • Tests localized, located, and locationless stack frames.
  • Covers invalid frames, regex options, caching, and timeout constants.
Show a summary per file
File Description
StackTraceRegexHelperTests.cs Adds regex and StackTraceHelper unit tests.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Test Reviewer on PR (on open / sync) workflow. · auto · 89.9 AIC · ⌖ 3.97 AIC · ⊞ 16.9K ·

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 20, 2026 02:21
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Expert test review — PR #10655

GradeTestMutationNotesHow to improve
A (90–100) new StackTraceHelperTests.
TryFindLocationFromStackFrame_
InitializesRegexWithBoundedTimeout
2/2 killed Reflects into the real cached s_regex and asserts it uses the bounded timeout, not an infinite one.
A (90–100) new StackTraceRegexHelperTests.
CreateFrameRegexPattern_
FrameWithLocation_
CapturesCodeFileAndLine
4/4 killed Data-driven, localization-safe, and checks that code1 stays unmatched alongside the positive groups.
A (90–100) new StackTraceRegexHelperTests.
CreateFrameRegexPattern_
FrameWithoutLocation_
CapturesCodeOnlyWhenAllowed
4/4 killed Contrasts permissive vs. location-only patterns on the same input, verifying each capture group independently.
A (90–100) new StackTraceRegexHelperTests.
CreateFrameRegexPattern_
TextThatIsNotExactlyAFrame_
DoesNotMatch
5/5 killed Exercises anchoring (^/$) and numeric-only line captures with five distinct invalid mutations.
A (90–100) new StackTraceRegexHelperTests.
GetFrameRegex_
FrameWithLocation_
CapturesCodeFileAndLine
3/3 killed Directly verifies the NET7+ hardcoded GeneratedRegex location branch, closing the earlier review gap.
A (90–100) new StackTraceRegexHelperTests.
GetFrameRegex_
HasExplicitCapturesAndNoTimeout
3/3 killed Confirms the Platform path intentionally uses an infinite timeout and (pre-NET7) caches/compiles the regex.
A (90–100) new StackTraceRegexHelperTests.
GetFrameRegex_
MatchesFrameFormatForCurrentTarget
2/2 killed Covers the no-location branch across both NET7+ and legacy targets via a real captured runtime frame.

All 7 newly added/modified tests reviewed cleanly. Two prior high-confidence findings from this run's earlier passes — (1) the MSBuild timeout assertion not exercising the actual cached regex, and (2) GetFrameRegex_MatchesFrameFormatForCurrentTarget missing NET7+ location-branch coverage — were already addressed in commit bddf26849 and are reflected in the grades above.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Suggestions on the Files
changed tab can be applied with one click. Re-run with
/review-tests.

🤖 Automated content by GitHub Copilot. Generated by the Test Reviewer on PR (on open / sync) workflow. · auto · 51.8 AIC · ⌖ 3.55 AIC · ⊞ 16.9K · [◷]( · )

@github-actions

Copy link
Copy Markdown
Contributor

🧵 Parallel-safety audit — PR #10655

Parallelization — one row per test assembly audited:

Test assembly Scope Workers Analyzer coverage
Microsoft.Testing.Platform.MSBuild.UnitTests MethodLevel 0 (CPU count) coverable once the parallel-safety analyzers ship (attribute-based opt-in in Program.cs)
Microsoft.Testing.Platform.UnitTests MethodLevel 0 (CPU count) coverable once the parallel-safety analyzers ship (attribute-based opt-in in Program.cs)

Both assemblies opt into [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)], so every test method is its own scheduling chunk and cross-test races are live, not just readiness concerns.

Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — by severity: Critical 0 · High 0 · Warning 0 · Info 0.

This PR's changed test surface is:

  • test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/StackTraceHelperTests.cs — adds TryFindLocationFromStackFrame_InitializesRegexWithBoundedTimeout, which only reads StackTraceHelper's static regex field via reflection and asserts on its MatchTimeout. No mutation of process-global state, no shared/relative filesystem paths, no [ResourceLock]/[DoNotParallelize] changes. On this project's TFMs (net8.0/net9.0, both NET7_0_OR_GREATER), StackTraceHelper.GetFrameRegex() is the source-generated [GeneratedRegex] overload — there is no mutable s_regex field on this code path at all, so there is no lazy-init race to flag here either.
  • test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/StackTraceRegexHelperTests.cs (new file) — all test methods operate on locally constructed Regex instances via CreateRegex(...)/StackTraceHelper.GetFrameRegex(). CultureInfo.InvariantCulture is used only as a read-only format argument (not a CurrentCulture mutation), Environment.NewLine is read-only, and CaptureRuntimeStackFrame() only reads Exception.StackTrace. No environment variables, current-directory, console state, or shared static mutable fields are written. No path construction or filesystem I/O anywhere in the file.

No changed lifecycle members ([TestInitialize]/[ClassInitialize]/etc.), no changed class- or assembly-level [ResourceLock]/[DoNotParallelize]/[Parallelize] declarations, and no parallelization-config files (.runsettings, testconfig.json, Directory.Build.props) were touched by this PR.

Verdict: clean audit — nothing unsafe under MethodLevel parallelism. No action needed.

Advisory only — heuristic, non-blocking. Re-run with /parallel-audit. This audit answers "is it parallel-safe?"; for testability, smells, or flakiness see the detect-static-dependencies / test-smell-detection / test-anti-patterns analyses.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · auto · 65.8 AIC · ⌖ 2.94 AIC · ⊞ 24.8K · [◷]( · )

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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test-improver] Add unit tests for StackTraceRegexHelper

3 participants