Skip to content

Remove Debug/Release line number branching from tests#8

Open
nohwnd wants to merge 1 commit intomainfrom
remove-debug-release-line-checks
Open

Remove Debug/Release line number branching from tests#8
nohwnd wants to merge 1 commit intomainfrom
remove-debug-release-line-checks

Conversation

@nohwnd
Copy link
Owner

@nohwnd nohwnd commented Mar 19, 2026

Summary

Add a \SourceAssert\ helper that reads actual source files to validate PDB-reported line numbers, replacing hardcoded Debug/Release conditional checks. This makes tests behave identically in both configurations, fixing the issue where CI (Release) and local (Debug) runs had different behavior.

Changes

  • *New \SourceAssert.cs* in test utilities with:
    • \LineIsWithinMethod(sourceFile, methodName, actualLine)\ — asserts a PDB line is within a method's range
    • \GetMethodRange\ / \GetAllMethodRanges\ — parse source files to find method line ranges
    • \FindSourceFile(assemblyPath, methodName)\ — navigates from a DLL to its project source file
  • DiaSessionTests — removed \ValidateMinLineNumber/\ValidateLineNumbers\ helpers, replaced with \SourceAssert\
  • DifferentTestFrameworkSimpleTests — removed Debug/Release branching for NUnit and xUnit adapter line assertions
  • DiscoverTests — removed dead Debug/Release branching (both branches already asserted the same value)

How it works

Instead of hardcoding expected line numbers per build configuration, the tests now read the actual source file, find the method by its signature (looking for \methodName(\ patterns), and verify the PDB-reported line falls within that method's declaration range (from attributes through closing brace).

Fixes microsoft#15458

@nohwnd nohwnd force-pushed the remove-debug-release-line-checks branch 3 times, most recently from 6e2b787 to ecbd72f Compare March 19, 2026 16:28
Add SourceAssert helper that reads actual source files to validate
PDB-reported line numbers, replacing hardcoded Debug/Release conditional
checks. The helper finds method declarations (including attributes) and
body ranges in source files, making line number assertions work
identically in both configurations.

Changes:
- New SourceAssert.cs with LineIsWithinMethod, GetMethodRange,
  GetAllMethodRanges, and FindSourceFile methods
- DiaSessionTests: removed ValidateMinLineNumber/ValidateLineNumbers
  helpers, using SourceAssert instead
- DifferentTestFrameworkSimpleTests: removed Debug/Release branching
  for NUnit and xUnit adapter line assertions
- DiscoverTests: removed dead Debug/Release branching

Fixes microsoft#15458

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd force-pushed the remove-debug-release-line-checks branch from ecbd72f to b520286 Compare March 19, 2026 17:11
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.

Test behavior differs in release mode

1 participant