diff --git a/tests/Main.elm b/tests/Main.elm index fda2887..f0194d8 100644 --- a/tests/Main.elm +++ b/tests/Main.elm @@ -9,7 +9,11 @@ Note that this always uses an initial seed of 902101337, since it can't do effec -} import Platform +import Random.Pcg as Random import Runner.Log +import Runner.String exposing (Summary) +import SeedTests +import Test exposing (Test) import Tests @@ -21,3 +25,45 @@ main = , subscriptions = \_ -> Sub.none } |> Runner.Log.run Tests.all + -- All seed tests should pass because they receive the same initial seed. + |> runAllTests 1 SeedTests.fixedSeed SeedTests.tests + + +runAllTests : Int -> Random.Seed -> List Test -> a -> a +runAllTests runs seed tests = + tests + |> List.foldl + (\test summary -> + Runner.String.runWithOptions runs seed test + |> combineSummaries summary + ) + emptySummary + |> Runner.Log.logOutput + + +emptySummary : Summary +emptySummary = + { output = "", passed = 0, failed = 0, autoFail = Nothing } + + +combineSummaries : Summary -> Summary -> Summary +combineSummaries first second = + { output = first.output ++ second.output + , passed = first.passed + second.passed + , failed = first.failed + second.failed + , autoFail = + case ( first.autoFail, second.autoFail ) of + ( Nothing, Nothing ) -> + Nothing + + ( Nothing, second ) -> + second + + ( first, Nothing ) -> + first + + ( Just first, Just second ) -> + [ first, second ] + |> String.join "\n" + |> Just + } diff --git a/tests/Runner/Log.elm b/tests/Runner/Log.elm index 29f267f..b6d5370 100644 --- a/tests/Runner/Log.elm +++ b/tests/Runner/Log.elm @@ -1,4 +1,4 @@ -module Runner.Log exposing (run, runWithOptions) +module Runner.Log exposing (logOutput, run, runWithOptions) {-| Log Runner diff --git a/tests/SeedTests.elm b/tests/SeedTests.elm new file mode 100644 index 0000000..4b8b0aa --- /dev/null +++ b/tests/SeedTests.elm @@ -0,0 +1,72 @@ +module SeedTests exposing (fixedSeed, tests) + +import Expect exposing (FloatingPointTolerance(Absolute, AbsoluteOrRelative, Relative)) +import Fuzz exposing (..) +import Random.Pcg as Random +import Test exposing (..) + + +fixedSeed : Random.Seed +fixedSeed = + Random.initialSeed 133742 + + +expectedNum : Int +expectedNum = + 1083264770 + + +{-| Most of the tests will use this, but we won't run it directly. + +When these tests are run using fixedSeed and a run count of 1, this is the +exact number they will get when the description around this fuzz test is +exactly the string "Seed test". + +-} +fuzzTest : Test +fuzzTest = + fuzz int "It receives the expected number" <| + \num -> + Expect.equal num expectedNum + + +tests : List Test +tests = + [ describe "Seed test" + [ fuzzTest ] + , describe "Seed test" + [ fuzz int "It receives the expected number even though this text is different" <| + \num -> + Expect.equal num expectedNum + ] + , describe "Seed test" + [ describe "Nested describes shouldn't affect seed distribution" + [ fuzzTest ] + ] + , describe "Seed test" + [ test "Unit tests before should not affect seed distribution" <| + \_ -> + Expect.pass + , fuzzTest + , test "Unit tests after should not affect seed distribution" <| + \_ -> + Expect.pass + ] + , -- Wrapping in a Test.concat shouldn't change anything + Test.concat + [ describe "Seed test" + [ fuzzTest ] + ] + , -- Wrapping in a Test.concat wth unit tests shouldn't change anything + Test.concat + [ describe "Seed test" + [ test "Unit tests before should not affect seed distribution" <| + \_ -> + Expect.pass + , fuzzTest + , test "Unit tests after should not affect seed distribution" <| + \_ -> + Expect.pass + ] + ] + ]