invenia / Memento.jl

A flexible logging library for Julia
https://invenia.github.io/Memento.jl/latest
Other
87 stars 14 forks source link

`@test_log` errors when `msg` doesn't match #130

Closed nickrobinson251 closed 4 years ago

nickrobinson251 commented 5 years ago

This should be a test failure, but instead it is an error (on Memento v0.12.1)

Example:

julia> using Memento

julia> using Memento.TestUtils

julia> @testset "oops" begin
           @test_log getlogger() "info" r".*foo.*" info(getlogger(), "foobar")
       end
Test Summary: | Pass  Total
oops          |    2      2
Test.DefaultTestSet("oops", Any[], 2, false)

julia> @testset "oops" begin
           @test_log getlogger() "info" r".*foo.*" info(getlogger(), "baz")
       end
oops: Test Failed at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:36
  Expression: handler.found[1] == $(Expr(:escape, "info"))
   Evaluated: nothing == "info"
Stacktrace:
 [1] (::getfield(Main, Symbol("##51#52")){Memento.TestUtils.TestHandler{DefaultFormatter,Base.GenericIOBuffer{Array{UInt8,1}}}})() at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:36
 [2] setpropagating!(::getfield(Main, Symbol("##51#52")){Memento.TestUtils.TestHandler{DefaultFormatter,Base.GenericIOBuffer{Array{UInt8,1}}}}, ::Logger, ::Bool) at /Users/nick/.julia/packages/Memento/UgJr2/src/loggers.jl:113
 [3] top-level scope at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:34
 [4] top-level scope at REPL[194]:2
 [5] top-level scope at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/Test/src/Test.jl:1113
 [6] top-level scope at REPL[194]:2
oops: Error During Test at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:37
  Test threw exception
  Expression: occursin_msg($(Expr(:escape, :(#= REPL[194]:2 =# @r_str ".*foo.*"))), handler.found[2])
  MethodError: no method matching occursin(::Regex, ::Nothing)
  Closest candidates are:
    occursin(::Regex, !Matched::SubString; offset) at regex.jl:172
    occursin(::Regex, !Matched::AbstractString; offset) at regex.jl:166
  Stacktrace:
   [1] occursin_msg(::Regex, ::Nothing) at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:15
   [2] (::getfield(Main, Symbol("##51#52")){Memento.TestUtils.TestHandler{DefaultFormatter,Base.GenericIOBuffer{Array{UInt8,1}}}})() at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:37
   [3] setpropagating!(::getfield(Main, Symbol("##51#52")){Memento.TestUtils.TestHandler{DefaultFormatter,Base.GenericIOBuffer{Array{UInt8,1}}}}, ::Logger, ::Bool) at /Users/nick/.julia/packages/Memento/UgJr2/src/loggers.jl:113
   [4] top-level scope at /Users/nick/.julia/packages/Memento/UgJr2/src/memento_test.jl:34
   [5] top-level scope at REPL[194]:2
   [6] top-level scope at /Users/sabae/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.2/Test/src/Test.jl:1113
   [7] top-level scope at REPL[194]:2

Test Summary: | Fail  Error  Total
oops          |    1      1      2
ERROR: Some tests did not pass: 0 passed, 1 failed, 1 errored, 0 broken.

Possible fix

add a method for the nothing case to occursin_msg, e.g.

occursin_msg(s, ::Nothing) = false

at https://github.com/invenia/Memento.jl/blob/d537259efc95ad51af79d6f38e03fc96b25fc1f9/src/memento_test.jl#L14