Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/testset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ ReTestSet(desc::String; verbose::Bool=false) =

# For a non-passed result, simply store the result
record(ts::ReTestSet, t::Union{Broken,Fail,Error}) = (push!(ts.results, t); t)
# `@test_logs` produces a `LogTestFailure` on failure, which is not a `Fail`.
# Convert it to `Fail` so the result counting and reporting below treat it as a
# failure, mirroring how `Test.DefaultTestSet` records it.
record(ts::ReTestSet, t::Test.LogTestFailure) =
(push!(ts.results, Fail(:test, t.orig_expr, t.logs, nothing, nothing, t.source, false)); t)
# For a passed result, do not store the result since it uses a lot of memory
record(ts::ReTestSet, t::Pass) = (ts.n_passed += 1; t)

Expand Down
44 changes: 44 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,25 @@ end # Failing
""")
end


# * Failing @test_logs (#50) .................................................
# A failing `@test_logs` must record as a failure (TestSetException), not
# MethodError from a missing record(::LogTestFailure) method.

module FailingTestLogs
using ReTest
using Test: @test_logs

@testset "logs fail" begin
# pattern expects "x", actual log is "y" → LogTestFailure
@test_logs (:info, "x") @info "y"
end
end # FailingTestLogs

@chapter FailingTestLogs begin
@test_throws Test.TestSetException retest(FailingTestLogs)
end

module FailingLoops
# we test that toplevel testset-for don't make retest unresponsive

Expand Down Expand Up @@ -1883,3 +1902,28 @@ end
end
@test Hijack.RUN == [1, 2, 3, 2, 3]
end

Test.@testset "record(::ReTestSet, ::LogTestFailure)" begin
ReTestSet = ReTest.Testset.ReTestSet
record = ReTest.Testset.record
anyfailed = ReTest.Testset.anyfailed
get_test_counts = ReTest.Testset.get_test_counts

logfail = Test.LogTestFailure(:(@info "x"), LineNumberNode(1, :file),
Any[(:info, "x")], Any[])

# A failing `@test_logs` is recordable, and counts as a failure.
ts = ReTestSet(Main, "lt")
Test.@test record(ts, logfail) === logfail
Test.@test anyfailed(ts)
_, fails, errors, _ = get_test_counts(ts)
Test.@test fails == 1
Test.@test errors == 0

# A testset with no failing result reports none.
ts2 = ReTestSet(Main, "lt_empty")
Test.@test !anyfailed(ts2)
_, fails2, errors2, _ = get_test_counts(ts2)
Test.@test fails2 == 0
Test.@test errors2 == 0
end
Loading