Skip to content

Commit

Permalink
Add verbose option to @testset (#33755)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ronisbr committed Nov 6, 2020
1 parent 0ed1752 commit 68c71f5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -162,6 +162,8 @@ Standard library changes
* `@time` now reports if the time presented included any compilation time, which is shown as a percentage ([#37678])
* `@varinfo` can now report non-exported objects within modules, look recursively into submodules, and return a sorted
results table ([#38042])
* `@testset` now supports the option `verbose` to show the test result summary
of the children even if they all pass ([#33755])

#### LinearAlgebra

Expand Down
8 changes: 5 additions & 3 deletions stdlib/Test/src/Test.jl
Expand Up @@ -784,8 +784,9 @@ mutable struct DefaultTestSet <: AbstractTestSet
results::Vector
n_passed::Int
anynonpass::Bool
verbose::Bool
end
DefaultTestSet(desc) = DefaultTestSet(desc, [], 0, false)
DefaultTestSet(desc; verbose = false) = DefaultTestSet(desc, [], 0, false, verbose)

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

# Only print results at lower levels if we had failures
if np + nb != subtotal
# Only print results at lower levels if we had failures or if the user
# wants.
if (np + nb != subtotal) || (ts.verbose)
for t in ts.results
if isa(t, DefaultTestSet)
print_counts(t, depth + 1, align,
Expand Down
70 changes: 70 additions & 0 deletions stdlib/Test/test/runtests.jl
Expand Up @@ -969,3 +969,73 @@ let ex = :(something_complex + [1, 2, 3])
@test eof(b)
end
end

@testset "verbose option" begin
expected = """
Test Summary: | Pass Total
Parent | 9 9
Child 1 | 3 3
Child 1.1 | 1 1
Child 1.2 | 1 1
Child 1.3 | 1 1
Child 2 | 3 3
Child 3 | 3 3
Child 3.1 | 1 1
Child 3.2 | 1 1
Child 3.3 | 1 1
"""

mktemp() do f, _
write(f,
"""
using Test
@testset "Parent" verbose = true begin
@testset "Child 1" verbose = true begin
@testset "Child 1.1" begin
@test 1 == 1
end
@testset "Child 1.2" begin
@test 1 == 1
end
@testset "Child 1.3" begin
@test 1 == 1
end
end
@testset "Child 2" begin
@testset "Child 2.1" begin
@test 1 == 1
end
@testset "Child 2.2" begin
@test 1 == 1
end
@testset "Child 2.3" begin
@test 1 == 1
end
end
@testset "Child 3" verbose = true begin
@testset "Child 3.1" begin
@test 1 == 1
end
@testset "Child 3.2" begin
@test 1 == 1
end
@testset "Child 3.3" begin
@test 1 == 1
end
end
end
""")
cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f`
result = read(pipeline(ignorestatus(cmd), stderr=devnull), String)
@test occursin(expected, result)
end
end

0 comments on commit 68c71f5

Please sign in to comment.