Skip to content

Simplify expectations to a single expectation #244

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Test.elm
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ test untrimmedDesc thunk =
Internal.blankDescriptionFailure

else
Internal.ElmTestVariant__Labeled desc (Internal.ElmTestVariant__UnitTest (\() -> [ thunk () ]))
Internal.ElmTestVariant__Labeled desc (Internal.ElmTestVariant__UnitTest (\() -> thunk ()))


{-| Returns a [`Test`](#Test) that is "TODO" (not yet implemented). These tests
Expand Down
7 changes: 3 additions & 4 deletions src/Test/Fuzz.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ validatedFuzzTest fuzzer getExpectation distribution =
in
case runResult.failure of
Nothing ->
[ Pass { distributionReport = runResult.distributionReport } ]
Pass { distributionReport = runResult.distributionReport }

Just failure ->
[ { failure
{ failure
| expectation =
failure.expectation
|> Test.Expectation.withDistributionReport runResult.distributionReport
}
}
|> formatExpectation
]
)


Expand Down
6 changes: 3 additions & 3 deletions src/Test/Internal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ For more information, see <https://github.com/elm-explorations/test/pull/153>

-}
type Test
= ElmTestVariant__UnitTest (() -> List Expectation)
| ElmTestVariant__FuzzTest (Random.Seed -> Int -> List Expectation)
= ElmTestVariant__UnitTest (() -> Expectation)
| ElmTestVariant__FuzzTest (Random.Seed -> Int -> Expectation)
| ElmTestVariant__Labeled String Test
| ElmTestVariant__Skipped Test
| ElmTestVariant__Only Test
Expand All @@ -27,7 +27,7 @@ type Test
failNow : { description : String, reason : Reason } -> Test
failNow record =
ElmTestVariant__UnitTest
(\() -> [ Test.Expectation.fail record ])
(\() -> Test.Expectation.fail record)


blankDescriptionFailure : Test
Expand Down
8 changes: 4 additions & 4 deletions src/Test/Runner.elm
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ import Test.Runner.Failure exposing (Reason(..))
{-| An unevaluated test.
-}
type Runnable
= Thunk (() -> List Expectation)
= Thunk (() -> Expectation)


{-| A function which, when evaluated, produces a list of expectations. Also a
list of labels which apply to this outcome.
-}
type alias Runner =
{ run : () -> List Expectation
{ run : () -> Expectation
, labels : List String
}

Expand Down Expand Up @@ -136,14 +136,14 @@ countRunnables runnable =
countRunnables runner


run : Runnable -> List Expectation
run : Runnable -> Expectation
run (Thunk fn) =
case runThunk fn of
Ok test ->
test

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


runThunk : (() -> a) -> Result String a
Expand Down
11 changes: 3 additions & 8 deletions tests/src/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ testSimplifyingWith { runs } test =
Test.test label <|
\() ->
runner.run ()
|> List.head
|> Maybe.map (passToFail handleFailure)
|> Maybe.withDefault (Expect.fail "Somehow `testSimplifyingWith` had multiple tests inside")
|> passToFail handleFailure

_ ->
Debug.todo "Unexpected number of test runners in `testSimplifyingWith`"
Expand Down Expand Up @@ -125,9 +123,7 @@ testFailingWith { runs } test =
Test.test label <|
\() ->
runner.run ()
|> List.head
|> Maybe.map (passToFail handleFailure)
|> Maybe.withDefault (Expect.fail "Somehow `testFailingWith` had multiple tests inside")
|> passToFail handleFailure

_ ->
Debug.todo "Unexpected number of test runners in `testFailingWith`"
Expand Down Expand Up @@ -165,8 +161,7 @@ expectTestToFail test =
test
|> Test.Runner.fromTest 100 seed
|> getRunners
|> List.concatMap (\{ run } -> run ())
|> List.map (\expectation () -> expectToFail expectation)
|> List.map (\{ run } () -> expectToFail (run ()))
|> (\expectations -> Expect.all expectations ())


Expand Down
3 changes: 1 addition & 2 deletions tests/src/Runner/String.elm
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ toOutputHelp runner summary =
Debug.log "TEST" runner.labels
in
-}
runner.run ()
|> List.foldl (fromExpectation runner.labels) summary
fromExpectation runner.labels (runner.run ()) summary


fromExpectation : List String -> Expectation -> Summary -> Summary
Expand Down
3 changes: 1 addition & 2 deletions tests/src/RunnerTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ fromTest =
case toSeededRunners (test "crashes" <| \() -> Debug.todo "crash") of
Plain [ runner ] ->
runner.run ()
|> List.head
|> Maybe.andThen Test.Runner.getFailureReason
|> Test.Runner.getFailureReason
|> Expect.equal
(Just
{ given = Nothing
Expand Down