Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

feat: match exceptions with a snapshot, written member-wise - #57

Merged
vbreuss merged 2 commits into
mainfrom
feat/exception-snapshots
Oct 18, 2026
Merged

vbreuss merged 2 commits into
mainfrom
feat/exception-snapshots

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 18, 2026

Copy link
Copy Markdown
Member

An exception was written as its type and message, so a snapshot could not show its parameter name, data or inner exceptions. Since aweXpect 3.4.0 a snapshot writes it member-wise instead: its message, its data when not empty, its inner exception (the inner exceptions of an AggregateException) and its other public members, recursively and sorted like any object, but without the members that differ between builds, runtimes, machines and Native AOT, like the stack trace. This package needs no change, so this adds the tests, the smoke tests under Native AOT and the documentation:

await Expect.That(() => player.Play(album, -1)).Throws<ArgumentOutOfRangeException>().Which.MatchesSnapshot()
    .For.Members().WithName("Message").Ignore();

The member rules apply to the members of an exception, e.g. to leave out a message that differs between runtimes. Under Native AOT, the own members of a custom exception are left out, as the source generator of aweXpect registers no type derived from Exception, whose TargetSite requires unreferenced code; the members of the framework exceptions, e.g. ParamName and ActualValue, are still written.

An exception was written as its type and message, so a snapshot could not show its parameter name, data or inner exceptions. Since aweXpect 3.4.0 a snapshot writes it member-wise instead: its message, its data when not empty, its inner exception (the inner exceptions of an `AggregateException`) and its other public members, recursively and sorted like any object, but without the members that differ between builds, runtimes, machines and Native AOT, like the stack trace. This package needs no change, so this adds the tests, the smoke tests under Native AOT and the documentation:

```csharp
await Expect.That(() => player.Play(album, -1)).Throws<ArgumentOutOfRangeException>().Which.MatchesSnapshot()
    .For.Members().WithName("Message").Ignore();
```

The member rules apply to the members of an exception, e.g. to leave out a message that differs between runtimes. Under Native AOT, the own members of a custom exception are left out, as the source generator of aweXpect registers no type derived from `Exception`, whose `TargetSite` requires unreferenced code; the members of the framework exceptions, e.g. `ParamName` and `ActualValue`, are still written.
@vbreuss vbreuss self-assigned this Oct 18, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 18, 2026 09:52
@vbreuss
vbreuss disabled auto-merge October 18, 2026 11:10
@vbreuss
vbreuss merged commit 9d4f297 into main Oct 18, 2026
11 checks passed
@vbreuss
vbreuss deleted the feat/exception-snapshots branch October 18, 2026 11:10
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
INTEL XEON PLATINUM 8573C 3.04GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.32 (8.0.32, 8.0.3226.50405), X64 RyuJIT x86-64-v4
DefaultJob : .NET 8.0.32 (8.0.32, 8.0.3226.50405), X64 RyuJIT x86-64-v4

Method Mean Error StdDev Gen0 Allocated
Dummy_aweXpect 136.5 ns 0.56 ns 0.53 ns 0.0045 384 B

@github-actions

Copy link
Copy Markdown

👽 Mutation Results

Mutation testing badge

aweXpect.Snapshots

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Runtime Errors Total Detected Total Undetected Total Mutants

The final mutation score is NaN%

Coverage Thresholds: high:80 low:60 break:0

@github-actions

Copy link
Copy Markdown

This is addressed in release v0.5.0.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant