Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diff support for teamcity reporter #136

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions src/Test/Spec/Reporter/TeamCity.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ module Test.Spec.Reporter.TeamCity (teamcityReporter, teamcity) where
import Prelude

import Control.Monad.State (get, modify)
import Data.Array (intercalate) as Array
import Data.Foldable (for_)
import Data.Int (trunc)
import Data.Map.Internal as Map
import Data.Maybe (Maybe, fromMaybe)
import Data.Newtype (unwrap)
import Data.String.Regex (replace') as Regex
import Data.String.Regex.Flags (global) as Regex
import Data.String.Regex.Unsafe (unsafeRegex) as Regex
import Data.String.Pattern (Pattern(Pattern), Replacement(Replacement))
import Data.Time.Duration (Milliseconds(..))
import Effect.Exception (Error)
import Test.Spec.Console (tellLn)
import Test.Spec.Reporter.Base (defaultReporter)
import Test.Spec.Result (Result(..))
import Test.Spec.Runner (Reporter)
import Test.Spec.Runner.Event (Event(..)) as Event
import Test.Spec.Tree (Path, parentSuite)
import Data.Array (intercalate) as Array
import Effect.Exception (message, stack) as Error
import Test.Spec.Runner.Event (Event(..)) as Event
import Data.Map.Internal as Map
import Data.String.Regex (replace') as Regex
import Data.String.Regex.Flags (global) as Regex
import Data.String.Regex.Unsafe (unsafeRegex) as Regex
import Data.String.CodeUnits (contains, drop, dropRight, dropWhile, take, takeWhile) as String
import Data.String.Common (replaceAll) as String

escape :: String -> String
escape = Regex.replace'
Expand Down Expand Up @@ -71,8 +76,43 @@ testFinished = teamcity' "" "testFinished"
testFinishedIn :: WithDuration -> String
testFinishedIn d = teamcity' ("duration" := (show $ trunc d.duration)) "testFinished" d

testFailed :: WithMessage -> String
testFailed d = teamcity' ("message" := d.message) "testFailed" d
testFailed :: WithMessage -> Error -> String
testFailed d e =
let
message = Error.message e
isEquals = String.contains (Pattern "≠") message
in
if isEquals then
let
readString string = string
# String.replaceAll (Pattern "\\n") (Replacement "\n")
# String.drop 1
# String.dropRight 1
read s =
if String.take 1 s == "\"" then readString s
else s

expected = message
# String.takeWhile (_ /= '≠')
# String.dropRight 1
# read

actual = message
# String.dropWhile (_ /= '≠')
# String.drop 2
# String.replaceAll (Pattern "\\n") (Replacement "\n")
# read
in
teamcity'
( "type" := "comparisonFailure"
<> "details" := (Error.stack e # fromMaybe "")
<> "message" := message
<> "expected" := expected
<> "actual" := actual
)
"testFailed"
d
else teamcity' ("message" := d.message) "testFailed" d

type ServiceMessage x =
{ name :: String
Expand Down Expand Up @@ -131,7 +171,7 @@ teamcityReporter = defaultReporter Map.empty case _ of
)
Event.TestEnd path name (Failure error) -> do
let attributes = serviceMessage name path # withMessage (show error)
tellLn $ testFailed attributes
tellLn $ testFailed attributes error
tellLn $ testFinished attributes
Event.End _ -> pure unit
Event.Start count -> tellLn $ testCount count