Skip to content

Commit 11f70d5

Browse files
committed
Revert "Simplify expectations to a single expectation"
This reverts commit ad74829.
1 parent 4b16da0 commit 11f70d5

7 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/Test.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test untrimmedDesc thunk =
161161
Internal.blankDescriptionFailure
162162

163163
else
164-
Internal.ElmTestVariant__Labeled desc (Internal.ElmTestVariant__UnitTest (\() -> thunk ()))
164+
Internal.ElmTestVariant__Labeled desc (Internal.ElmTestVariant__UnitTest (\() -> [ thunk () ]))
165165

166166

167167
{-| Returns a [`Test`](#Test) that is "TODO" (not yet implemented). These tests

src/Test/Fuzz.elm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ validatedFuzzTest desc fuzzer getExpectation distribution =
6161
in
6262
case runResult.failure of
6363
Nothing ->
64-
Pass { distributionReport = runResult.distributionReport }
64+
[ Pass { distributionReport = runResult.distributionReport } ]
6565

6666
Just failure ->
67-
{ failure
67+
[ { failure
6868
| expectation =
6969
failure.expectation
7070
|> Test.Expectation.withDistributionReport runResult.distributionReport
71-
}
71+
}
7272
|> formatExpectation
73+
]
7374
)
7475

7576

src/Test/Internal.elm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ For more information, see <https://github.com/elm-explorations/test/pull/153>
1414
1515
-}
1616
type Test
17-
= ElmTestVariant__UnitTest (() -> Expectation)
18-
| ElmTestVariant__FuzzTest (Random.Seed -> Int -> Expectation)
17+
= ElmTestVariant__UnitTest (() -> List Expectation)
18+
| ElmTestVariant__FuzzTest (Random.Seed -> Int -> List Expectation)
1919
| ElmTestVariant__Labeled String Test
2020
| ElmTestVariant__Skipped Test
2121
| ElmTestVariant__Only Test
@@ -27,7 +27,7 @@ type Test
2727
failNow : { description : String, reason : Reason } -> Test
2828
failNow record =
2929
ElmTestVariant__UnitTest
30-
(\() -> Test.Expectation.fail record)
30+
(\() -> [ Test.Expectation.fail record ])
3131

3232

3333
blankDescriptionFailure : Test

src/Test/Runner.elm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ import Test.Runner.Failure exposing (Reason(..))
6262
{-| An unevaluated test.
6363
-}
6464
type Runnable
65-
= Thunk (() -> Expectation)
65+
= Thunk (() -> List Expectation)
6666

6767

6868
{-| A function which, when evaluated, produces a list of expectations. Also a
6969
list of labels which apply to this outcome.
7070
-}
7171
type alias Runner =
72-
{ run : () -> Expectation
72+
{ run : () -> List Expectation
7373
, labels : List String
7474
}
7575

@@ -136,14 +136,14 @@ countRunnables runnable =
136136
countRunnables runner
137137

138138

139-
run : Runnable -> Expectation
139+
run : Runnable -> List Expectation
140140
run (Thunk fn) =
141141
case runThunk fn of
142142
Ok test ->
143143
test
144144

145145
Err message ->
146-
Expect.fail ("This test failed because it threw an exception: \"" ++ message ++ "\"")
146+
[ Expect.fail ("This test failed because it threw an exception: \"" ++ message ++ "\"") ]
147147

148148

149149
runThunk : (() -> a) -> Result String a

tests/src/Helpers.elm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ testSimplifyingWith { runs } test =
8282
Test.test label <|
8383
\() ->
8484
runner.run ()
85-
|> passToFail handleFailure
85+
|> List.head
86+
|> Maybe.map (passToFail handleFailure)
87+
|> Maybe.withDefault (Expect.fail "Somehow `testSimplifyingWith` had multiple tests inside")
8688

8789
_ ->
8890
Debug.todo "Unexpected number of test runners in `testSimplifyingWith`"
@@ -123,7 +125,9 @@ testFailingWith { runs } test =
123125
Test.test label <|
124126
\() ->
125127
runner.run ()
126-
|> passToFail handleFailure
128+
|> List.head
129+
|> Maybe.map (passToFail handleFailure)
130+
|> Maybe.withDefault (Expect.fail "Somehow `testFailingWith` had multiple tests inside")
127131

128132
_ ->
129133
Debug.todo "Unexpected number of test runners in `testFailingWith`"
@@ -161,7 +165,7 @@ expectTestToFail test =
161165
test
162166
|> Test.Runner.fromTest 100 seed
163167
|> getRunners
164-
|> List.map (\{ run } -> run ())
168+
|> List.concatMap (\{ run } -> run ())
165169
|> List.map (\expectation () -> expectToFail expectation)
166170
|> (\expectations -> Expect.all expectations ())
167171

tests/src/Runner/String.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ toOutputHelp runner summary =
6363
Debug.log "TEST" runner.labels
6464
in
6565
-}
66-
fromExpectation runner.labels (runner.run ()) summary
66+
runner.run ()
67+
|> List.foldl (fromExpectation runner.labels) summary
6768

6869

6970
fromExpectation : List String -> Expectation -> Summary -> Summary

tests/src/RunnerTests.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ fromTest =
197197
case toSeededRunners (test "crashes" <| \() -> Debug.todo "crash") of
198198
Plain [ runner ] ->
199199
runner.run ()
200-
|> Test.Runner.getFailureReason
200+
|> List.head
201+
|> Maybe.andThen Test.Runner.getFailureReason
201202
|> Expect.equal
202203
(Just
203204
{ given = Nothing

0 commit comments

Comments
 (0)