question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

throwWithRegexMessage

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CaptnCodrcommented, Oct 19, 2021

Diffract can show you a diff of your F# types etc., see: https://github.com/d-edge/Diffract

1reaction
sergey-tihoncommented, Jun 25, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I check if a function throws an error which ...
1 Answer 1 · regular expression: error message matches the pattern · string: error message includes the substring · error object: error message...
Read more >
How to customize Error Message thrown by validateRegex?
I have the following code, which is throwing a "Regex Pattern not matched" message. I need for it to show a custom message....
Read more >
Allow toThrow() matcher to match a regular expression #343
Passing a regex to 'toThrowError' checks that the thrown error message matches the regex. Passing a regex to 'toThrow' will check that what...
Read more >
How to use regular expressions, handle exceptions, and ...
Write code that creates and throws an Error object. • Write code that uses a try-catch ... Describe how a regular expression can...
Read more >
Validation Regex throw error while submitting the form.
I have created one Validation regex (which is accepting decimal values) or add it in variable , and it's accepting the decimal value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found