Skip to content

Instantly share code, notes, and snippets.

@bryanedds
Created July 12, 2016 16:35
Show Gist options
  • Save bryanedds/5c031b212a63622d6ddb140b4b01f548 to your computer and use it in GitHub Desktop.
Save bryanedds/5c031b212a63622d6ddb140b4b01f548 to your computer and use it in GitHub Desktop.
There, fuck 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