Skip to content

Commit

Permalink
Avoid excessive output from test errors (JuliaLang#28184)
Browse files Browse the repository at this point in the history
* Don't print repr of exception when backtrace is also printed in test
error output.

Save decorated repr of exception instead of full undecorated repr

* Fix handling of limited output in logging
  • Loading branch information
andreasnoack committed Aug 7, 2018
1 parent 2990f0e commit 60cf688
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 2 additions & 4 deletions stdlib/Logging/src/ConsoleLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ function handle_message(logger::ConsoleLogger, level, message, _module, group, i
valbuf = IOBuffer()
rows_per_value = max(1, dsize[1]÷(length(kwargs)+1))
valio = IOContext(IOContext(valbuf, logger.stream),
:displaysize=>(rows_per_value,dsize[2]-5))
if logger.show_limited
valio = IOContext(valio, :limit=>true)
end
:displaysize => (rows_per_value,dsize[2]-5),
:limit => logger.show_limited)
for (key,val) in pairs(kwargs)
showvalue(valio, val)
vallines = split(String(take!(valbuf)), '\n')
Expand Down
10 changes: 7 additions & 3 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ mutable struct Error <: Result
else
bt_str = ""
end
new(test_type, orig_expr, repr(value), bt_str, source)
new(test_type,
orig_expr,
sprint(show, value, context = :limit => true),
bt_str,
source)
end
end
function Base.show(io::IO, t::Error)
Expand All @@ -157,7 +161,7 @@ function Base.show(io::IO, t::Error)
println(io, " Expression: ", t.orig_expr)
print( io, " Value: ", t.value)
elseif t.test_type == :test_error
println(io, " Test threw exception ", t.value)
println(io, " Test threw exception")
println(io, " Expression: ", t.orig_expr)
# Capture error message and indent to match
print(io, join(map(line->string(" ",line),
Expand All @@ -169,7 +173,7 @@ function Base.show(io::IO, t::Error)
println(io, " Got correct result, please change to @test if no longer broken.")
elseif t.test_type == :nontest_error
# we had an error outside of a @test
println(io, " Got exception $(t.value) outside of a @test")
println(io, " Got exception outside of a @test")
# Capture error message and indent to match
print(io, join(map(line->string(" ",line),
split(t.backtrace, "\n")), "\n"))
Expand Down

0 comments on commit 60cf688

Please sign in to comment.