Skip to content

Commit bd0df7b

Browse files
authored
Highlight in red name of failed test when showing output (#90)
* Highlight in red name of failed test when showing output * Use `printstyled` in more places * Add tests * Bump version
1 parent dbb019c commit bd0df7b

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

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 <v.churavy@gmail.com>"]
4-
version = "2.3.0"
4+
version = "2.4.0"
55

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

src/ParallelTestRunner.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,13 @@ function runtests(mod::Module, args::ParsedArgs;
11151115
# print the output generated by each testset
11161116
for (testname, result, output, start, stop) in results
11171117
if !isempty(output)
1118-
println(io_ctx.stdout, "\nOutput generated during execution of '$testname':")
1118+
print(io_ctx.stdout, "\nOutput generated during execution of '")
1119+
if result isa Exception || anynonpass(result.value)
1120+
printstyled(io_ctx.stdout, testname; color=:red)
1121+
else
1122+
printstyled(io_ctx.stdout, testname; color=:normal)
1123+
end
1124+
println(io_ctx.stdout, "':")
11191125
lines = collect(eachline(IOBuffer(output)))
11201126

11211127
for (i,line) in enumerate(lines)
@@ -1223,9 +1229,9 @@ function runtests(mod::Module, args::ParsedArgs;
12231229
print(io_ctx.stdout, c.output)
12241230
end
12251231
if !anynonpass(o_ts)
1226-
println(io_ctx.stdout, " \033[32;1mSUCCESS\033[0m")
1232+
printstyled(io_ctx.stdout, " SUCCESS\n"; bold=true, color=:green)
12271233
else
1228-
println(io_ctx.stderr, " \033[31;1mFAILURE\033[0m\n")
1234+
printstyled(io_ctx.stderr, " FAILURE\n\n"; bold=true, color=:red)
12291235
if VERSION >= v"1.13.0-DEV.1033"
12301236
Test.print_test_errors(io_ctx.stdout, o_ts)
12311237
else

test/runtests.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,23 @@ end
183183
@testset "failing test" begin
184184
testsuite = Dict(
185185
"failing test" => quote
186+
println("This test will fail")
186187
@test 1 == 2
187188
end
188189
)
189190
error_line = @__LINE__() - 3
190191

191192
io = IOBuffer()
193+
ioc = IOContext(io, :color => true)
192194
@test_throws Test.FallbackTestSetException("Test run finished with errors") begin
193-
runtests(ParallelTestRunner, ["--verbose"]; testsuite, stdout=io, stderr=io)
195+
runtests(ParallelTestRunner, ["--verbose"]; testsuite, stdout=ioc, stderr=ioc)
194196
end
195197

196198
str = String(take!(io))
197-
@test contains(str, r"failing test .+ failed at")
199+
@test contains(str, r"failing test.+ failed at")
198200
@test contains(str, "$(basename(@__FILE__)):$error_line")
199201
@test contains(str, "FAILURE")
202+
@test contains(str, "Output generated during execution of '\e[31mfailing test\e[39m':")
200203
@test contains(str, "Test Failed")
201204
@test contains(str, "1 == 2")
202205
end
@@ -263,11 +266,13 @@ end
263266
)
264267

265268
io = IOBuffer()
269+
ioc = IOContext(io, :color => true)
266270
@test_throws Test.FallbackTestSetException("Test run finished with errors") begin
267-
runtests(ParallelTestRunner, ["--verbose"]; testsuite, stdout=io, stderr=io)
271+
runtests(ParallelTestRunner, ["--verbose"]; testsuite, stdout=ioc, stderr=ioc)
268272
end
269273

270274
str = String(take!(io))
275+
@test contains(str, "Output generated during execution of '\e[31mabort\e[39m':")
271276
# Make sure we can capture the output generated by the crashed process, see
272277
# issue <https://github.com/JuliaTesting/ParallelTestRunner.jl/issues/83>.
273278
@test contains(str, msg)
@@ -276,7 +281,7 @@ end
276281
@test contains(str, "in expression starting at")
277282
# Following are messages printed by ParallelTestRunner.
278283
@test contains(str, r"abort .+ started at")
279-
@test contains(str, r"abort .+ crashed at")
284+
@test contains(str, r"abort.+ crashed at")
280285
@test contains(str, "FAILURE")
281286
@test contains(str, "Error During Test")
282287
@test contains(str, "Malt.TerminatedWorkerException")

0 commit comments

Comments
 (0)