Skip to content
Merged
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
3 changes: 2 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
128 changes: 86 additions & 42 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,100 @@
using ParallelTestRunner
using Test
using Test, IOCapture

pushfirst!(ARGS, "--verbose")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtests mutates ARGS so this only affected the first invocation.

@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