Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix backtrace filtering in failed testsets #23998

Merged
merged 2 commits into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@ export GenericString, GenericSet, GenericDict, GenericArray
#-----------------------------------------------------------------------

# Backtrace utility functions
function ip_matches_func_and_name(ip, func::Symbol, dir::String, file::String)
for fr in StackTraces.lookup(ip)
if fr === StackTraces.UNKNOWN || fr.from_c
return false
end
path = string(fr.file)
fr.func == func && dirname(path) == dir && basename(path) == file && return true
end
return false
function ip_has_file_and_func(ip, file, funcs)
return any(fr -> (string(fr.file) == file && fr.func in funcs), StackTraces.lookup(ip))
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(ip -> ip_has_file_and_func(ip, @__FILE__, (:do_test, :do_test_throws)), 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(ip -> ip_has_file_and_func(ip, @__FILE__, (Symbol("macro expansion"),)), bt)
if name_ind != 0 && length(bt) != 0
bt = bt[1:name_ind]
end
Expand Down
27 changes: 17 additions & 10 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,23 @@ 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should delete this when done, or use a mktemp do block

write(f,
"""
using Test
@testset begin
@test 1==2
@test_throws MethodError 1
end
""")
msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=DevNull), String)
# 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(msg, "do_test(")
@test !contains(msg, "include(")
@test contains(msg, "at " * f * ":3")
@test contains(msg, "at " * f * ":4")
rm(f; force=true)
end

let io = IOBuffer()
Expand Down