Repository navigation
test: assertions that unwrap options, value options and results - #44
Merged
Merged
Conversation
Extend the `Assert` class of MSTest with members for the F# option, value option and result types, so that a test unwraps a value in one expression instead of matching on it and failing by hand: * `WantSome`, `WantValueSome`, `WantOk` and `WantError` return the unwrapped value or fail the test with the message of the caller; the two result assertions add the error or the value to it. * `IsSome`, `IsNone`, `IsValueSome`, `IsValueNone`, `IsOk` and `IsError` check the case and discard the value. * `IsDefaultOf`, `OkEquals` and `ErrorEquals` compare a value with the default of its type or with the content of a result. MSTest takes the message of a failure as a text that is not null, while an optional message that the caller omitted is null, so the assertions that fail pass an empty text then. `AssertExtensionsTests` checks that each member passes on the expected case and fails with its message on the other one; a test category names the area. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Declare `AssertExtensions` as the root module of `Assert.fs`, as the other files of the tests and the library that hold one module do. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…sertExtensions` The tests that took the value out of an option or a value option by hand, or checked its case by hand, use the assertions of `AssertExtensions` now: * The expected elements of `replace` and `replaceWith` of `FlatList` and `FlatListBuilder` come from `Assert.WantValueSome` where they came from `ValueOption.get`, so test data without a value to replace fails the test with a message. * `FlatListOracles.messageDetail` fails the test, where it threw `InvalidOperationException`, when the action does not throw. * `tryTail` of the sequence-like access contract and of the `Option` namespace tests asserts the case and takes the tail in one expression with `Assert.IsValueNone`, `Assert.WantValueSome` and `Assert.WantSome`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
that referenced
this pull request
Oct 20, 2026
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Adds
Assert.fsto the test project: extension members of the MSTestAssertclass for F#option,voptionandResultvalues.AssertExtensionsis the root module of the file and opens automatically in the tests.WantSome,WantValueSome,WantOkandWantErrorreturn the unwrapped value or fail the test with the message of the caller.WantOkandWantErroradd the error or the value to the message. A test goes on with the value in one expression, instead of matching on the case and failing by hand.IsSome,IsNone,IsValueSome,IsValueNone,IsOkandIsErrorcheck the case and discard the value.IsDefaultOf,OkEqualsandErrorEqualscompare a value with the default of its type, or the content of a result with an expected value.The tests that are already in
mainuse the assertions where they took the value out of an option by hand:replaceandreplaceWithofFlatListandFlatListBuildercome fromWantValueSomewhere they came fromValueOption.get.FlatListOracles.messageDetailfails the test, where it threwInvalidOperationException, when the action does not throw.tryTailof the sequence-like access contract and of theOptionnamespace tests asserts the case and takes the tail in one expression.Types of changes
What types of changes does your code introduce to FSharp.Collections.Immutable?
Put an
xin the boxes that applyA change of the test project only: no code of the library changes.
Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
AssertExtensionsTestshas 18 tests. It checks each member on the case that it accepts and on the case that it rejects, and a failure must carry the message of the caller. Three deliberate defects each made tests fail: anIsNonethat never fails, aWantOkthat drops the message and anOkEqualsthat never compares. The converted tests keep their expectations, so the number of tests stays the same.An optional message that the caller leaves out is
null, whileAssert.Failtakes a text that is not null, so the assertions that fail pass an empty text then. The parameter staysstring | null, as an F# optional argument of a reference type.The test category
Assert extensionsnames the area, as the rules of the test categories ask.The open pull requests that unwrap options in their tests, such as #31, can take
WantSomeandWantValueSomefrom here instead of local helpers.🤖 Generated with Claude Code