Skip to content

Commit

Permalink
Fix testset for testing logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Jan 10, 2025
1 parent 6bf54db commit 80f8e10
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test/corelogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,35 @@ end
@test_logs (Info,"the msg") logmsg()
@test only(collect_test_logs(logmsg)[1]).kwargs[:x] === "the y"
end
end
@testset "Log message handle_message exception handling" begin
function capture_stderr(func)
fname = tempname()
f = open(fname, "w")
redirect_stderr(f) do
func()
end
close(f)
buf = read(fname)
rm(fname)
String(buf)
end

# Exceptions in log handling (printing) of msg are caught by default
struct Foo end
Base.show(::IO, ::Foo) = 1 ÷ 0
@test_logs (Error, Test.Ignored(), Test.Ignored(), :logevent_error) catch_exceptions=true @info Foo()
out = capture_stderr() do
@info Foo()
end
@test occursin("Error: Exception while generating log record in module Main at", out)
@test occursin("DivideError: integer division error", out)

# Exceptions in log handling (printing) of attributes are caught by default
@test_logs (Error, Test.Ignored(), Test.Ignored(), :logevent_error) catch_exceptions=true @info "foo" x=Foo()
out = capture_stderr() do
@info "foo" x=Foo()
end
@test occursin("Error: Exception while generating log record in module Main at", out)
@test occursin("DivideError: integer division error", out)
end

@testset "Special keywords" begin
Expand Down

0 comments on commit 80f8e10

Please sign in to comment.