throwWithRegexMessage
I find myself using regex to match dynamic errors, could this be added?
let throwWithRegexMessage (m:string) (t:System.Type) = CustomMatcher<obj>(sprintf "%s \"%s\"" (string t) m,
fun f -> match f with
| :? (unit -> unit) as testFunc ->
try
testFunc()
false
with
| ex -> ex.GetType() = t && Regex.IsMatch (ex.Message, m)
| _ -> false )
(fun () -> AsyncWrite2 (streamName) (int64(EventStore.ClientAPI.ExpectedVersion.Any)) (event)
|> Async.RunSynchronously
|> ignore)
|> should (throwWithRegexMessage @"EventStoreConnection 'ES-.{36}' is not active.") typeof<System.AggregateException>
Maybe there could be a better message I can make the PR if worth including.
Also, if throwWithMessage fails, then it prints:
Expected: System.AggregateException "EventStoreConnection 'ES-.{36}' is not active."
Actual: was ProgramTest+try async write 2@49
Would expect Actual to have the same form as Expected instead the function id
@sergey-tihon Suggestions or ideas?
could this be added?
I do not mind if throwWithRegexMessage will be added with tests for all framework
Would expect Actual to have the same form as Expected instead the function id
This is quite tricky, xUnit and MSUnit mismatch description builder rely on .ToString() that is defined for F# types in a way now very pleasant for our use case (would be way more useful to use %A)
I am not sure that there is a short of simple fix for this, that does not break error messages for other operators.
that is defined for F# types in a way now very pleasant for our use case (would be way more useful to use
%A)
Then maybe I'm not using it correctly? because idk how to work with Actual: was ProgramTest+try async write 2@49, I expected something more like this:

I am not aware about such diffs for .net test frameworks. I believe it cannot be added to DSL library (like FsUnit), It should be supposrted by framework (xUnit, NUnit, MSUnit) and runner (console runner) that will provide colorful output.
AFAIK, Expecto support string diff (but for a git-like diff for objects) https://github.com/haf/expecto/releases/tag/v2.2.0
Diffract can show you a diff of your F# types etc., see: https://github.com/d-edge/Diffract