From 460f82d4672d160eb5d54ef08c015164e4655c94 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Mon, 18 May 2015 21:51:17 -0500 Subject: [PATCH] Fix for #195 --- src/canopy/runner.fs | 31 +++++++++++++++++++++++-------- src/canopy/types.fs | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index 1f80a72b..a9d7f22c 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -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 @@ -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 diff --git a/src/canopy/types.fs b/src/canopy/types.fs index 4c4c8c64..70e52941 100644 --- a/src/canopy/types.fs +++ b/src/canopy/types.fs @@ -62,6 +62,7 @@ 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 @@ -69,5 +70,6 @@ type suite () = class 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 \ No newline at end of file