# Test with\_handler() in 0.6.0

**URL:** <https://discourse.julialang.org/t/test-with-handler-in-0-6-0/4822>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [July 12, 2017, 7:58pm UTC](https://discourse.julialang.org/t/test-with-handler-in-0-6-0/4822 "2017-07-12T19:58:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [July 12, 2017, 7:58pm UTC](https://discourse.julialang.org/t/test-with-handler-in-0-6-0/4822/1 "2017-07-12T19:58:04Z")

</div>

I’m using Julia 0.6.0 and would like to know the equivalent of this code in 0.4.x (taken from [https://docs.julialang.org/en/release-0.4/stdlib/test/#handlers](https://docs.julialang.org/en/release-0.4/stdlib/test/#handlers))

```julia
julia> using Base.Test

julia> custom_handler(r::Test.Success) = println("Success on $(r.expr)")
custom_handler (generic function with 1 method)

julia> custom_handler(r::Test.Failure) = error("Error on custom handler: $(r.expr)")
custom_handler (generic function with 2 methods)

julia> custom_handler(r::Test.Error) = rethrow(r)
custom_handler (generic function with 3 methods)

julia> Test.with_handler(custom_handler) do
         @test 1 == 1
         @test 1 != 1
       end
Success on :((1==1))
ERROR: Error on custom handler: :((1!=1))
 in error at error.jl:21
 in custom_handler at none:1
 in do_test at test.jl:39
 in anonymous at no file:3
 in task_local_storage at task.jl:28
 in with_handler at test.jl:24

```

I want to print custom messages on PASS/FAIL of each test.

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [July 13, 2017, 7:47am UTC](https://discourse.julialang.org/t/test-with-handler-in-0-6-0/4822/2 "2017-07-13T07:47:09Z")

</div>

I do not know how to make this work under 0.6

But having a look at test.jl, you can see which functions you can modify to get your custom messages.  
[https://github.com/JuliaLang/julia/blob/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/test.jl#L390](https://github.com/JuliaLang/julia/blob/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/test.jl#L390)

```julia
import Base.Test.Pass
function Base.show(io::IO, t::Pass)
    print_with_color(:green, io, "Test Passed. You can get some ice cream now \n"; bold = true)
    if !(t.orig_expr === nothing)
        print(io, " Expression: ", t.orig_expr)
    end
    if t.test_type == :test_throws
        # The correct type of exception was thrown
        print(io, "\n Thrown: ", typeof(t.value))
    elseif t.test_type == :test && isa(t.data,Expr) && t.data.head == :comparison
        # The test was an expression, so display the term-by-term
        # evaluated version as well
        print(io, "\n Evaluated: ", t.data)
    end
end

@test 2 == 2 #this should print 'Test Passed. You can get some ice cream now '

Test Passed. You can get some ice cream now 

```

---

<div class="post-metadata">

**Author:** ![v-i-s-h](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v-i-s-h/32/46152_2.png) [@v-i-s-h](https://discourse.julialang.org/u/v-i-s-h)\
**Post date:** [July 13, 2017, 7:59am UTC](https://discourse.julialang.org/t/test-with-handler-in-0-6-0/4822/3 "2017-07-13T07:59:37Z")

</div>

Thanks @bernhard 🙂  
This is helpful
