diff --git a/test/Project.toml b/test/Project.toml index 700082b..72c588e 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,2 +1,3 @@ [deps] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" \ No newline at end of file +IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 8e6bbd1..ea9ba3f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,56 +1,100 @@ using ParallelTestRunner -using Test +using Test, IOCapture -pushfirst!(ARGS, "--verbose") +@testset "ParallelTestRunner" verbose=true begin -runtests(ARGS) +@testset "basic test" begin + println() + println("Showing the output of one test run:") + println("-"^80) + c = IOCapture.capture(passthrough=true) do + runtests(["--verbose"]) + end + println("-"^80) + println() + @test contains(c.output, r"basic .+ started at") + @test contains(c.output, "SUCCESS") +end -# custom tests, and initialization code -init_code = quote - using Test - should_be_defined() = true +@testset "custom tests and init code" begin + init_code = quote + using Test + should_be_defined() = true - macro should_also_be_defined() - return :(true) + macro should_also_be_defined() + return :(true) + end end -end -custom_tests = Dict( - "custom" => quote - @test should_be_defined() - @test @should_also_be_defined() + custom_tests = Dict( + "custom" => quote + @test should_be_defined() + @test @should_also_be_defined() + end + ) + c = IOCapture.capture() do + runtests(["--verbose"]; init_code, custom_tests) end -) -runtests(ARGS; init_code, custom_tests) + @test contains(c.output, r"basic .+ started at") + @test contains(c.output, r"custom .+ started at") + @test contains(c.output, "SUCCESS") +end -# custom worker -function test_worker(name) - if name == "needs env var" - return addworker(env = ["SPECIAL_ENV_VAR" => "42"]) +@testset "custom worker" begin + function test_worker(name) + if name == "needs env var" + return addworker(env = ["SPECIAL_ENV_VAR" => "42"]) + end + return nothing end - return nothing -end -custom_tests = Dict( - "needs env var" => quote - @test ENV["SPECIAL_ENV_VAR"] == "42" - end, - "doesn't need env var" => quote - @test !haskey(ENV, "SPECIAL_ENV_VAR") + custom_tests = Dict( + "needs env var" => quote + @test ENV["SPECIAL_ENV_VAR"] == "42" + end, + "doesn't need env var" => quote + @test !haskey(ENV, "SPECIAL_ENV_VAR") + end + ) + c = IOCapture.capture() do + runtests(["--verbose"]; test_worker, custom_tests) end -) -runtests(ARGS; test_worker, custom_tests) + @test contains(c.output, r"basic .+ started at") + @test contains(c.output, r"needs env var .+ started at") + @test contains(c.output, r"doesn't need env var .+ started at") + @test contains(c.output, "SUCCESS") +end -# failing test -custom_tests = Dict( - "failing test" => quote - @test 1 == 2 +@testset "failing test" begin + custom_tests = Dict( + "failing test" => quote + @test 1 == 2 + end + ) + c = IOCapture.capture(rethrow=Union{}) do + runtests(["--verbose"]; custom_tests) end -) -@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests) + @test contains(c.output, r"basic .+ started at") + @test contains(c.output, r"failing test .+ failed at") + @test contains(c.output, "FAILURE") + @test contains(c.output, "1 == 2") + @test c.error + @test c.value == Test.FallbackTestSetException("Test run finished with errors") +end -# throwing test -custom_tests = Dict( - "throwing test" => quote - error("This test throws an error") +@testset "throwing test" begin + custom_tests = Dict( + "throwing test" => quote + error("This test throws an error") + end + ) + c = IOCapture.capture(rethrow=Union{}) do + runtests(["--verbose"]; custom_tests) end -) -@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests) + @test contains(c.output, r"basic .+ started at") + @test contains(c.output, r"throwing test .+ failed at") + @test contains(c.output, "FAILURE") + @test contains(c.output, "Got exception outside of a @test") + @test c.error + @test c.value == Test.FallbackTestSetException("Test run finished with errors") +end + +end