fix(sourcegen): emit default literal for value-type assertion parameters#5919
Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| CodeStyle | 1 minor |
🟢 Metrics -7 complexity
Metric Results Complexity -7
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This is a clean, well-scoped fix for a genuine Roslyn edge case. Here's my assessment:
What's Good
Correct root cause diagnosis. Roslyn reports null as the constant value for = default on non-nullable value types, but = null is invalid C# for those types (CS1750). The fix correctly branches on IsValueType and the Nullable<T> carve-out is right — Nullable<T> should stay on the null path since null is a valid default for it.
Sensible deduplication. The two FormatDefaultValue private methods were nearly identical; pulling them into DefaultValueFormatter is the right call and the useFullyQualifiedEnumName parameter neatly encodes the one intentional semantic difference between the two call sites.
Snapshot hygiene. .verified.txt files committed; .received.txt not committed. All four TFMs covered.
CompileChecker is a good addition. Structurally-correct-but-compile-broken output would otherwise slip past content-only snapshot tests. The #if NETFRAMEWORK CS0122 filter is well-documented.
Suggestions
1. Boolean trap on useFullyQualifiedEnumName
// Current — caller must know which bool means what
DefaultValueFormatter.FormatDefaultValue(value, type, useFullyQualifiedEnumName: true)Named arguments mitigate this, but with only two call sites it's also fine to keep two thin static helpers instead:
internal static class DefaultValueFormatter
{
public static string FormatDefaultValue(object? defaultValue, ITypeSymbol type)
=> FormatDefaultValueCore(defaultValue, type, useFullyQualifiedEnumName: false);
public static string FormatDefaultValueFullyQualified(object? defaultValue, ITypeSymbol type)
=> FormatDefaultValueCore(defaultValue, type, useFullyQualifiedEnumName: true);
private static string FormatDefaultValueCore(...) { ... }
}This makes the intent at each call site self-documenting without needing to read the parameter name. Not a blocker — the named-argument form is readable enough — but worth considering if more generators are added later.
2. Pre-existing: incomplete string escaping
return $"\"{str.Replace("\"", "\\\"")}\"";This only escapes ". A default value of e.g. "line1\nline2" would emit as a literal newline inside a string literal. Since this PR didn't introduce the issue and it's in a code path for test-assertion generators where string defaults are rare, it's fine to leave it, but worth tracking separately.
3. CompileChecker compiles all generated files together
This is correct behaviour (multi-file generators can have cross-file dependencies), but it means a missing reference will silently drop the error if ReferencesHelper.References doesn't include the missing assembly. If CI ever shows a false-green, this is the first place to check.
Verdict
Approving. The fix is correct, well-tested, and the deduplication is a genuine improvement. The suggestions above are minor and non-blocking.
…hods Per review feedback on thomhurst#5919: replace the `useFullyQualifiedEnumName` boolean with two thin public wrappers (`FormatDefaultValue` for the short enum form and `FormatDefaultValueFullyQualified` for the namespace-prefixed form), each delegating to a private `FormatDefaultValueCore` that retains the original parameterised body. Removes the boolean trap at call sites without changing emit behaviour. Existing snapshots compare identically.
|
Thanks! |
…hods Per review feedback on thomhurst#5919: replace the `useFullyQualifiedEnumName` boolean with two thin public wrappers (`FormatDefaultValue` for the short enum form and `FormatDefaultValueFullyQualified` for the namespace-prefixed form), each delegating to a private `FormatDefaultValueCore` that retains the original parameterised body. Removes the boolean trap at call sites without changing emit behaviour. Existing snapshots compare identically.
9ef34a6 to
024a415
Compare
…hods Per review feedback on thomhurst#5919: replace the `useFullyQualifiedEnumName` boolean with two thin public wrappers (`FormatDefaultValue` for the short enum form and `FormatDefaultValueFullyQualified` for the namespace-prefixed form), each delegating to a private `FormatDefaultValueCore` that retains the original parameterised body. Removes the boolean trap at call sites without changing emit behaviour. Existing snapshots compare identically.
024a415 to
038d561
Compare
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.40.5 to 1.45.0. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.45.0 <!-- Release notes generated using configuration in .github/release.yml at v1.45.0 --> ## What's Changed ### Other Changes * fix(generator): place CallerArgumentExpression before params in [GenerateAssertion] emit by @JohnVerheij in thomhurst/TUnit#5940 * fix(sourcegen): drop covariant TActual when [GenerateAssertion] method has its own type parameters by @JohnVerheij in thomhurst/TUnit#5935 * feat(assertions): add CancellationToken overload to WaitsFor and Eventually by @JohnVerheij in thomhurst/TUnit#5938 * fix(html-report): extract categories using MTP Key=name convention by @thomhurst in thomhurst/TUnit#5946 * feat(html-report): rewrite as split-pane design template by @thomhurst in thomhurst/TUnit#5947 ### Dependencies * chore(deps): update microsoft.testing to 2.2.3 by @thomhurst in thomhurst/TUnit#5927 * chore(deps): update mstest to 4.2.3 by @thomhurst in thomhurst/TUnit#5928 * chore(deps): update tunit to 1.44.39 by @thomhurst in thomhurst/TUnit#5929 * chore(deps): update aspire to 13.3.3 by @thomhurst in thomhurst/TUnit#5933 * chore(deps): update dependency dompurify to v3.4.4 by @thomhurst in thomhurst/TUnit#5944 * chore(deps): update dependency qs to v6.15.2 by @thomhurst in thomhurst/TUnit#5941 **Full Changelog**: thomhurst/TUnit@v1.44.39...v1.45.0 ## 1.44.39 <!-- Release notes generated using configuration in .github/release.yml at v1.44.39 --> ## What's Changed ### Other Changes * fix(tests): retry trx read to dodge MTP post-exit flush race on Windows by @thomhurst in thomhurst/TUnit#5888 * fix(pipeline): timeout + retry InstallPlaywrightModule so a hung download fails fast by @thomhurst in thomhurst/TUnit#5889 * fix(otel): require two consecutive idle windows in DrainAsync to catch in-transit POSTs by @thomhurst in thomhurst/TUnit#5890 * test(assertions): drop flaky wall-clock upper bound on WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5886 * fix(sourcegen): drop spurious ')' in MethodAssertionGenerator Task<bool> emit by @JohnVerheij in thomhurst/TUnit#5920 * fix(sourcegen): merge generic parameter lists in [AssertionExtension] emit by @JohnVerheij in thomhurst/TUnit#5921 * fix(aspnetcore): scope correlation processor per-factory to stop cross-factory tag leak by @thomhurst in thomhurst/TUnit#5891 * Changed FSharp.Core version to 10.1.300 by @licon4812 in thomhurst/TUnit#5909 * feat(mocks): add Mock.HttpClientFactory() helper by @thomhurst in thomhurst/TUnit#5894 * Harden WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5926 * fix(sourcegen): emit `default` literal for value-type assertion parameters by @JohnVerheij in thomhurst/TUnit#5919 ### Dependencies * chore(deps): update dependency nunit to 4.6.0 by @thomhurst in thomhurst/TUnit#5826 * chore(deps): update tunit to 1.44.0 by @thomhurst in thomhurst/TUnit#5882 * chore(deps): update dependency mockolate to 3.2.0 by @thomhurst in thomhurst/TUnit#5892 * chore(deps): update dependency yaml to v2.9.0 by @thomhurst in thomhurst/TUnit#5887 * chore(deps): update dependency nuget.protocol to 7.6.0 by @thomhurst in thomhurst/TUnit#5897 * chore(deps): update dependency microsoft.entityframeworkcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5898 * chore(deps): update dependency microsoft.templateengine.authoring.cli to v10.0.300 by @thomhurst in thomhurst/TUnit#5899 * chore(deps): update microsoft.extensions by @thomhurst in thomhurst/TUnit#5905 * chore(deps): update microsoft.aspnetcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5904 * chore(deps): update dependency microsoft.templateengine.authoring.templateverifier to 10.0.300 by @thomhurst in thomhurst/TUnit#5902 * chore(deps): update aspire to 13.3.1 by @thomhurst in thomhurst/TUnit#5900 * chore(deps): update dependency system.commandline to 2.0.8 by @thomhurst in thomhurst/TUnit#5903 * chore(deps): update dependency azure.storage.blobs to 12.28.0 by @thomhurst in thomhurst/TUnit#5910 * chore(deps): update dependency dotnet-sdk to v10.0.300 by @thomhurst in thomhurst/TUnit#5901 * chore(deps): update dependency stackexchange.redis to 2.13.1 by @thomhurst in thomhurst/TUnit#5906 * chore(deps): update aspire to 13.3.2 by @thomhurst in thomhurst/TUnit#5924 * chore(deps): bump mermaid from 11.12.2 to 11.15.0 in /docs by @dependabot[bot] in thomhurst/TUnit#5893 * chore(deps): update dependency streamjsonrpc to 2.24.92 by @thomhurst in thomhurst/TUnit#5915 * chore(deps): update dependency dompurify to v3.4.3 by @thomhurst in thomhurst/TUnit#5913 * chore(deps): update microsoft.build to 18.6.3 by @thomhurst in thomhurst/TUnit#5914 **Full Changelog**: thomhurst/TUnit@v1.44.0...v1.44.39 ## 1.44.0 <!-- Release notes generated using configuration in .github/release.yml at v1.44.0 --> ## What's Changed ### Other Changes * Generated mocks live in the same namespace as the mocked type by @thomhurst in thomhurst/TUnit#5870 * Show multi-step test spans in class timeline, align report ordering with execution, and correlate linked OTel activities by @Copilot in thomhurst/TUnit#5847 * fix: don't leak RUC onto Should-style comparer overloads (#5857) by @thomhurst in thomhurst/TUnit#5873 * Fix culture-dependent timestamp in HTML test report (#5868) by @thomhurst in thomhurst/TUnit#5872 * fix(mocks-http): auto-prepend `/` to partial endpoint paths (#5838) by @thomhurst in thomhurst/TUnit#5874 * Replace Report.ExpandClassTimeline with [ClassTimeline] attribute by @thomhurst in thomhurst/TUnit#5875 * feat(assertions): make ShouldAssertion<T> implement IAssertion (#5824) by @thomhurst in thomhurst/TUnit#5876 * feat(mocks): support non-span ref struct out/ref params by @thomhurst in thomhurst/TUnit#5878 * fix(core): fill optional params when invoking MethodDataSource via reflection by @thomhurst in thomhurst/TUnit#5880 * Mocks: structural fix for Mock<T> / mocked-member name collisions by @thomhurst in thomhurst/TUnit#5881 * chore(mocks): promote TUnit.Mocks packages to stable by @thomhurst in thomhurst/TUnit#5877 ### Dependencies * chore(deps): update tunit to 1.43.41 by @thomhurst in thomhurst/TUnit#5863 * chore(deps): update dependency tunit.assertions.fsharp to 1.43.41 by @thomhurst in thomhurst/TUnit#5865 * chore(deps): bump @babel/plugin-transform-modules-systemjs from 7.28.5 to 7.29.4 in /docs by @dependabot[bot] in thomhurst/TUnit#5867 * chore(deps): bump fast-uri from 3.1.0 to 3.1.2 in /docs by @dependabot[bot] in thomhurst/TUnit#5862 **Full Changelog**: thomhurst/TUnit@v1.43.41...v1.44.0 ## 1.43.41 <!-- Release notes generated using configuration in .github/release.yml at v1.43.41 --> ## What's Changed ### Other Changes * feat(playwright): expose default Context/Launch options on settings by @thomhurst in thomhurst/TUnit#5861 * fix(hooks): resolve TestDiscovery hook context type by attribute kind, not method name by @thomhurst in thomhurst/TUnit#5860 ### Dependencies * chore(deps): update tunit to 1.43.38 by @thomhurst in thomhurst/TUnit#5858 **Full Changelog**: thomhurst/TUnit@v1.43.38...v1.43.41 ## 1.43.38 <!-- Release notes generated using configuration in .github/release.yml at v1.43.38 --> ## What's Changed ### Other Changes * feat(playwright): add TUnitPlaywrightSettings defaults by @thomhurst in thomhurst/TUnit#5859 **Full Changelog**: thomhurst/TUnit@v1.43.37...v1.43.38 ## 1.43.37 <!-- Release notes generated using configuration in .github/release.yml at v1.43.37 --> ## What's Changed ### Other Changes * docs: clarify MethodDataSourceAttribute.Factory is source-generator-managed by @Copilot in thomhurst/TUnit#5835 * fix(assertions): skip ref-struct members in IsEquivalentTo (#5841) by @thomhurst in thomhurst/TUnit#5842 * feat(playwright): add composition-based fixtures by @thomhurst in thomhurst/TUnit#5840 ### Dependencies * chore(deps): update tunit to 1.43.11 by @thomhurst in thomhurst/TUnit#5821 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5830 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5829 * chore(deps): update react to ^19.2.6 by @thomhurst in thomhurst/TUnit#5839 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5848 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5849 * chore(deps): update aspire to 13.3.0 by @thomhurst in thomhurst/TUnit#5851 * chore(deps): update dependency brace-expansion to v5.0.6 by @thomhurst in thomhurst/TUnit#5853 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5854 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5855 * chore(deps): update verify to 31.16.3 by @thomhurst in thomhurst/TUnit#5856 **Full Changelog**: thomhurst/TUnit@v1.43.11...v1.43.37 ## 1.43.11 <!-- Release notes generated using configuration in .github/release.yml at v1.43.11 --> ## What's Changed ### Other Changes * perf(engine): skip execution ledger for independent tests by @thomhurst in thomhurst/TUnit#5813 * perf(engine): skip tracked object graph rediscovery by @thomhurst in thomhurst/TUnit#5814 * fix: suppress XML doc warnings in generated sources by @mvanhorn in thomhurst/TUnit#5797 * Fix xUnit Throws migration docs by @thomhurst in thomhurst/TUnit#5819 * Fix Should optional overload generation by @thomhurst in thomhurst/TUnit#5820 ### Dependencies * chore(deps): update dependency mockolate to 3.1.0 by @thomhurst in thomhurst/TUnit#5811 * chore(deps): update tunit to 1.43.2 by @thomhurst in thomhurst/TUnit#5809 * chore(deps): update dependency nunit.analyzers to 4.13.0 by @thomhurst in thomhurst/TUnit#5815 * chore(deps): update dependency yaml to v2.8.4 by @thomhurst in thomhurst/TUnit#5812 ## New Contributors * @mvanhorn made their first contribution in thomhurst/TUnit#5797 **Full Changelog**: thomhurst/TUnit@v1.43.2...v1.43.11 ## 1.43.2 <!-- Release notes generated using configuration in .github/release.yml at v1.43.2 --> ## What's Changed ### Other Changes * fix(assertions): emit auto-generated header in MethodAssertionGenerator output by @JohnVerheij in thomhurst/TUnit#5796 * fix(engine): enforce runtime exclusion for global [NotInParallel] (#5800) by @thomhurst in thomhurst/TUnit#5805 * feat(mocks): add Arg.AnyArgs() shortcut for setup/verify by @thomhurst in thomhurst/TUnit#5792 * fix(should): add specialized assertion sources by @thomhurst in thomhurst/TUnit#5806 ### Dependencies * chore(deps): update tunit to 1.41.0 by @thomhurst in thomhurst/TUnit#5789 * chore(deps): update microsoft.testing to 2.2.2 by @thomhurst in thomhurst/TUnit#5793 * chore(deps): update mstest to 4.2.2 by @thomhurst in thomhurst/TUnit#5794 * chore(deps): update docusaurus by @thomhurst in thomhurst/TUnit#5798 * chore(deps): update dependency dompurify to v3.4.2 by @thomhurst in thomhurst/TUnit#5799 * chore(deps): update dependency mockolate to v3 by @thomhurst in thomhurst/TUnit#5801 **Full Changelog**: thomhurst/TUnit@v1.41.0...v1.43.2 ## 1.41.0 <!-- Release notes generated using configuration in .github/release.yml at v1.41.0 --> ## TUnit Should() Assertions (beta) This versions comes with a beta version of TUnit.Assertions.Should - meaning that you can do: `myCode.Should().BeEqualTo(fluentShouldSyntax);` For more information see the docs: https://tunit.dev/docs/assertions/should-syntax ## What's Changed ### Other Changes * fix(reporters): unwrap TestFailedException for failure grouping by @thomhurst in thomhurst/TUnit#5776 * Fix item-at Satisfies source typing by @thomhurst in thomhurst/TUnit#5764 * ci(docs): add link-check automation and tighten Docusaurus strictness by @thomhurst in thomhurst/TUnit#5779 * feat: add TUnit.Assertions.Should package by @thomhurst in thomhurst/TUnit#5785 ### Dependencies * chore(deps): update tunit to 1.40.10 by @thomhurst in thomhurst/TUnit#5775 * chore(deps): update actions/cache action to v5 by @thomhurst in thomhurst/TUnit#5780 * chore(deps): update dependency microsoft.net.test.sdk to 18.5.1 by @thomhurst in thomhurst/TUnit#5784 **Full Changelog**: thomhurst/TUnit@v1.40.10...v1.41.0 ## 1.40.10 <!-- Release notes generated using configuration in .github/release.yml at v1.40.10 --> ## What's Changed ### Other Changes * refactor(opentelemetry): depend on TUnit.Core instead of umbrella TUnit by @thomhurst in thomhurst/TUnit#5774 ### Dependencies * chore(deps): update tunit to 1.40.5 by @thomhurst in thomhurst/TUnit#5769 **Full Changelog**: thomhurst/TUnit@v1.40.5...v1.40.10 Commits viewable in [compare view](thomhurst/TUnit@v1.40.5...v1.45.0). </details> Updated [TUnit.AspNetCore](https://github.com/thomhurst/TUnit) from 1.40.5 to 1.45.0. <details> <summary>Release notes</summary> _Sourced from [TUnit.AspNetCore's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.45.0 <!-- Release notes generated using configuration in .github/release.yml at v1.45.0 --> ## What's Changed ### Other Changes * fix(generator): place CallerArgumentExpression before params in [GenerateAssertion] emit by @JohnVerheij in thomhurst/TUnit#5940 * fix(sourcegen): drop covariant TActual when [GenerateAssertion] method has its own type parameters by @JohnVerheij in thomhurst/TUnit#5935 * feat(assertions): add CancellationToken overload to WaitsFor and Eventually by @JohnVerheij in thomhurst/TUnit#5938 * fix(html-report): extract categories using MTP Key=name convention by @thomhurst in thomhurst/TUnit#5946 * feat(html-report): rewrite as split-pane design template by @thomhurst in thomhurst/TUnit#5947 ### Dependencies * chore(deps): update microsoft.testing to 2.2.3 by @thomhurst in thomhurst/TUnit#5927 * chore(deps): update mstest to 4.2.3 by @thomhurst in thomhurst/TUnit#5928 * chore(deps): update tunit to 1.44.39 by @thomhurst in thomhurst/TUnit#5929 * chore(deps): update aspire to 13.3.3 by @thomhurst in thomhurst/TUnit#5933 * chore(deps): update dependency dompurify to v3.4.4 by @thomhurst in thomhurst/TUnit#5944 * chore(deps): update dependency qs to v6.15.2 by @thomhurst in thomhurst/TUnit#5941 **Full Changelog**: thomhurst/TUnit@v1.44.39...v1.45.0 ## 1.44.39 <!-- Release notes generated using configuration in .github/release.yml at v1.44.39 --> ## What's Changed ### Other Changes * fix(tests): retry trx read to dodge MTP post-exit flush race on Windows by @thomhurst in thomhurst/TUnit#5888 * fix(pipeline): timeout + retry InstallPlaywrightModule so a hung download fails fast by @thomhurst in thomhurst/TUnit#5889 * fix(otel): require two consecutive idle windows in DrainAsync to catch in-transit POSTs by @thomhurst in thomhurst/TUnit#5890 * test(assertions): drop flaky wall-clock upper bound on WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5886 * fix(sourcegen): drop spurious ')' in MethodAssertionGenerator Task<bool> emit by @JohnVerheij in thomhurst/TUnit#5920 * fix(sourcegen): merge generic parameter lists in [AssertionExtension] emit by @JohnVerheij in thomhurst/TUnit#5921 * fix(aspnetcore): scope correlation processor per-factory to stop cross-factory tag leak by @thomhurst in thomhurst/TUnit#5891 * Changed FSharp.Core version to 10.1.300 by @licon4812 in thomhurst/TUnit#5909 * feat(mocks): add Mock.HttpClientFactory() helper by @thomhurst in thomhurst/TUnit#5894 * Harden WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5926 * fix(sourcegen): emit `default` literal for value-type assertion parameters by @JohnVerheij in thomhurst/TUnit#5919 ### Dependencies * chore(deps): update dependency nunit to 4.6.0 by @thomhurst in thomhurst/TUnit#5826 * chore(deps): update tunit to 1.44.0 by @thomhurst in thomhurst/TUnit#5882 * chore(deps): update dependency mockolate to 3.2.0 by @thomhurst in thomhurst/TUnit#5892 * chore(deps): update dependency yaml to v2.9.0 by @thomhurst in thomhurst/TUnit#5887 * chore(deps): update dependency nuget.protocol to 7.6.0 by @thomhurst in thomhurst/TUnit#5897 * chore(deps): update dependency microsoft.entityframeworkcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5898 * chore(deps): update dependency microsoft.templateengine.authoring.cli to v10.0.300 by @thomhurst in thomhurst/TUnit#5899 * chore(deps): update microsoft.extensions by @thomhurst in thomhurst/TUnit#5905 * chore(deps): update microsoft.aspnetcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5904 * chore(deps): update dependency microsoft.templateengine.authoring.templateverifier to 10.0.300 by @thomhurst in thomhurst/TUnit#5902 * chore(deps): update aspire to 13.3.1 by @thomhurst in thomhurst/TUnit#5900 * chore(deps): update dependency system.commandline to 2.0.8 by @thomhurst in thomhurst/TUnit#5903 * chore(deps): update dependency azure.storage.blobs to 12.28.0 by @thomhurst in thomhurst/TUnit#5910 * chore(deps): update dependency dotnet-sdk to v10.0.300 by @thomhurst in thomhurst/TUnit#5901 * chore(deps): update dependency stackexchange.redis to 2.13.1 by @thomhurst in thomhurst/TUnit#5906 * chore(deps): update aspire to 13.3.2 by @thomhurst in thomhurst/TUnit#5924 * chore(deps): bump mermaid from 11.12.2 to 11.15.0 in /docs by @dependabot[bot] in thomhurst/TUnit#5893 * chore(deps): update dependency streamjsonrpc to 2.24.92 by @thomhurst in thomhurst/TUnit#5915 * chore(deps): update dependency dompurify to v3.4.3 by @thomhurst in thomhurst/TUnit#5913 * chore(deps): update microsoft.build to 18.6.3 by @thomhurst in thomhurst/TUnit#5914 **Full Changelog**: thomhurst/TUnit@v1.44.0...v1.44.39 ## 1.44.0 <!-- Release notes generated using configuration in .github/release.yml at v1.44.0 --> ## What's Changed ### Other Changes * Generated mocks live in the same namespace as the mocked type by @thomhurst in thomhurst/TUnit#5870 * Show multi-step test spans in class timeline, align report ordering with execution, and correlate linked OTel activities by @Copilot in thomhurst/TUnit#5847 * fix: don't leak RUC onto Should-style comparer overloads (#5857) by @thomhurst in thomhurst/TUnit#5873 * Fix culture-dependent timestamp in HTML test report (#5868) by @thomhurst in thomhurst/TUnit#5872 * fix(mocks-http): auto-prepend `/` to partial endpoint paths (#5838) by @thomhurst in thomhurst/TUnit#5874 * Replace Report.ExpandClassTimeline with [ClassTimeline] attribute by @thomhurst in thomhurst/TUnit#5875 * feat(assertions): make ShouldAssertion<T> implement IAssertion (#5824) by @thomhurst in thomhurst/TUnit#5876 * feat(mocks): support non-span ref struct out/ref params by @thomhurst in thomhurst/TUnit#5878 * fix(core): fill optional params when invoking MethodDataSource via reflection by @thomhurst in thomhurst/TUnit#5880 * Mocks: structural fix for Mock<T> / mocked-member name collisions by @thomhurst in thomhurst/TUnit#5881 * chore(mocks): promote TUnit.Mocks packages to stable by @thomhurst in thomhurst/TUnit#5877 ### Dependencies * chore(deps): update tunit to 1.43.41 by @thomhurst in thomhurst/TUnit#5863 * chore(deps): update dependency tunit.assertions.fsharp to 1.43.41 by @thomhurst in thomhurst/TUnit#5865 * chore(deps): bump @babel/plugin-transform-modules-systemjs from 7.28.5 to 7.29.4 in /docs by @dependabot[bot] in thomhurst/TUnit#5867 * chore(deps): bump fast-uri from 3.1.0 to 3.1.2 in /docs by @dependabot[bot] in thomhurst/TUnit#5862 **Full Changelog**: thomhurst/TUnit@v1.43.41...v1.44.0 ## 1.43.41 <!-- Release notes generated using configuration in .github/release.yml at v1.43.41 --> ## What's Changed ### Other Changes * feat(playwright): expose default Context/Launch options on settings by @thomhurst in thomhurst/TUnit#5861 * fix(hooks): resolve TestDiscovery hook context type by attribute kind, not method name by @thomhurst in thomhurst/TUnit#5860 ### Dependencies * chore(deps): update tunit to 1.43.38 by @thomhurst in thomhurst/TUnit#5858 **Full Changelog**: thomhurst/TUnit@v1.43.38...v1.43.41 ## 1.43.38 <!-- Release notes generated using configuration in .github/release.yml at v1.43.38 --> ## What's Changed ### Other Changes * feat(playwright): add TUnitPlaywrightSettings defaults by @thomhurst in thomhurst/TUnit#5859 **Full Changelog**: thomhurst/TUnit@v1.43.37...v1.43.38 ## 1.43.37 <!-- Release notes generated using configuration in .github/release.yml at v1.43.37 --> ## What's Changed ### Other Changes * docs: clarify MethodDataSourceAttribute.Factory is source-generator-managed by @Copilot in thomhurst/TUnit#5835 * fix(assertions): skip ref-struct members in IsEquivalentTo (#5841) by @thomhurst in thomhurst/TUnit#5842 * feat(playwright): add composition-based fixtures by @thomhurst in thomhurst/TUnit#5840 ### Dependencies * chore(deps): update tunit to 1.43.11 by @thomhurst in thomhurst/TUnit#5821 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5830 * chore(deps): update dependency polyfill to 10.4.0 by @thomhurst in thomhurst/TUnit#5829 * chore(deps): update react to ^19.2.6 by @thomhurst in thomhurst/TUnit#5839 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5848 * chore(deps): update dependency polyfill to 10.5.0 by @thomhurst in thomhurst/TUnit#5849 * chore(deps): update aspire to 13.3.0 by @thomhurst in thomhurst/TUnit#5851 * chore(deps): update dependency brace-expansion to v5.0.6 by @thomhurst in thomhurst/TUnit#5853 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5854 * chore(deps): update dependency polyfill to 10.5.1 by @thomhurst in thomhurst/TUnit#5855 * chore(deps): update verify to 31.16.3 by @thomhurst in thomhurst/TUnit#5856 **Full Changelog**: thomhurst/TUnit@v1.43.11...v1.43.37 ## 1.43.11 <!-- Release notes generated using configuration in .github/release.yml at v1.43.11 --> ## What's Changed ### Other Changes * perf(engine): skip execution ledger for independent tests by @thomhurst in thomhurst/TUnit#5813 * perf(engine): skip tracked object graph rediscovery by @thomhurst in thomhurst/TUnit#5814 * fix: suppress XML doc warnings in generated sources by @mvanhorn in thomhurst/TUnit#5797 * Fix xUnit Throws migration docs by @thomhurst in thomhurst/TUnit#5819 * Fix Should optional overload generation by @thomhurst in thomhurst/TUnit#5820 ### Dependencies * chore(deps): update dependency mockolate to 3.1.0 by @thomhurst in thomhurst/TUnit#5811 * chore(deps): update tunit to 1.43.2 by @thomhurst in thomhurst/TUnit#5809 * chore(deps): update dependency nunit.analyzers to 4.13.0 by @thomhurst in thomhurst/TUnit#5815 * chore(deps): update dependency yaml to v2.8.4 by @thomhurst in thomhurst/TUnit#5812 ## New Contributors * @mvanhorn made their first contribution in thomhurst/TUnit#5797 **Full Changelog**: thomhurst/TUnit@v1.43.2...v1.43.11 ## 1.43.2 <!-- Release notes generated using configuration in .github/release.yml at v1.43.2 --> ## What's Changed ### Other Changes * fix(assertions): emit auto-generated header in MethodAssertionGenerator output by @JohnVerheij in thomhurst/TUnit#5796 * fix(engine): enforce runtime exclusion for global [NotInParallel] (#5800) by @thomhurst in thomhurst/TUnit#5805 * feat(mocks): add Arg.AnyArgs() shortcut for setup/verify by @thomhurst in thomhurst/TUnit#5792 * fix(should): add specialized assertion sources by @thomhurst in thomhurst/TUnit#5806 ### Dependencies * chore(deps): update tunit to 1.41.0 by @thomhurst in thomhurst/TUnit#5789 * chore(deps): update microsoft.testing to 2.2.2 by @thomhurst in thomhurst/TUnit#5793 * chore(deps): update mstest to 4.2.2 by @thomhurst in thomhurst/TUnit#5794 * chore(deps): update docusaurus by @thomhurst in thomhurst/TUnit#5798 * chore(deps): update dependency dompurify to v3.4.2 by @thomhurst in thomhurst/TUnit#5799 * chore(deps): update dependency mockolate to v3 by @thomhurst in thomhurst/TUnit#5801 **Full Changelog**: thomhurst/TUnit@v1.41.0...v1.43.2 ## 1.41.0 <!-- Release notes generated using configuration in .github/release.yml at v1.41.0 --> ## TUnit Should() Assertions (beta) This versions comes with a beta version of TUnit.Assertions.Should - meaning that you can do: `myCode.Should().BeEqualTo(fluentShouldSyntax);` For more information see the docs: https://tunit.dev/docs/assertions/should-syntax ## What's Changed ### Other Changes * fix(reporters): unwrap TestFailedException for failure grouping by @thomhurst in thomhurst/TUnit#5776 * Fix item-at Satisfies source typing by @thomhurst in thomhurst/TUnit#5764 * ci(docs): add link-check automation and tighten Docusaurus strictness by @thomhurst in thomhurst/TUnit#5779 * feat: add TUnit.Assertions.Should package by @thomhurst in thomhurst/TUnit#5785 ### Dependencies * chore(deps): update tunit to 1.40.10 by @thomhurst in thomhurst/TUnit#5775 * chore(deps): update actions/cache action to v5 by @thomhurst in thomhurst/TUnit#5780 * chore(deps): update dependency microsoft.net.test.sdk to 18.5.1 by @thomhurst in thomhurst/TUnit#5784 **Full Changelog**: thomhurst/TUnit@v1.40.10...v1.41.0 ## 1.40.10 <!-- Release notes generated using configuration in .github/release.yml at v1.40.10 --> ## What's Changed ### Other Changes * refactor(opentelemetry): depend on TUnit.Core instead of umbrella TUnit by @thomhurst in thomhurst/TUnit#5774 ### Dependencies * chore(deps): update tunit to 1.40.5 by @thomhurst in thomhurst/TUnit#5769 **Full Changelog**: thomhurst/TUnit@v1.40.5...v1.40.10 Commits viewable in [compare view](thomhurst/TUnit@v1.40.5...v1.45.0). </details> 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 this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [TUnit.Core](https://github.com/thomhurst/TUnit) from 1.44.0 to 1.45.8. <details> <summary>Release notes</summary> _Sourced from [TUnit.Core's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.45.8 <!-- Release notes generated using configuration in .github/release.yml at v1.45.8 --> ## What's Changed ### Other Changes * fix(aspire): route CreateHttpClient through IHttpClientFactory by @thomhurst in thomhurst/TUnit#5957 ### Dependencies * chore(deps): update tunit to 1.45.0 by @thomhurst in thomhurst/TUnit#5949 * chore(deps): update dependency dompurify to v3.4.5 by @thomhurst in thomhurst/TUnit#5951 * chore(deps): update dependency microsoft.testing.extensions.codecoverage to 18.7.0 by @thomhurst in thomhurst/TUnit#5953 * chore(deps): update dependency coverlet.collector to 10.0.1 by @thomhurst in thomhurst/TUnit#5952 * chore(deps): update dependency polyfill to 10.6.0 by @thomhurst in thomhurst/TUnit#5955 * chore(deps): update dependency polyfill to 10.6.0 by @thomhurst in thomhurst/TUnit#5954 **Full Changelog**: thomhurst/TUnit@v1.45.0...v1.45.8 ## 1.45.0 <!-- Release notes generated using configuration in .github/release.yml at v1.45.0 --> ## What's Changed ### Other Changes * fix(generator): place CallerArgumentExpression before params in [GenerateAssertion] emit by @JohnVerheij in thomhurst/TUnit#5940 * fix(sourcegen): drop covariant TActual when [GenerateAssertion] method has its own type parameters by @JohnVerheij in thomhurst/TUnit#5935 * feat(assertions): add CancellationToken overload to WaitsFor and Eventually by @JohnVerheij in thomhurst/TUnit#5938 * fix(html-report): extract categories using MTP Key=name convention by @thomhurst in thomhurst/TUnit#5946 * feat(html-report): rewrite as split-pane design template by @thomhurst in thomhurst/TUnit#5947 ### Dependencies * chore(deps): update microsoft.testing to 2.2.3 by @thomhurst in thomhurst/TUnit#5927 * chore(deps): update mstest to 4.2.3 by @thomhurst in thomhurst/TUnit#5928 * chore(deps): update tunit to 1.44.39 by @thomhurst in thomhurst/TUnit#5929 * chore(deps): update aspire to 13.3.3 by @thomhurst in thomhurst/TUnit#5933 * chore(deps): update dependency dompurify to v3.4.4 by @thomhurst in thomhurst/TUnit#5944 * chore(deps): update dependency qs to v6.15.2 by @thomhurst in thomhurst/TUnit#5941 **Full Changelog**: thomhurst/TUnit@v1.44.39...v1.45.0 ## 1.44.39 <!-- Release notes generated using configuration in .github/release.yml at v1.44.39 --> ## What's Changed ### Other Changes * fix(tests): retry trx read to dodge MTP post-exit flush race on Windows by @thomhurst in thomhurst/TUnit#5888 * fix(pipeline): timeout + retry InstallPlaywrightModule so a hung download fails fast by @thomhurst in thomhurst/TUnit#5889 * fix(otel): require two consecutive idle windows in DrainAsync to catch in-transit POSTs by @thomhurst in thomhurst/TUnit#5890 * test(assertions): drop flaky wall-clock upper bound on WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5886 * fix(sourcegen): drop spurious ')' in MethodAssertionGenerator Task<bool> emit by @JohnVerheij in thomhurst/TUnit#5920 * fix(sourcegen): merge generic parameter lists in [AssertionExtension] emit by @JohnVerheij in thomhurst/TUnit#5921 * fix(aspnetcore): scope correlation processor per-factory to stop cross-factory tag leak by @thomhurst in thomhurst/TUnit#5891 * Changed FSharp.Core version to 10.1.300 by @licon4812 in thomhurst/TUnit#5909 * feat(mocks): add Mock.HttpClientFactory() helper by @thomhurst in thomhurst/TUnit#5894 * Harden WaitsFor timeout test by @thomhurst in thomhurst/TUnit#5926 * fix(sourcegen): emit `default` literal for value-type assertion parameters by @JohnVerheij in thomhurst/TUnit#5919 ### Dependencies * chore(deps): update dependency nunit to 4.6.0 by @thomhurst in thomhurst/TUnit#5826 * chore(deps): update tunit to 1.44.0 by @thomhurst in thomhurst/TUnit#5882 * chore(deps): update dependency mockolate to 3.2.0 by @thomhurst in thomhurst/TUnit#5892 * chore(deps): update dependency yaml to v2.9.0 by @thomhurst in thomhurst/TUnit#5887 * chore(deps): update dependency nuget.protocol to 7.6.0 by @thomhurst in thomhurst/TUnit#5897 * chore(deps): update dependency microsoft.entityframeworkcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5898 * chore(deps): update dependency microsoft.templateengine.authoring.cli to v10.0.300 by @thomhurst in thomhurst/TUnit#5899 * chore(deps): update microsoft.extensions by @thomhurst in thomhurst/TUnit#5905 * chore(deps): update microsoft.aspnetcore to 10.0.8 by @thomhurst in thomhurst/TUnit#5904 * chore(deps): update dependency microsoft.templateengine.authoring.templateverifier to 10.0.300 by @thomhurst in thomhurst/TUnit#5902 * chore(deps): update aspire to 13.3.1 by @thomhurst in thomhurst/TUnit#5900 * chore(deps): update dependency system.commandline to 2.0.8 by @thomhurst in thomhurst/TUnit#5903 * chore(deps): update dependency azure.storage.blobs to 12.28.0 by @thomhurst in thomhurst/TUnit#5910 * chore(deps): update dependency dotnet-sdk to v10.0.300 by @thomhurst in thomhurst/TUnit#5901 * chore(deps): update dependency stackexchange.redis to 2.13.1 by @thomhurst in thomhurst/TUnit#5906 * chore(deps): update aspire to 13.3.2 by @thomhurst in thomhurst/TUnit#5924 * chore(deps): bump mermaid from 11.12.2 to 11.15.0 in /docs by @dependabot[bot] in thomhurst/TUnit#5893 * chore(deps): update dependency streamjsonrpc to 2.24.92 by @thomhurst in thomhurst/TUnit#5915 * chore(deps): update dependency dompurify to v3.4.3 by @thomhurst in thomhurst/TUnit#5913 * chore(deps): update microsoft.build to 18.6.3 by @thomhurst in thomhurst/TUnit#5914 **Full Changelog**: thomhurst/TUnit@v1.44.0...v1.44.39 Commits viewable in [compare view](thomhurst/TUnit@v1.44.0...v1.45.8). </details> [](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 this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Description
Both source generators in
TUnit.Assertions.SourceGeneratorcarried a near-duplicate privateFormatDefaultValuehelper, and both returned"null"when the parameter's Roslyn-reported default-value constant wasnull. For a non-nullable value-type parameter declared with thedefaultliteral (e.g.CancellationToken ct = default), Roslyn reports the default asnull, so the generator emitted= null. That literal is invalid as the default for a value type and produces CS1750.Fix: when the constant is
null, branch on the parameter type. Non-nullable value types emit the baredefaultliteral (the compiler infers the target type from the parameter, matching the user's original declaration). Reference types andNullable<T>continue to emitnull.Unified the two private helpers into a single shared
DefaultValueFormatter.FormatDefaultValue(new fileGenerators/DefaultValueFormatter.cs, sibling to the existingCovarianceHelper). The helper takes abool useFullyQualifiedEnumNameparameter so each generator preserves its intentional enum-emit style:MethodAssertionGeneratorpassestrue(emitsNamespace.Enum.Memberto match its fully-qualified-everywhere style), andAssertionExtensionGeneratorpassesfalse(emitsEnum.Memberbecause it relies onusingdirectives at the top of its generated files). Both generators now share a single source of truth for default-value emit while keeping the call-site-specific behaviour explicit.Test coverage:
ValueTypeDefaultParametertest onMethodAssertionGeneratorTests([GenerateAssertion]path).ValueTypeDefaultParametertest onAssertionExtensionGeneratorTests([AssertionExtension]path).token = default,) and run a structural compile-clean gate.CompileChecker.AssertNoErrors(generatedFiles)test helper (sibling toReferencesHelper) so the compile-clean assertion isn't duplicated across the two new tests.Related Issue
Fixes #5917
Type of Change
Checklist
Required
TUnit-Specific Requirements
TUnit.Core.SourceGenerator)TUnit.Engine)TUnit.Core.SourceGenerator.Testsand/orTUnit.PublicAPItests.received.txtfiles and accepted them as.verified.txt.verified.txtfiles[DynamicallyAccessedMembers]annotationsdotnet publish -p:PublishAot=trueTesting
dotnet test)Additional Notes
.claude/docs/mandatory-rules.mdRule 1, dual-mode does not apply to assertion library changes. This PR fixes an emit defect inTUnit.Assertions.SourceGeneratoronly.useFullyQualifiedEnumNameparameter encodes the previously-duplicated semantic difference between the two generators, so neither generator's output for any existing case changes.CompileCheckertest helper: on the net472 leg of CI, the test project'sPolyfillassembly marksCallerArgumentExpressionAttributeasinternal, producing a CS0122 ('inaccessible due to its protection level') false positive when Roslyn compiles the generator's output through the test reference set. Conditional#if NETFRAMEWORKfilter pre-empts this in the helper. On modern TFMs the BCL attribute is public, so CS0122 (if it ever appears) remains a real failure signal. All four TFMs (net472 + net8.0 + net9.0 + net10.0) verified green locally before push.