perf: use static Task in MethodAssertionGenerator generated code#4543
perf: use static Task in MethodAssertionGenerator generated code#4543thomhurst merged 1 commit intothomhurst:mainfrom
Task in MethodAssertionGenerator generated code#4543Conversation
SummaryOptimizes generated code by caching the successful assertion result task in a static field. Critical IssuesMissing snapshot test updates - The PR modifies source generator output but does not include updated verified.txt files. TUnit CRITICAL RULE 2 requires snapshot tests to be updated when source generator output changes. The generated code will now include a static field and changed return logic affecting MethodAssertionGeneratorTests snapshot files. Required: Run snapshot tests, review changes, update verified.txt files and commit them. SuggestionsThe optimization follows TUnit Performance First principle. Caching the success case is good. The failure case correctly allocates new Task for unique error messages. VerdictREQUEST CHANGES - Missing required snapshot test updates |
Improve generated code by
MethodAssertionGeneratorto sometimes emitprivate static readonly Task<AssertionResult> _passedTask = Task.FromResult(AssertionResult.Passed);and return it.protected static readonly Task<AssertionResult> _passedTaskinherited fromAssertion<T>, but I didn't want to change the existing api.Again I'll ask you to update the snapshot tests, I've rebased and I still get the Sourcy error 😅
Before
After