@@ -36,37 +36,41 @@ type ItBuilder(name: string) =
3636let it name = ItBuilder name
3737let pending name = It.Pending name
3838
39- type DescribeStep =
39+ type Step =
4040 | It of It
4141 | LogStatement of LogLevel
4242
4343type Describe = {
4444 Name: string
45- Steps: DescribeStep list
45+ Steps: Step list
4646 Each: EachFunction list
4747 Children: Describe list
4848}
4949with
50- static member Empty name = {
50+ member this.TotalCount =
51+ let rec countSteps ( describe : Describe ) =
52+ describe.Children.Length + ( describe.Children |> List.map countSteps |> List.sum)
53+ countSteps this
54+ static member New name = {
5155 Name = name
5256 Steps = []
5357 Each = []
5458 Children = []
5559 }
5660
5761type DescribeBuilder ( name ) =
58- member _.Zero () = Describe.Empty name
62+ member _.Zero () = Describe.New name
5963 member _.Yield ( each : EachFunction ) =
60- { Describe.Empty name with Each = [ each] }
64+ { Describe.New name with Each = [ each] }
6165 member _.Yield ( tc : It ) =
62- { Describe.Empty name with Steps = [ It tc] }
66+ { Describe.New name with Steps = [ It tc] }
6367 member _.Yield ( log : LogLevel ) =
64- { Describe.Empty name with Steps = [ LogStatement log] }
68+ { Describe.New name with Steps = [ LogStatement log] }
6569 member _.Yield ( describe : Describe ) =
66- { Describe.Empty name with Children = [ describe] }
70+ { Describe.New name with Children = [ describe] }
6771 member _.Combine ( a , b ) =
6872 {
69- Describe.Empty name
73+ Describe.New name
7074 with
7175 Each = a.Each @ b.Each
7276 Children = a.Children @ b.Children
@@ -77,7 +81,7 @@ type DescribeBuilder(name) =
7781 let sb =
7882 sequence
7983 |> Seq.map body
80- |> Seq.fold ( fun s a -> this.Combine( s, a)) ( Describe.Empty name)
84+ |> Seq.fold ( fun s a -> this.Combine( s, a)) ( Describe.New name)
8185 sb
8286 member _.Run ( f : Describe ) = f
8387
@@ -99,6 +103,7 @@ type TestResult =
99103 | Pending of Path * string
100104
101105type ITestReporter =
106+ abstract Begin : totalCount : int -> unit
102107 abstract BeginSuite : name : string * path : Path -> unit
103108 abstract ReportResult : result : TestResult * path : Path -> unit
104109 abstract EndSuite : name : string * path : Path -> unit
@@ -124,6 +129,9 @@ module Reporters =
124129 ConsoleReporter( " ✅" , " ❌" , " ❔" , " " )
125130
126131 interface ITestReporter with
132+ member _.Begin ( totalCount ) =
133+ printfn $" Running %d {totalCount} tests..."
134+ sw.Restart()
127135 member _.BeginSuite ( name , path ) =
128136 let indent = indent path
129137 printfn $" %s {indent}{AnsiColours.green}{name}{AnsiColours.reset}"
@@ -165,6 +173,32 @@ module Reporters =
165173 printfn $" Summary: {passedCount} passed, {failedCount} failed, {pendingCount} pending"
166174 printfn $" Total time: %s {sw.Elapsed.ToString()}"
167175
176+ type TapReporter () =
177+ interface ITestReporter with
178+ member this.Begin ( totalCount : int ): unit =
179+ printfn " TAP version 14"
180+ printfn " 1..%d " totalCount
181+ member this.BeginSuite ( name : string , path : Path ): unit =
182+ ()
183+ member this.Debug ( message : string , path : Path ): unit =
184+ ()
185+ member this.End ( arg1 : TestResult list ): unit = ()
186+ member this.EndSuite ( name : string , path : Path ): unit =
187+ printfn " "
188+ member this.Info ( message : string , path : Path ): unit =
189+ ()
190+ member this.ReportResult ( result : TestResult , path : Path ): unit =
191+ match result with
192+ | Passed (_, name) ->
193+ printf " ok %s \n " name
194+ | Failed (_, name, ex) ->
195+ printf
196+ " not ok %s \n ---\n message: %s \n severity: fail\n ...\n "
197+ name
198+ ex.Message
199+ | Pending (_, name) ->
200+ printf " ok %s # SKIP\n " name
201+
168202type TestContext = {
169203 Path: Path
170204 ParentBeforeHooks: HookFunction list
@@ -173,7 +207,7 @@ type TestContext = {
173207 Log: string -> unit
174208}
175209with
176- static member Empty = {
210+ static member New = {
177211 Path = Path []
178212 ParentBeforeHooks = []
179213 ParentAfterHooks = []
@@ -251,11 +285,12 @@ let rec private doRunTestSuite (suite: Describe) (context: TestContext): TestRes
251285 allResults
252286
253287let runTestSuiteWithContext ( sb : Describe ) ( context : TestContext ) =
288+ context.Reporter.Begin( sb.TotalCount)
254289 let testResults = doRunTestSuite sb { context with Path = Path ( context.Path.Value @ [ sb.Name]) }
255290 context.Reporter.EndSuite( sb.Name, context.Path)
256291 context.Reporter.End testResults
257292
258- let runTestSuite ( describe : Describe ) = runTestSuiteWithContext describe TestContext.Empty
293+ let runTestSuite ( describe : Describe ) = runTestSuiteWithContext describe TestContext.New
259294
260295[<AutoOpen>]
261296module Constraints =
0 commit comments