Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Jan 23, 2026

Improve generated code by MethodAssertionGenerator to sometimes emit private static readonly Task<AssertionResult> _passedTask = Task.FromResult(AssertionResult.Passed); and return it.

  • This could be a protected static readonly Task<AssertionResult> _passedTask inherited from Assertion<T>, but I didn't want to change the existing api.
  • It's been a while since I've worked on a source generator, but could this one use caching?

Again I'll ask you to update the snapshot tests, I've rebased and I still get the Sourcy error 😅

Before

image

After

image

@thomhurst
Copy link
Owner

Summary

Optimizes generated code by caching the successful assertion result task in a static field.

Critical Issues

Missing 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.

Suggestions

The optimization follows TUnit Performance First principle. Caching the success case is good. The failure case correctly allocates new Task for unique error messages.

Verdict

REQUEST CHANGES - Missing required snapshot test updates

@thomhurst thomhurst merged commit 142292c into thomhurst:main Jan 25, 2026
9 of 10 checks passed
This was referenced Jan 26, 2026
This was referenced Jan 26, 2026
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.

2 participants