Skip to content

Commit 68c71f5

Browse files
authored
Add verbose option to @testset (#33755)
The `verbose` option in `@testset` can be used to print the results of the child tests, even when all of them have passed. Closes #27088
1 parent 0ed1752 commit 68c71f5

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Standard library changes
162162
* `@time` now reports if the time presented included any compilation time, which is shown as a percentage ([#37678])
163163
* `@varinfo` can now report non-exported objects within modules, look recursively into submodules, and return a sorted
164164
results table ([#38042])
165+
* `@testset` now supports the option `verbose` to show the test result summary
166+
of the children even if they all pass ([#33755])
165167

166168
#### LinearAlgebra
167169

stdlib/Test/src/Test.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,9 @@ mutable struct DefaultTestSet <: AbstractTestSet
784784
results::Vector
785785
n_passed::Int
786786
anynonpass::Bool
787+
verbose::Bool
787788
end
788-
DefaultTestSet(desc) = DefaultTestSet(desc, [], 0, false)
789+
DefaultTestSet(desc; verbose = false) = DefaultTestSet(desc, [], 0, false, verbose)
789790

790791
# For a broken result, simply store the result
791792
record(ts::DefaultTestSet, t::Broken) = (push!(ts.results, t); t)
@@ -1016,8 +1017,9 @@ function print_counts(ts::DefaultTestSet, depth, align,
10161017
end
10171018
println()
10181019

1019-
# Only print results at lower levels if we had failures
1020-
if np + nb != subtotal
1020+
# Only print results at lower levels if we had failures or if the user
1021+
# wants.
1022+
if (np + nb != subtotal) || (ts.verbose)
10211023
for t in ts.results
10221024
if isa(t, DefaultTestSet)
10231025
print_counts(t, depth + 1, align,

stdlib/Test/test/runtests.jl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,73 @@ let ex = :(something_complex + [1, 2, 3])
969969
@test eof(b)
970970
end
971971
end
972+
973+
@testset "verbose option" begin
974+
expected = """
975+
Test Summary: | Pass Total
976+
Parent | 9 9
977+
Child 1 | 3 3
978+
Child 1.1 | 1 1
979+
Child 1.2 | 1 1
980+
Child 1.3 | 1 1
981+
Child 2 | 3 3
982+
Child 3 | 3 3
983+
Child 3.1 | 1 1
984+
Child 3.2 | 1 1
985+
Child 3.3 | 1 1
986+
"""
987+
988+
mktemp() do f, _
989+
write(f,
990+
"""
991+
using Test
992+
993+
@testset "Parent" verbose = true begin
994+
@testset "Child 1" verbose = true begin
995+
@testset "Child 1.1" begin
996+
@test 1 == 1
997+
end
998+
999+
@testset "Child 1.2" begin
1000+
@test 1 == 1
1001+
end
1002+
1003+
@testset "Child 1.3" begin
1004+
@test 1 == 1
1005+
end
1006+
end
1007+
1008+
@testset "Child 2" begin
1009+
@testset "Child 2.1" begin
1010+
@test 1 == 1
1011+
end
1012+
1013+
@testset "Child 2.2" begin
1014+
@test 1 == 1
1015+
end
1016+
1017+
@testset "Child 2.3" begin
1018+
@test 1 == 1
1019+
end
1020+
end
1021+
1022+
@testset "Child 3" verbose = true begin
1023+
@testset "Child 3.1" begin
1024+
@test 1 == 1
1025+
end
1026+
1027+
@testset "Child 3.2" begin
1028+
@test 1 == 1
1029+
end
1030+
1031+
@testset "Child 3.3" begin
1032+
@test 1 == 1
1033+
end
1034+
end
1035+
end
1036+
""")
1037+
cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f`
1038+
result = read(pipeline(ignorestatus(cmd), stderr=devnull), String)
1039+
@test occursin(expected, result)
1040+
end
1041+
end

0 commit comments

Comments
 (0)