Skip to content

Commit fbff504

Browse files
KristofferCmaleadt
authored andcommitted
use a counter for passed tests instead of storing the Result object (#20150)
ref #20150 (cherry picked from commit b7c850e)
1 parent 8d4ef37 commit fbff504

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

base/test.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,15 @@ along with a summary of the test results.
411411
type DefaultTestSet <: AbstractTestSet
412412
description::AbstractString
413413
results::Vector
414+
n_passed::Int
414415
anynonpass::Bool
415416
end
416-
DefaultTestSet(desc) = DefaultTestSet(desc, [], false)
417+
DefaultTestSet(desc) = DefaultTestSet(desc, [], 0, false)
417418

418-
# For a passing or broken result, simply store the result
419-
record(ts::DefaultTestSet, t::Union{Pass,Broken}) = (push!(ts.results, t); t)
419+
# For a broken result, simply store the result
420+
record(ts::DefaultTestSet, t::Broken) = (push!(ts.results, t); t)
421+
# For a passed result, do not store the result since it uses a lot of memory
422+
record(ts::DefaultTestSet, t::Pass) = (ts.n_passed += 1; t)
420423

421424
# For the other result types, immediately print the error message
422425
# but do not terminate. Print a backtrace.
@@ -520,10 +523,9 @@ get_alignment(ts, depth::Int) = 0
520523
# Recursive function that counts the number of test results of each
521524
# type directly in the testset, and totals across the child testsets
522525
function get_test_counts(ts::DefaultTestSet)
523-
passes, fails, errors, broken = 0, 0, 0, 0
526+
passes, fails, errors, broken = ts.n_passed, 0, 0, 0
524527
c_passes, c_fails, c_errors, c_broken = 0, 0, 0, 0
525528
for t in ts.results
526-
isa(t, Pass) && (passes += 1)
527529
isa(t, Fail) && (fails += 1)
528530
isa(t, Error) && (errors += 1)
529531
isa(t, Broken) && (broken += 1)

test/test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ ts = @testset "@testset should return the testset" begin
174174
@test true
175175
end
176176
@test typeof(ts) == Base.Test.DefaultTestSet
177-
@test typeof(ts.results[1]) == Base.Test.Pass
177+
@test ts.n_passed == 1
178178

179179
tss = @testset "@testset/for should return an array of testsets: $i" for i in 1:3
180180
@test true
181181
end
182182
@test length(tss) == 3
183183
@test typeof(tss[1]) == Base.Test.DefaultTestSet
184-
@test typeof(tss[1].results[1]) == Base.Test.Pass
184+
@test tss[1].n_passed == 1
185185

186186
# Issue #17908 (return)
187187
testset_depth17908 = Test.get_testset_depth()

0 commit comments

Comments
 (0)