# @test\_warn doesn't work with @warn in 0.7

**URL:** https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001
**Category:** Internals & Design
**Created:** [February 11, 2018, 5:48pm UTC](https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001 "2018-02-11T17:48:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [February 11, 2018, 5:48pm UTC](https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001/1 "2018-02-11T17:48:56Z")

</div>

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
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)

```

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [February 12, 2018, 3:16pm UTC](https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001/2 "2018-02-12T15:16:40Z")

</div>

```julia
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

```

---

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [February 12, 2018, 3:28pm UTC](https://discourse.julialang.org/t/test-warn-doesnt-work-with-warn-in-0-7/9001/3 "2018-02-12T15:28:22Z")

</div>

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

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

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

```
