Skip to content

Instantly share code, notes, and snippets.

@jeroldhaas
Forked from bryanedds/Assert.fs
Created July 12, 2016 16:38
Show Gist options
  • Save jeroldhaas/c24659126f6819789f2481fdeb7f7d8e to your computer and use it in GitHub Desktop.
Save jeroldhaas/c24659126f6819789f2481fdeb7f7d8e to your computer and use it in GitHub Desktop.
There, screw nunit.
exception AssertionException of string
module Assert =
let isTrue value =
if not value then
raise (AssertionException "Expected true but got false.")
let isFalse value =
if value then
raise (AssertionException "Expected false but got true.")
let inline areEqual expected actual =
if expected <> actual then
raise (AssertionException ("Expected value '" + string expected + "' but got '" + string actual + "'."))
let tests1 (ty : Type) =
let methods = ty.GetMethods (BindingFlags.Instance ||| BindingFlags.Public)
let instance = Activator.CreateInstance(ty, [||])
for meth in methods do
try meth.Invoke(instance, [||]) |> ignore
with
| :? AssertionException as exn -> Console.WriteLine ("Test method '" + ty.FullName + "." + meth.Name + "' failed due to: " + string exn)
| exn -> Console.WriteLine ("Test method '" + ty.FullName + "." + meth.Name + "' unexpectedly exited with exception: " + string exn)
let tests<'t> () =
tests1 (typeof<'t>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment