Skip to content

Commit 4ce98c9

Browse files
authored
Use redirect_stdio instead of IOCapture to avoid issues. (#42)
1 parent d7f1314 commit 4ce98c9

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/ParallelTestRunner.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function runtest(::Type{TestRecord}, f, name, init_code, color)
198198
function inner()
199199
# generate a temporary module to execute the tests in
200200
mod = @eval(Main, module $(gensym(name)) end)
201-
@eval(mod, import ParallelTestRunner: Test, Random, IOCapture)
201+
@eval(mod, import ParallelTestRunner: Test, Random)
202202
@eval(mod, using .Test, .Random)
203203

204204
Core.eval(mod, init_code)
@@ -207,13 +207,17 @@ function runtest(::Type{TestRecord}, f, name, init_code, color)
207207
GC.gc(true)
208208
Random.seed!(1)
209209

210-
stats = @timed IOCapture.capture(; color=$color) do
211-
@testset $name begin
212-
$f
210+
mktemp() do path, io
211+
stats = redirect_stdio(stdout=io, stderr=io) do
212+
@timed @testset $name begin
213+
$f
214+
end
213215
end
216+
close(io)
217+
output = read(path, String)
218+
(; testset=stats.value, output, stats.time, stats.bytes, stats.gctime)
219+
214220
end
215-
captured = stats.value
216-
(; testset=captured.value, captured.output, stats.time, stats.bytes, stats.gctime)
217221
end
218222

219223
# process results

test/runtests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ end
123123
end
124124
)
125125

126+
println("NOTE: The next test is expected to crash a worker process, which may print some output to the terminal.")
126127
io = IOBuffer()
127128
@test_throws Test.FallbackTestSetException("Test run finished with errors") begin
128129
runtests(ParallelTestRunner, ["--verbose"]; custom_tests, stdout=io, stderr=io)
129130
end
131+
println()
130132

131133
str = String(take!(io))
132134
@test contains(str, r"crash .+ started at")
@@ -151,4 +153,19 @@ end
151153
@test contains(str, "SUCCESS")
152154
end
153155

156+
@testset "warnings" begin
157+
custom_tests = Dict(
158+
"warning" => quote
159+
@test_warn "3.0" @warn "3.0"
160+
end
161+
)
162+
163+
io = IOBuffer()
164+
runtests(ParallelTestRunner, ["--verbose"]; custom_tests, stdout=io, stderr=io)
165+
166+
str = String(take!(io))
167+
@test contains(str, r"warning .+ started at")
168+
@test contains(str, "SUCCESS")
169+
end
170+
154171
end

0 commit comments

Comments
 (0)