Skip to content

Commit

Permalink
refactor record
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Dec 21, 2024
1 parent 462693c commit 774434f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["distributed", "test"]
license = "MIT"
desc = "some useful steps in tests"
authors = ["WooKyoung Noh <[email protected]>"]
version = "0.2.28"
version = "0.2.29"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
50 changes: 2 additions & 48 deletions src/runtests_testset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,11 @@ mutable struct JiveTestSet <: AbstractTestSet
end
end

using .Test: TESTSET_PRINT_ENABLE, scrub_backtrace
import .Test: record, finish

# import .Test: record
function record(ts::JiveTestSet, t::Test.Pass)
ts.default.n_passed += 1
t
end

function record(ts::JiveTestSet, t::Test.Broken)
push!(ts.default.results, t)
t
end

extract_file(source::LineNumberNode) = extract_file(source.file)
extract_file(file::Symbol) = string(file)
extract_file(::Nothing) = nothing

function record(ts::JiveTestSet, t::Test.LogTestFailure)
if TESTSET_PRINT_ENABLE[]
printstyled(ts.default.description, ": ", color=:white)
print(t)
Base.show_backtrace(stdout, scrub_backtrace(backtrace(), ts.default.file, extract_file(t.source)))
println()
end
# Hack: convert to `Fail` so that test summarization works correctly
push!(ts.default.results, Test.Fail(:test, t.orig_expr, t.logs, nothing, nothing, t.source, false))
return t
end

function record(ts::JiveTestSet, t::Union{Test.Fail, Test.Error})
if TESTSET_PRINT_ENABLE[]
print(ts.default.description, ": ")
# don't print for interrupted tests
if !(t isa Test.Error) || t.test_type !== :test_interrupted
print(t)
if !isa(t, Test.Error) # if not gets printed in the show method
Base.show_backtrace(stdout, compat_scrub_backtrace(backtrace(), ts.default, compat_extract_file(t.source)))
end
println()
end
end
push!(ts.default.results, t)
return t
end

function record(ts::JiveTestSet, t::AbstractTestSet)
push!(ts.default.results, t)
function record(ts::JiveTestSet, t::Union{Test.Pass, Test.Broken, Test.Fail, Test.Error, Test.LogTestFailure, AbstractTestSet})
record(ts.default, t)
end

# import .Test: finish
function finish(ts::JiveTestSet)
jive_finish!(Core.stdout, true, :test, ts)
end
Expand Down

0 comments on commit 774434f

Please sign in to comment.