-
-
Save dmitry-a-morozov/f6ca95f1af3ea144495b to your computer and use it in GitHub Desktop.
Descriptive assertions using new F# 4.0 feature
This file contains 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
open FSharp.Quotations | |
open System.Diagnostics | |
open System | |
type Debug with | |
[<Conditional("DEBUG")>] | |
static member AssertThat([<ReflectedDefinition(true)>] condition: Expr<bool>) = | |
match condition with | |
| Patterns.WithValue(value, t, expr) when t = typeof<bool> -> | |
let message = string expr //how do I get unparsed F# here? | |
Debug.Assert(unbox value, message) | |
| _ -> invalidArg "condition" (sprintf "Unexpected expressions: %A" condition) | |
Debug.AssertThat(42 = 42) | |
Debug.AssertThat(42 = 43) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
something like this (compile with
--quotations-debug+
):