Skip to content

Name the guarded API in ThrowIfVerifyHasBeenRun - #1864

Merged
SimonCropp merged 2 commits into
mainfrom
fix-throwif-api-frame
Aug 17, 2026
Merged

Name the guarded API in ThrowIfVerifyHasBeenRun#1864
SimonCropp merged 2 commits into
mainfrom
fix-throwif-api-frame

Conversation

@SimonCropp

@SimonCropp SimonCropp commented Aug 17, 2026

Copy link
Copy Markdown
Member

The message named the calling code as "The API":

The API 'MyTests.SomeTest' must be called prior to any Verify has run.

which points at the wrong place to move into a [ModuleInitializer].

First attempt read frame 0 instead of frame 1, and CI caught that it does not hold. Whether the guarded API has a stack frame of its own is a JIT decision: on net48 in release VerifierSettings.IgnoreMembers is inlined into its caller, so frame 0 is the caller. No frame index is correct — with the original GetFrame(1) the same net48 release run names Xunit.Assert.RecordException, two frames adrift, because the test lambda is inlined too.

So the name now comes from [CallerMemberName], which the compiler fills in at each of the 111 call sites. It cannot drift with inlining, costs nothing at run time, and needs no StackTrace (which also makes it safe under trimming, where frames can be stripped).

Two consequences worth calling out:

  • The declaring type is gone from the messageCallerMemberName only supplies the member. It now reads The API 'IgnoreMembers' must be called prior…. No snapshot or doc captures this message, so nothing else moved.
  • ThrowIfVerifyHasBeenRun gains an optional parameter. Source compatible, but a binary break for anything already compiled against the no-arg signature. Every caller in this repo is rebuilt together; a third party adapter shipped as a prebuilt assembly would need a recompile. That seems acceptable for 32.0.0, but it is your call.

ThrowIfVerifyHasBeenRunTests.NamesTheApi calls a real guarded API and asserts the message names it and not the test. Verified across Debug and Release × net48 and net11.0 this time, since that axis is exactly what the first attempt missed.

Release suites: Verify.Tests net48 (1197), net11.0 (1287), net9.0 (1293); StaticSettingsTests, Verify.NUnit.Tests, Verify.MSTest.Tests, Verify.XunitV3.Tests, ApplyScrubbersTests, Verify.ExceptionParsing.Tests all green.

@SimonCropp SimonCropp added this to the 32.0.0 milestone Aug 17, 2026
The message named the calling code as "The API", pointing at the wrong place to
move into a module initializer. Reading the name off a StackTrace cannot fix
that: whether the guarded API has a frame of its own depends on the JIT, and on
net48 in release it is inlined into the caller, so no frame index is right.

The name now comes from CallerMemberName, which the compiler fills in at each
call site, so it is the same under every runtime and configuration. That drops
the declaring type from the message, since only the member name is available.
@SimonCropp
SimonCropp force-pushed the fix-throwif-api-frame branch from acc7c7b to 2c029cf Compare August 17, 2026 12:51
@SimonCropp
SimonCropp merged commit 1e73f28 into main Aug 17, 2026
5 checks passed
@SimonCropp
SimonCropp deleted the fix-throwif-api-frame branch August 17, 2026 22:25
This was referenced Aug 26, 2026
tom-wolfe pushed a commit to tom-wolfe/Wolfe.CommandLine that referenced this pull request Aug 27, 2026
Updated [Verify.XunitV3](https://github.com/VerifyTests/Verify) from
31.28.0 to 32.0.0.

<details>
<summary>Release notes</summary>

_Sourced from [Verify.XunitV3's
releases](https://github.com/VerifyTests/Verify/releases)._

## 32.0.0

- [x] [#​1832](VerifyTests/Verify#1832) Add
Inline snpashot support
- [x] [#​1835](VerifyTests/Verify#1835) Add
SettingsTask.AddContext
- [x] [#​1847](VerifyTests/Verify#1847) Honor
explicit DefaultValueHandling for bools
- [x] [#​1850](VerifyTests/Verify#1850) Stray
extension-less snapshot file crashes every run of its test
- [x] [#​1851](VerifyTests/Verify#1851) Static
UniqueForTargetFramework(Assembly) overloads ignore the assembly passed
to them
- [x] [#​1852](VerifyTests/Verify#1852)
Appended files skip scrubbing and newline normalization when a stream
converter is registered
- [x] [#​1853](VerifyTests/Verify#1853)
IgnoreParameters() ignore-all sentinel is lost when combined with
another ignore source
- [x] [#​1854](VerifyTests/Verify#1854) Format
UTC offsets with the invariant culture
- [x] [#​1855](VerifyTests/Verify#1855) Format
UTC offsets with invariant culture
- [x] [#​1856](VerifyTests/Verify#1856) Use
ticks to decide date precision
- [x] [#​1857](VerifyTests/Verify#1857) Clean #
out of file name parameters
- [x] [#​1858](VerifyTests/Verify#1858) Escape
one character trimmed date formats
- [x] [#​1859](VerifyTests/Verify#1859) Prefer
the exact type when resolving a member converter
- [x] [#​1860](VerifyTests/Verify#1860) Keep
empty collections ignored alongside instance predicates
- [x] [#​1861](VerifyTests/Verify#1861) Key the
combinations name cache by reference
- [x] [#​1862](VerifyTests/Verify#1862) Match
MSTest overloads against the test data
- [x] [#​1863](VerifyTests/Verify#1863) Report
deletes as directory relative paths
- [x] [#​1864](VerifyTests/Verify#1864) Name the
guarded API in ThrowIfVerifyHasBeenRun
- [x] [#​1865](VerifyTests/Verify#1865) Keep
stack frames that have no parameter list
- [x] [#​1866](VerifyTests/Verify#1866) Generate
the TestContext property for record test classes
- [x] [#​1867](VerifyTests/Verify#1867) Fix two
CombinationResultsConverter edge cases
- [x] [#​1868](VerifyTests/Verify#1868) Sign
sub-hour UTC offsets
- [x] [#​1869](VerifyTests/Verify#1869) Write
the received file from the stream for handle based FileStreams
- [x] [#​1870](VerifyTests/Verify#1870) Compare
prefixes ignoring case
- [x] [#​1871](VerifyTests/Verify#1871) Guard
the counter value caches with a lock
- [x] [#​1872](VerifyTests/Verify#1872) Sign
sub-hour UTC offsets

## 32.0.0-beta.16



## 32.0.0-beta.15



## 32.0.0-beta.14



## 32.0.0-beta.13



## 32.0.0-beta.12



## 32.0.0-beta.10



## 32.0.0-beta.8



## 32.0.0-beta.7



## 32.0.0-beta.6



## 32.0.0-beta.5



## 32.0.0-beta.4



## 32.0.0-beta.3



## 32.0.0-beta.2



## 32.0.0-beta.1



Commits viewable in [compare
view](VerifyTests/Verify@31.28.0...32.0.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Verify.XunitV3&package-manager=nuget&previous-version=31.28.0&new-version=32.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant