Skip to content

Commit

Permalink
Fix for #195
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed May 19, 2015
1 parent 3ebcab4 commit 460f82d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@ let context c =
let s = new suite()
s.Context <- c
suites <- suites @ [s]

let ( &&& ) description f = (last suites).Tests <- (last suites).Tests @ [Test(description, f, (last suites).Tests.Length + 1)]
let private incrementLastTestSuite () =
let lastSuite = last suites
lastSuite.TotalTestsCount <- lastSuite.TotalTestsCount + 1
lastSuite
let ( &&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Tests <- lastSuite.Tests @ [Test(description, f, lastSuite.TotalTestsCount)]
let test f = null &&& f
let ntest description f = description &&& f
let ( &&&& ) description f = (last suites).Wips <- (last suites).Wips @ [Test(description, f, (last suites).Wips.Length + 1)]
let ( &&&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Wips <- lastSuite.Wips @ [Test(description, f, lastSuite.TotalTestsCount)]
let wip f = null &&&& f
let many count f = [1 .. count] |> List.iter (fun _ -> (last suites).Manys <- (last suites).Manys @ [Test(null, f, (last suites).Manys.Length + 1)])
let ( &&! ) description f = (last suites).Tests <- (last suites).Tests @ [Test(description, skipped, (last suites).Tests.Length + 1)]
let many count f =
let lastSuite = incrementLastTestSuite()
[1 .. count] |> List.iter (fun _ -> lastSuite.Manys <- lastSuite.Manys @ [Test(null, f, lastSuite.TotalTestsCount)])
let ( &&! ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Tests <- lastSuite.Tests @ [Test(description, skipped, lastSuite.TotalTestsCount)]
let xtest f = null &&! f

let ( &&&&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Always <- lastSuite.Always @ [Test(description, f, lastSuite.TotalTestsCount)]
let mutable passedCount = 0
let mutable failedCount = 0
let mutable contextFailed = false
Expand Down Expand Up @@ -114,12 +127,14 @@ let run () =
s.Once ()
if s.Wips.IsEmpty = false then
wipTest <- true
s.Wips |> List.iter (fun w -> runtest s w)
let tests = s.Wips @ s.Always |> List.sortBy (fun t -> t.Number)
tests |> List.iter (fun w -> runtest s w)
wipTest <- false
else if s.Manys.IsEmpty = false then
s.Manys |> List.iter (fun m -> runtest s m)
else
s.Tests |> List.iter (fun t -> runtest s t)
let tests = s.Tests @ s.Always |> List.sortBy (fun t -> t.Number)
tests |> List.iter (fun t -> runtest s t)
s.Lastly ()
with
| ex -> failSuite ex s
Expand Down
2 changes: 2 additions & 0 deletions src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ type Test (description: string, func : (unit -> unit), number : int) =

type suite () = class
member val Context : string = null with get, set
member val TotalTestsCount : int = 0 with get, set
member val Once = fun () -> () with get, set
member val Before = fun () -> () with get, set
member val After = fun () -> () with get, set
member val Lastly = fun () -> () with get, set
member val Tests : Test list = [] with get, set
member val Wips : Test list = [] with get, set
member val Manys : Test list = [] with get, set
member val Always : Test list = [] with get, set
member val IsParallel = false with get, set
end

0 comments on commit 460f82d

Please sign in to comment.