Skip to content

Commit

Permalink
Merge pull request #180 from ludekcakl/master
Browse files Browse the repository at this point in the history
fix for #176 + new feature
  • Loading branch information
lefthandedgoat committed Jan 22, 2015
2 parents 5229a45 + 3f65114 commit 98f9dff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
26 changes: 16 additions & 10 deletions src/canopy/reporters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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("|", "||")
Expand All @@ -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 ()
Expand All @@ -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
Expand All @@ -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 () = ()
Expand Down
42 changes: 26 additions & 16 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,24 @@ 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()
let stopWatch = new Diagnostics.Stopwatch()
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
Expand All @@ -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

Expand All @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98f9dff

Please sign in to comment.