Skip to content

Instantly share code, notes, and snippets.

@t0yv0
Created August 25, 2011 19:48
Show Gist options
  • Select an option

  • Save t0yv0/1171654 to your computer and use it in GitHub Desktop.

Select an option

Save t0yv0/1171654 to your computer and use it in GitHub Desktop.
let mutable section = ""
let mutable status = 0
let mutable count = 0
exception Fail of string
let run (name: string) test =
try
test ()
count <- count + 1
with
| Fail reason ->
status <- 1
stderr.WriteLine("FAIL: {0}.{1} -- {2}", section, name, reason)
| e ->
status <- 1
stderr.WriteLine("FAIL: {0}.{1}", section, name)
stderr.WriteLine(e)
type Test(name: string) =
member this.Delay(f : unit -> unit) = run name f
member this.Zero() = ()
let Section name =
section <- name
let Throws<'T when 'T :> exn> f =
try
f ()
raise (Fail (sprintf "Does not throw: %O" typeof<'T>))
with
| :? 'T ->
()
let ( =? ) a b =
if a <> b then
raise (Fail (sprintf "Expected %A and got %A." a b))
let ( <>? ) a b =
if a = b then
raise (Fail (sprintf "Unexpected %A." a))
let runTests () =
Section "Arithmetic"
Test "addition" {
1 + 1 =? 2
1 + 0 =? 0
}
[<EntryPoint>]
let main args =
runTests ()
if status = 0 then
stdout.WriteLine("OK, {0} tests passed.", count)
status
<Target Name="AfterBuild">
<Exec Command="$(TargetPath)" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment