From e93fd3059115132dfc182d1b052fbdb1c860d601 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 5 Oct 2017 11:46:16 +0200 Subject: [PATCH] fix backtrace filtering --- stdlib/Test/src/Test.jl | 4 ++-- stdlib/Test/test/runtests.jl | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index cca73159264be9..b979a7364d0670 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -37,11 +37,11 @@ function ip_matches_func_and_name(ip, func::Symbol, dir::String, file::String) end function scrub_backtrace(bt) - do_test_ind = findfirst(addr->ip_matches_func_and_name(addr, :do_test, ".", "test.jl"), bt) + do_test_ind = findfirst(addr->ip_matches_func_and_name(addr, :do_test, @__DIR__, "Test.jl"), bt) if do_test_ind != 0 && length(bt) > do_test_ind bt = bt[do_test_ind + 1:end] end - name_ind = findfirst(addr->ip_matches_func_and_name(addr, Symbol("macro expansion"), ".", "test.jl"), bt) + name_ind = findfirst(addr->ip_matches_func_and_name(addr, Symbol("macro expansion"), @__DIR__, "Test.jl"), bt) if name_ind != 0 && length(bt) != 0 bt = bt[1:name_ind] end diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index a1d9d661110cee..2e67c9c4177ddc 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -533,16 +533,18 @@ end end @testset "backtraces in test errors" begin - let io = IOBuffer() - # calls backtrace() from inside @test - @test (print(io, Test.Error(:test_error, "woot", 5, backtrace())); 1) == 1 - let str = String(take!(io)) - # NOTE: This test depends on the code generated by @testset getting compiled, - # to get good backtraces. If it fails, check the implementation of `testset_beginend`. - @test contains(str, "Test.jl") - @test_broken !contains(str, "client.jl") - end - end + f = tempname() + write(f, + """ + using Test + @testset begin + @test 1==2 + end + """) + msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=DevNull), String) + @test !contains(msg, "do_test(") + @test !contains(msg, "include(") + @test contains(msg, "at " * f * ":3") end let io = IOBuffer()