Skip to content
37 changes: 36 additions & 1 deletion src/ElmTestRunner/Failure.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Json.Encode as Encode
import Test.Runner.Failure exposing (InvalidReason(..), Reason(..))


{-| Type resulting of calling `Test.Runner.getFailureReason` on a test `Expectation`.
{-| Type resulting of calling the old `Test.Runner.getFailureReason` on a test `Expectation`.
-}
type alias Failure =
{ given : Maybe String
Expand Down Expand Up @@ -50,6 +50,12 @@ encode =
-- }
-- | TODO
-- | Invalid InvalidReason
-- | Multiple
-- (List
-- { description : String
-- , reason : Reason
-- }
-- )
--
-- type InvalidReason
-- = EmptyList
Expand All @@ -61,6 +67,10 @@ encode =
-- | DistributionBug


type alias Record_description_String_reason_Reason_ =
{ description : String, reason : Reason }


type alias Record_expected_String_actual_String_extra_ListString_missing_ListString_ =
{ expected : String, actual : String, extra : List String, missing : List String }

Expand Down Expand Up @@ -147,10 +157,22 @@ decodeReasonHelp constructor =
Invalid
(Decode.field "A1" decodeInvalidReason)

"Multiple" ->
Decode.map
Multiple
(Decode.field "A1" (Decode.list decodeRecord_description_String_reason_Reason_))

other ->
Decode.fail <| "Unknown constructor for type Reason: " ++ other


decodeRecord_description_String_reason_Reason_ =
Decode.map2
Record_description_String_reason_Reason_
(Decode.field "description" Decode.string)
(Decode.field "reason" decodeReason)


decodeRecord_expected_String_actual_String_extra_ListString_missing_ListString_ =
Decode.map4
Record_expected_String_actual_String_extra_ListString_missing_ListString_
Expand Down Expand Up @@ -250,6 +272,19 @@ encodeReason a =
, ( "A1", encodeInvalidReason a1 )
]

Multiple a1 ->
Encode.object
[ ( "Constructor", Encode.string "Multiple" )
, ( "A1", Encode.list encodeRecord_description_String_reason_Reason_ a1 )
]


encodeRecord_description_String_reason_Reason_ a =
Encode.object
[ ( "description", Encode.string a.description )
, ( "reason", encodeReason a.reason )
]


encodeRecord_expected_String_actual_String_extra_ListString_missing_ListString_ a =
Encode.object
Expand Down
9 changes: 4 additions & 5 deletions src/ElmTestRunner/Reporter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ but will basically be wrapped by an actual port in the main Elm caller module.
-}
type alias Ports msg =
{ restart : ({ kind : String, testsCount : Int } -> msg) -> Sub msg
, incomingResult : ({ duration : Float, result : Value, logs : List String } -> msg) -> Sub msg
, incomingResult : ({ result : Value } -> msg) -> Sub msg
, stdout : String -> Cmd msg
, signalFinished : { exitCode : Int, testsCount : Int } -> Cmd msg
}
Expand All @@ -55,7 +55,7 @@ The main Elm module calling this one will typically look like the example below.

port restart : ({ kind : String, count : Int } -> msg) -> Sub msg

port incomingResult : ({ duration : Float, result : Value, logs : List String } -> msg) -> Sub msg
port incomingResult : ({ result : Value } -> msg) -> Sub msg

port signalFinished : { exitCode : Int, testsCount : Int } -> Cmd msg

Expand Down Expand Up @@ -140,7 +140,7 @@ type alias Model =
-}
type Msg
= Restart { kind : String, testsCount : Int }
| IncomingResult { duration : Float, result : Value, logs : List String }
| IncomingResult { result : Value }
| Summarize
| Finished

Expand Down Expand Up @@ -195,11 +195,10 @@ update msg model =
, report model.ports.stdout (model.reporter.onBegin testsCount)
)

IncomingResult { duration, result, logs } ->
IncomingResult { result } ->
let
testResultResult =
decodeValue TestResult.decoder result
|> Result.map (TestResult.setLogs logs >> TestResult.setDuration duration)

allTestResults =
case testResultResult of
Expand Down
26 changes: 21 additions & 5 deletions src/ElmTestRunner/Reporter/ConsoleColor.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ElmTestRunner.Vendor.ConsoleText as Text exposing (Text, UseColor, dark,
import ElmTestRunner.Vendor.FormatColor as FormatColor
import ElmTestRunner.Vendor.FormatMonochrome as FormatMonochrome
import Test.Distribution exposing (DistributionReport)
import Test.Runner exposing (formatLabels)


{-| Provide a console implementation of a reporter, mostly for human consumption.
Expand Down Expand Up @@ -116,10 +115,27 @@ successLabelsToText =
formatLabels (dark << plain << withChar '↓') (green << withChar '✓') >> Text.concat


formatLabels :
(String -> Text)
-> (String -> Text)
-> List String
-> List Text
formatLabels formatDescription formatTest labels =
case labels of
[] ->
[]

test :: descriptions ->
List.foldl
(\x acc -> formatDescription x :: acc)
[ formatTest test ]
descriptions


distributionReportToString : DistributionReport -> Maybe String
distributionReportToString distributionReport =
case distributionReport of
Test.Distribution.NoDistribution ->
Test.Distribution.NoDistribution () ->
Nothing

Test.Distribution.DistributionToReport r ->
Expand Down Expand Up @@ -173,16 +189,16 @@ indent str =
|> String.join "\n"


logsToText : List String -> Text
logsToText : String -> Text
logsToText logs =
if List.isEmpty logs then
if String.isEmpty logs then
Text.plain ""

else
Text.plain <|
String.join "\n"
[ indent "with debug logs:\n"
, String.concat logs
, logs
, ""
]

Expand Down
4 changes: 2 additions & 2 deletions src/ElmTestRunner/Reporter/ConsoleDebug.elm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ indent str =
|> String.join "\n"


displayFailureContent : List String -> List Failure -> List DistributionReport -> List String -> String
displayFailureContent : List String -> List Failure -> List DistributionReport -> String -> String
displayFailureContent todos failures distributionReports logs =
"""with todos: {{ todos }}
with failures: {{ failures }}
Expand All @@ -91,7 +91,7 @@ with debug logs:
|> String.replace "{{ todos }}" (Debug.toString todos)
|> String.replace "{{ failures }}" (Debug.toString failures)
|> String.replace "{{ distributionReports }}" (Debug.toString distributionReports)
|> String.replace "{{ logs }}" (String.concat logs)
|> String.replace "{{ logs }}" logs


onEnd : Result String Kind -> Array TestResult -> Maybe String
Expand Down
5 changes: 2 additions & 3 deletions src/ElmTestRunner/Reporter/Exercism.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ElmTestRunner.Vendor.ConsoleText as Text exposing (Text, UseColor)
import ElmTestRunner.Vendor.FormatColor as FormatColor
import ElmTestRunner.Vendor.FormatMonochrome as FormatMonochrome
import Json.Encode as Encode exposing (Value)
import Test.Distribution exposing (DistributionReport)


{-| Implementation of a reporter for exercism, mostly for automated tools.
Expand Down Expand Up @@ -128,11 +127,11 @@ toExercismResult testResult =
, message = Just (failureMessage failures todos)
, output =
case logs of
[] ->
"" ->
Nothing

_ ->
Just (String.join "\n" logs)
Just logs
}


Expand Down
9 changes: 8 additions & 1 deletion src/ElmTestRunner/Reporter/Json.elm
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,18 @@ encodeReason description reason =
|> Encode.object
|> encodeReasonType "CollectionDiff"

Multiple _ ->
-- elm-test-runner does not support showing the `reason` for `Expect.oneOf`.
-- Also, when this was added, this avoided downstream consumers of this JSON
-- choking on a new variant.
Encode.string description
|> encodeSumType "Custom"


encodeDistributionReport : DistributionReport -> Encode.Value
encodeDistributionReport distributionReport =
case distributionReport of
NoDistribution ->
NoDistribution () ->
Encode.null
|> encodeSumType "NoDistribution"

Expand Down
8 changes: 6 additions & 2 deletions src/ElmTestRunner/Reporter/Junit.elm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ encodeTestResult result =
-- Data that was written to standard out while the test was executed.
-- Normally this is not an attribute inside "testcase" but a tag inside "testsuite" but here we bend the rules
-- to get the Debug.log outputs for this particular test.
, ( "system-out", Encode.string (String.join "\n" logs) )
, ( "system-out", Encode.string logs )
]
in
Encode.object
Expand All @@ -158,7 +158,7 @@ classAndName labels =
distributionReportToString : DistributionReport -> Maybe String
distributionReportToString distributionReport =
case distributionReport of
Test.Distribution.NoDistribution ->
Test.Distribution.NoDistribution () ->
Nothing

Test.Distribution.DistributionToReport r ->
Expand Down Expand Up @@ -271,3 +271,7 @@ reasonToString description reason =
++ String.join "\n" extra
++ "\n\nthese were missing:\n\n"
++ String.join "\n" missing

Multiple _ ->
-- elm-test-runner does not support showing the `reason` for `Expect.oneOf`.
description
Loading