Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #43641 #44079

Closed
Closed
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
17 changes: 3 additions & 14 deletions stdlib/Test/src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,20 @@ mutable struct TestLogger <: AbstractLogger
min_level::LogLevel
catch_exceptions::Bool
shouldlog_args
message_limits::Dict{Any,Int}
end

TestLogger(; min_level=Info, catch_exceptions=false) =
TestLogger(LogRecord[], min_level, catch_exceptions, nothing, Dict{Any, Int}())
TestLogger(LogRecord[], min_level, catch_exceptions, nothing)
Logging.min_enabled_level(logger::TestLogger) = logger.min_level

function Logging.shouldlog(logger::TestLogger, level, _module, group, id)
if get(logger.message_limits, id, 1) > 0
logger.shouldlog_args = (level, _module, group, id)
true
else
false
end
logger.shouldlog_args = (level, _module, group, id)
true
end

function Logging.handle_message(logger::TestLogger, level, msg, _module,
group, id, file, line; kwargs...)
@nospecialize
maxlog = get(kwargs, :maxlog, nothing)
if maxlog isa Core.BuiltinInts
remaining = get!(logger.message_limits, id, Int(maxlog)::Int)
logger.message_limits[id] = remaining - 1
remaining > 0 || return
end
push!(logger.logs, LogRecord(level, msg, _module, group, id, file, line, kwargs))
end

Expand Down
5 changes: 0 additions & 5 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,6 @@ end
@test occursin("Evaluated: 0.9 ≈ 0.1 (nans=true, atol=0.01)", msg)
end

erronce() = @error "an error" maxlog=1

@testset "@test_logs" begin
function foo(n)
@info "Doing foo with n=$n"
Expand Down Expand Up @@ -867,9 +865,6 @@ erronce() = @error "an error" maxlog=1

@test_logs (Debug,"Iteration 5") min_level=Debug match_mode=:any foo(10)

# Respect `maxlog` (#41625). We check we only find one logging message.
@test_logs (:error, "an error") (erronce(); erronce())

# Test failures
fails = @testset NoThrowTestSet "check that @test_logs detects bad input" begin
@test_logs (Warn,) foo(1)
Expand Down