Skip to content

Commit c42f202

Browse files
giordanomaleadt
andauthored
Save stdout/err of tests with colors (#70)
* Save stdout/err of tests with colors * Add test for colorful output * Bump patch version number * Update src/ParallelTestRunner.jl Co-authored-by: Tim Besard <[email protected]> --------- Co-authored-by: Tim Besard <[email protected]>
1 parent d37fbf5 commit c42f202

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ParallelTestRunner"
22
uuid = "d3525ed8-44d0-4b2c-a655-542cee43accc"
33
authors = ["Valentin Churavy <[email protected]>"]
4-
version = "2.0.1"
4+
version = "2.0.2"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/ParallelTestRunner.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ function runtest(f, name, init_code, color)
258258
take!(pipe_initialized)
259259
read(pipe, String)
260260
end
261-
stats = redirect_stdio(stdout=pipe, stderr=pipe) do
261+
io = IOContext(pipe, :color=>$(color))
262+
stats = redirect_stdio(; stdout=io, stderr=io) do
262263
put!(pipe_initialized, nothing)
263264

264265
# @testset CustomTestRecord switches the all lower-level testset to our custom testset,

test/runtests.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,32 @@ end
230230
@test contains(str, "SUCCESS")
231231
end
232232

233+
# Issue <https://github.com/JuliaTesting/ParallelTestRunner.jl/issues/69>.
234+
@testset "colorful output" begin
235+
testsuite = Dict(
236+
"color" => quote
237+
printstyled("Roses Are Red"; color=:red)
238+
end
239+
)
240+
io = IOBuffer()
241+
ioc = IOContext(io, :color => true)
242+
runtests(ParallelTestRunner, String[]; testsuite, stdout=ioc, stderr=ioc)
243+
str = String(take!(io))
244+
@test contains(str, "\e[31mRoses Are Red\e[39m\n")
245+
@test contains(str, "SUCCESS")
246+
247+
testsuite = Dict(
248+
"no color" => quote
249+
print("Violets are ")
250+
printstyled("blue"; color=:blue)
251+
end
252+
)
253+
io = IOBuffer()
254+
ioc = IOContext(io, :color => false)
255+
runtests(ParallelTestRunner, String[]; testsuite, stdout=ioc, stderr=ioc)
256+
str = String(take!(io))
257+
@test contains(str, "Violets are blue\n")
258+
@test contains(str, "SUCCESS")
259+
end
260+
233261
end

0 commit comments

Comments
 (0)