invenia / Memento.jl

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

Error Message for @test_warn #106

Closed ccoffrin closed 5 years ago

ccoffrin commented 5 years ago

Testing the following code on Julia v0.7 and Memento v0.10,

module ModA
    using Memento

    const LOGGER = getlogger(@__MODULE__)
    __init__() = Memento.register(LOGGER)

    function danger()
        warn(LOGGER, "ModA warning")
    end
end

ModA.danger()

using Memento
using Compat.Test
TESTLOG = getlogger(Main.ModA)

@test_warn(TESTLOG, "ModA warning", ModA.danger())

@test_warn(TESTLOG, "ModA warning 1", ModA.danger())

The last line results in,

Test Failed at /Users/carleton/.julia/packages/Memento/QMKyB/src/memento_test.jl:35
  Expression: handler.found[1] == $(Expr(:escape, "warn"))
   Evaluated: "" == "warn"
ERROR: There was an error during testing

Is this the intended error message? Seems a bit cryptic to me.

iamed2 commented 5 years ago

This happens because the test handler has a filter which doesn't accept log messages that don't match the pattern. The comparison you're seeing there is for a fallback empty message that the test handler keeps until it encounters a message that matches. We should change that to a proper sentinel so that it's clear that no matching log was found.