From ca943e2d74bdd3b18de8aa1b4341b2e812693de9 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Tue, 14 Jan 2025 17:18:55 -0700 Subject: [PATCH] Fixup r"" in Log message handle_message testset --- test/corelogging.jl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/corelogging.jl b/test/corelogging.jl index 64475c8252067..154202da759c2 100644 --- a/test/corelogging.jl +++ b/test/corelogging.jl @@ -115,18 +115,17 @@ end end end @testset "Log message handle_message exception handling" begin - # Exceptions in log handling (printing) of msg are caught by default + # Exceptions in log handling (printing) of msg are caught by default. struct Foo end Base.show(::IO, ::Foo) = 1 รท 0 - @test_warn r"Error: Exception while generating log record in module Main at.*DivideError: integer division error" @info Foo() + # We cannot use `@test_logs` here, since test_logs does not actually _print_ the message + # (i.e. it does not invoke handle_message). To test exception handling during printing, + # we have to use `@test_warn` to see what was printed. + @test_warn r"Error: Exception while generating log record in module .*DivideError: integer division error"s @info Foo() # Exceptions in log handling (printing) of attributes are caught by default - 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) + @test_warn r"Error: Exception while generating log record in module .*DivideError: integer division error"s @info "foo" x=Foo() end @testset "Special keywords" begin