mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial code for displaying errors
This commit is contained in:
parent
f37105af5e
commit
e722cc4f1f
1 changed files with 37 additions and 3 deletions
|
@ -31,7 +31,7 @@ module Spectator::Formatting
|
|||
title(io)
|
||||
indent(inner_indent) do
|
||||
message(io)
|
||||
values(io)
|
||||
content(io)
|
||||
source(io)
|
||||
end
|
||||
end
|
||||
|
@ -57,9 +57,19 @@ module Spectator::Formatting
|
|||
line(io, FailureMessage.color(@result))
|
||||
end
|
||||
|
||||
# Produces the main content of the failure block.
|
||||
private def content(io)
|
||||
io.puts
|
||||
if(@result.is_a?(ErroredResult))
|
||||
stack_trace(io)
|
||||
else
|
||||
values(io)
|
||||
end
|
||||
io.puts
|
||||
end
|
||||
|
||||
# Produces the values list of the failure block.
|
||||
private def values(io)
|
||||
io.puts
|
||||
indent do
|
||||
@result.expectations.each_unsatisfied do |expectation|
|
||||
MatchDataValues.new(expectation.values).each do |pair|
|
||||
|
@ -67,7 +77,31 @@ module Spectator::Formatting
|
|||
end
|
||||
end
|
||||
end
|
||||
io.puts
|
||||
end
|
||||
|
||||
# Produces the stack trace for an errored result.
|
||||
private def stack_trace(io)
|
||||
error = @result.error
|
||||
indent do
|
||||
loop do
|
||||
display_error(io, error)
|
||||
if (next_error = error.cause)
|
||||
error = next_error
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Display a single error and its stacktrace.
|
||||
private def display_error(io, error) : Nil
|
||||
line(io, Color.error("Caused by: #{error.message} (#{error.class})"))
|
||||
indent do
|
||||
error.backtrace.each do |frame|
|
||||
line(io, Color.error(frame))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Produces the source line of the failure block.
|
||||
|
|
Loading…
Reference in a new issue