Skip to content

Fix Assert.That to not evaluate expression twice - #6699

Closed
Evangelink wants to merge 8 commits into
mainfrom
dev/amauryleve/assert-that
Closed

Fix Assert.That to not evaluate expression twice#6699
Evangelink wants to merge 8 commits into
mainfrom
dev/amauryleve/assert-that

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #6690

Comment thread src/TestFramework/TestFramework/Assertions/Assert.That.cs Outdated
Comment thread src/TestFramework/TestFramework/Assertions/Assert.That.cs Outdated
Comment thread src/TestFramework/TestFramework/Assertions/Assert.That.cs Outdated
Comment thread test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs Outdated
# Conflicts:
#	src/TestFramework/TestFramework/Resources/FrameworkMessages.resx
#	test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs
@Evangelink
Evangelink enabled auto-merge (squash) November 25, 2025 13:28
@nohwnd
nohwnd disabled auto-merge November 25, 2025 16:35
@nohwnd

nohwnd commented Nov 25, 2025

Copy link
Copy Markdown
Member

disabled automerge, I want to do some more testing, but now don't have any inspiration. So plese wait for me a day or 2.

@nohwnd

nohwnd commented Nov 25, 2025

Copy link
Copy Markdown
Member

https://github.com/microsoft/testfx/compare/dev/amauryleve/assert-that...assert-that+objects?expand=1

When the method returns objects they will get merged in the cache, and only 1 instance is returned. Making it impossible to see what was returned.

It probably needs to serialize the objects for the assertion as it goes, adding overhead for passing assertions, but also snapshotting the values better.

Also this would avoid issues with the object overriding equals / gethash, when we grab it from the cache?

image

The linked code returns 2 instances that have different data when they are evaluated, but I cannot see that from the output.

@Evangelink Evangelink closed this Dec 19, 2025
Evangelink added a commit that referenced this pull request May 19, 2026
)

Co-authored-by: Jakub Jareš <me@jakubjares.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Amaury Levé <Evangelink@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assert.That evaluates expression twice

3 participants