Skip to content

Commit

Permalink
fix backtrace filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Oct 5, 2017
1 parent 92fa0f3 commit e93fd30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e93fd30

Please sign in to comment.