@test_warn doesn't work with @warn in 0.7

I’m trying to make a package work on 0.7 but the unit test is failing like this… (I converted warn to @warn per suggestion from the deprecation warnings.)

julia> foo() = @warn("hello")
foo (generic function with 1 method)

julia> Test.@test_warn "hello" foo()
┌ Warning: hello
└ @ Main REPL[1]:1
Test Failed at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/site/v0.7/Test/src/Test.jl:546
  Expression: contains_warn(read(fname, String), $(Expr(:escape, "hello")))
ERROR: There was an error during testing

julia> versioninfo()
Julia Version 0.7.0-DEV.3551
Commit 0a42222e8f (2018-01-24 02:08 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
1 Like
help?> Test.@test_logs
  @test_logs [log_patterns...] [keywords] expression

  Collect a list of log records generated by expression using collect_test_logs, check that they match the sequence log_patterns, and return the value of expression. The keywords provide some simple filtering
  of log records: the min_level keyword controls the minimum log level which will be collected for the test, the match_mode keyword defines how matching will be performed (the default :all checks that all logs
  and patterns match pairwise; use :any to check that the pattern matches at least once somewhere in the sequence.)

  The most useful log pattern is a simple tuple of the form (level,message). A different number of tuple elements may be used to match other log metadata, corresponding to the arguments to passed to
  AbstractLogger via the handle_message function: (level,message,module,group,id,file,line). Elements which are present will be matched pairwise with the log record fields using == by default, with the special
  cases that Symbols may be used for the standard log levels, and Regexs in the pattern will match string or Symbol fields using contains.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  Consider a function which logs a warning, and several debug messages:

  function foo(n)
      @info "Doing foo with n=$n"
      for i=1:n
          @debug "Iteration $i"
      end
      42
  end

  We can test the info message using

  @test_logs (:info,"Doing foo with n=2") foo(2)

  If we also wanted to test the debug messages, these need to be enabled with the min_level keyword:

  @test_logs (:info,"Doing foo with n=2") (:debug,"Iteration 1") (:debug,"Iteration 2") min_level=Debug foo(2)

  The macro may be chained with @test to also test the returned value:

  @test (@test_logs (:info,"Doing foo with n=2") foo(2)) == 42
1 Like

Nice, that works in 0.7 (as a workaround?)

But then @test_logs does not exist in 0.6 or Compat.Test…

julia> Compat.Test.@
@inferred           @test_approx_eq      @test_broken         @test_skip           @test_warn
@test               @test_approx_eq_eps  @test_nowarn         @test_throws         @testset