From a9612878edb9bf71cdf446d15e3213474e158ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lud=C4=9Bk=20Cakl?= Date: Wed, 21 Jan 2015 14:20:28 +0100 Subject: [PATCH 1/2] Added suport for TeamCity parallel reporting (parameter flowId - https://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-MessageFlowId ) --- src/canopy/reporters.fs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/canopy/reporters.fs b/src/canopy/reporters.fs index 4fa9a266..a9607237 100644 --- a/src/canopy/reporters.fs +++ b/src/canopy/reporters.fs @@ -97,6 +97,9 @@ type ConsoleReporter() = member this.skip () = () type TeamCityReporter() = + + let flowId = System.Guid.NewGuid().ToString() + let consoleReporter : IReporter = new ConsoleReporter() :> IReporter let tcFriendlyMessage (message : string) = let message = message.Replace("|", "||") @@ -109,6 +112,10 @@ type TeamCityReporter() = let message = message.Replace("]", "|]") message + let teamcityReport text = + let temcityReport = sprintf "##teamcity[%s flowId='%s']" text flowId + consoleReporter.describe temcityReport + interface IReporter with member this.pass () = consoleReporter.pass () @@ -117,23 +124,22 @@ type TeamCityReporter() = if not (Array.isEmpty ss) then image <- String.Format("canopy-image({0})", Convert.ToBase64String(ss)) - consoleReporter.describe (String.Format("##teamcity[testFailed name='{0}' message='{1}' details='{3}']", - (tcFriendlyMessage id), - (tcFriendlyMessage ex.Message), - (tcFriendlyMessage ex.StackTrace), - (tcFriendlyMessage image))) + teamcityReport (sprintf "testFailed name='%s' message='%s' details='%s'" + (tcFriendlyMessage id) + (tcFriendlyMessage ex.Message) + (tcFriendlyMessage image)) consoleReporter.fail ex id ss member this.describe d = - consoleReporter.describe (String.Format("##teamcity[message text='{0}' status='NORMAL']", (tcFriendlyMessage d))) + teamcityReport (sprintf "message text='%s' status='NORMAL'" (tcFriendlyMessage d)) consoleReporter.describe d member this.contextStart c = - consoleReporter.describe (String.Format("##teamcity[testSuiteStarted name='{0}']", (tcFriendlyMessage c))) + teamcityReport (sprintf "testSuiteStarted name='%s'" (tcFriendlyMessage c)) consoleReporter.contextStart c member this.contextEnd c = - consoleReporter.describe (String.Format("##teamcity[testSuiteFinished name='{0}']", (tcFriendlyMessage c))) + teamcityReport (sprintf "testSuiteFinished name='%s'" (tcFriendlyMessage c)) consoleReporter.contextEnd c member this.summary minutes seconds passed failed = consoleReporter.summary minutes seconds passed failed @@ -142,9 +148,9 @@ type TeamCityReporter() = member this.suggestSelectors selector suggestions = consoleReporter.suggestSelectors selector suggestions - member this.testStart id = consoleReporter.describe (String.Format("##teamcity[testStarted name='{0}']", (tcFriendlyMessage id))) + member this.testStart id = teamcityReport (sprintf "testStarted name='%s'" (tcFriendlyMessage id)) - member this.testEnd id = consoleReporter.describe (String.Format("##teamcity[testFinished name='{0}']", (tcFriendlyMessage id))) + member this.testEnd id = teamcityReport (sprintf "testFinished name='%s'" (tcFriendlyMessage id)) member this.quit () = () From 3f651141b0098011d857db48dcad2fbc92ecbd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lud=C4=9Bk=20Cakl?= Date: Wed, 21 Jan 2015 14:23:13 +0100 Subject: [PATCH 2/2] fix for #178 (https://github.com/lefthandedgoat/canopy/issues/178) --- src/canopy/runner.fs | 42 ++++++++++++++++++++++++++---------------- src/canopy/types.fs | 1 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index b045d4a3..47e0f40f 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -60,7 +60,14 @@ let fail (ex : Exception) id = //Fail during error report (likely OpenQA.Selenium.WebDriverException.WebDriverTimeoutException ). // Don't fail the runner itself, but report it. reporter.write (sprintf "Error during fail reporting: %s" (failExc.ToString())) - reporter.fail ex id null + reporter.fail ex id Array.empty + +let failSuite (ex: Exception) (suite : suite) = + let reportFailedTest (ex: Exception) (test : Test) = + reporter.testStart test.Id + fail ex test.Id + reporter.testEnd test.Id + suite.Tests |> List.iter (fun test -> reportFailedTest ex test) let run () = reporter.suiteBegin() @@ -68,10 +75,9 @@ let run () = stopWatch.Start() let runtest (suite : suite) (test : Test) = - if failed = false then - let desc = if test.Description = null then (String.Format("Test #{0}", test.Number)) else test.Description + if failed = false then try - reporter.testStart desc + reporter.testStart test.Id if System.Object.ReferenceEquals(test.Func, todo) then reporter.todo () else if System.Object.ReferenceEquals(test.Func, skipped) then @@ -83,8 +89,8 @@ let run () = pass() with | ex when failureMessage <> null && failureMessage = ex.Message -> pass() - | ex -> fail ex desc - reporter.testEnd desc + | ex -> fail ex test.Id + reporter.testEnd test.Id failureMessage <- null @@ -104,16 +110,20 @@ let run () = if failed = false then contextFailed <- false if s.Context <> null then reporter.contextStart s.Context - s.Once () - if s.Wips.IsEmpty = false then - wipTest <- true - s.Wips |> 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) - s.Lastly () + try + s.Once () + if s.Wips.IsEmpty = false then + wipTest <- true + s.Wips |> 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) + s.Lastly () + with + | ex -> failSuite ex s + if contextFailed = true then failedContexts <- failedContexts @ [s.Context] if s.Context <> null then reporter.contextEnd s.Context ) diff --git a/src/canopy/types.fs b/src/canopy/types.fs index 157790b9..6adb41ef 100644 --- a/src/canopy/types.fs +++ b/src/canopy/types.fs @@ -53,6 +53,7 @@ type Test (description: string, func : (unit -> unit), number : int) = member x.Description = description member x.Func = func member x.Number = number + member x.Id = if description = null then (String.Format("Test #{0}", number)) else description type suite () = class member val Context : string = null with get, set