Skip to content

Commit 549e32e

Browse files
committed
Use IOCapture to silence tests.
1 parent 43cdf2d commit 549e32e

File tree

3 files changed

+84
-43
lines changed

3 files changed

+84
-43
lines changed

src/ParallelTestRunner.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
667667
Test.print_test_errors(o_ts)
668668
throw(Test.FallbackTestSetException("Test run finished with errors"))
669669
end
670-
return nothing
671670
end # runtests
672671

673672
end # module ParallelTestRunner

test/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2+
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
3+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 82 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,97 @@
11
using ParallelTestRunner
2-
using Test
2+
using Test, IOCapture
33

44
pushfirst!(ARGS, "--verbose")
55

6-
runtests(ARGS)
6+
@testset "ParallelTestRunner" verbose=true begin
77

8-
# custom tests, and initialization code
9-
init_code = quote
10-
using Test
11-
should_be_defined() = true
12-
13-
macro should_also_be_defined()
14-
return :(true)
8+
@testset "basic test" begin
9+
c = IOCapture.capture() do
10+
runtests(ARGS)
1511
end
12+
@test contains(c.output, "SUCCESS")
13+
@test contains(c.output, r"basic .+ started at")
1614
end
17-
custom_tests = Dict(
18-
"custom" => quote
19-
@test should_be_defined()
20-
@test @should_also_be_defined()
21-
end
22-
)
23-
runtests(ARGS; init_code, custom_tests)
2415

25-
# custom worker
26-
function test_worker(name)
27-
if name == "needs env var"
28-
return addworker(env = ["SPECIAL_ENV_VAR" => "42"])
16+
@testset "custom tests and init code" begin
17+
init_code = quote
18+
using Test
19+
should_be_defined() = true
20+
21+
macro should_also_be_defined()
22+
return :(true)
23+
end
2924
end
30-
return nothing
25+
custom_tests = Dict(
26+
"custom" => quote
27+
@test should_be_defined()
28+
@test @should_also_be_defined()
29+
end
30+
)
31+
c = IOCapture.capture() do
32+
runtests(ARGS; init_code, custom_tests)
33+
end
34+
@test contains(c.output, "SUCCESS")
35+
@test contains(c.output, "basic")
36+
@test contains(c.output, "custom")
3137
end
32-
custom_tests = Dict(
33-
"needs env var" => quote
34-
@test ENV["SPECIAL_ENV_VAR"] == "42"
35-
end,
36-
"doesn't need env var" => quote
37-
@test !haskey(ENV, "SPECIAL_ENV_VAR")
38+
39+
@testset "custom worker" begin
40+
function test_worker(name)
41+
if name == "needs env var"
42+
return addworker(env = ["SPECIAL_ENV_VAR" => "42"])
43+
end
44+
return nothing
45+
end
46+
custom_tests = Dict(
47+
"needs env var" => quote
48+
@test ENV["SPECIAL_ENV_VAR"] == "42"
49+
end,
50+
"doesn't need env var" => quote
51+
@test !haskey(ENV, "SPECIAL_ENV_VAR")
52+
end
53+
)
54+
c = IOCapture.capture() do
55+
runtests(ARGS; test_worker, custom_tests)
3856
end
39-
)
40-
runtests(ARGS; test_worker, custom_tests)
57+
@test contains(c.output, "SUCCESS")
58+
@test contains(c.output, "basic")
59+
@test contains(c.output, "needs env var")
60+
@test contains(c.output, "doesn't need env var")
61+
end
4162

42-
# failing test
43-
custom_tests = Dict(
44-
"failing test" => quote
45-
@test 1 == 2
63+
@testset "failing test" begin
64+
custom_tests = Dict(
65+
"failing test" => quote
66+
@test 1 == 2
67+
end
68+
)
69+
c = IOCapture.capture(rethrow=Union{}) do
70+
runtests(ARGS; custom_tests)
4671
end
47-
)
48-
@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests)
72+
@test contains(c.output, "FAILURE")
73+
@test contains(c.output, "basic")
74+
@test contains(c.output, r"failing test .+ failed at")
75+
@test contains(c.output, "1 == 2")
76+
@test c.error
77+
@test c.value == Test.FallbackTestSetException("Test run finished with errors")
78+
end
4979

50-
# throwing test
51-
custom_tests = Dict(
52-
"throwing test" => quote
53-
error("This test throws an error")
80+
@testset "throwing test" begin
81+
custom_tests = Dict(
82+
"throwing test" => quote
83+
error("This test throws an error")
84+
end
85+
)
86+
c = IOCapture.capture(rethrow=Union{}) do
87+
runtests(ARGS; custom_tests)
5488
end
55-
)
56-
@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests)
89+
@test contains(c.output, "FAILURE")
90+
@test contains(c.output, "basic")
91+
@test contains(c.output, r"throwing test .+ failed at")
92+
@test contains(c.output, "Got exception outside of a @test")
93+
@test c.error
94+
@test c.value == Test.FallbackTestSetException("Test run finished with errors")
95+
end
96+
97+
end

0 commit comments

Comments
 (0)