mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add error block component
This commit is contained in:
parent
ed3ad662d2
commit
f81c498aef
3 changed files with 52 additions and 3 deletions
44
src/spectator/formatting/components/error_block.cr
Normal file
44
src/spectator/formatting/components/error_block.cr
Normal file
|
@ -0,0 +1,44 @@
|
|||
require "../../example"
|
||||
require "../../error_result"
|
||||
require "./comment"
|
||||
|
||||
module Spectator::Formatting::Components
|
||||
struct ErrorBlock
|
||||
private INDENT = 2
|
||||
|
||||
def initialize(@example : Example, @result : ErrorResult, @index : Int32)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
2.times { io << ' ' }
|
||||
io << @index
|
||||
io << ')'
|
||||
io << ' '
|
||||
io.puts @example
|
||||
indent = INDENT + index_digit_count + 2
|
||||
indent.times { io << ' ' }
|
||||
error = @result.error
|
||||
io << "Error: ".colorize(:red)
|
||||
io.puts error.message
|
||||
io.puts
|
||||
indent.times { io << ' ' }
|
||||
io << error.class
|
||||
io.puts ':'
|
||||
indent += INDENT
|
||||
error.backtrace?.try do |trace|
|
||||
trace.each do |entry|
|
||||
indent.times { io << ' ' }
|
||||
entry = entry.colorize.dim unless entry.starts_with?(/src\/|spec\//)
|
||||
io.puts entry
|
||||
end
|
||||
end
|
||||
indent -= INDENT
|
||||
indent.times { io << ' ' }
|
||||
io.puts Comment.colorize(@example.location) # TODO: Use location of failed expectation.
|
||||
end
|
||||
|
||||
private def index_digit_count
|
||||
(Math.log(@index.to_f + 1) / Math.log(10)).ceil.to_i
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,12 @@
|
|||
require "../../example"
|
||||
require "../../fail_result"
|
||||
require "./comment"
|
||||
|
||||
module Spectator::Formatting::Components
|
||||
struct FailureBlock
|
||||
private INDENT = 2
|
||||
|
||||
def initialize(@example : Example, @index : Int32)
|
||||
@result = @example.result.as(FailResult)
|
||||
def initialize(@example : Example, @result : FailResult, @index : Int32)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "../fail_result"
|
||||
require "./components"
|
||||
|
||||
module Spectator::Formatting
|
||||
|
@ -36,7 +37,11 @@ module Spectator::Formatting
|
|||
io.puts "Failures:"
|
||||
io.puts
|
||||
examples.each_with_index do |example, index|
|
||||
io.puts Components::FailureBlock.new(example, index + 1)
|
||||
if result = example.result.as?(ErrorResult)
|
||||
io.puts Components::ErrorBlock.new(example, result, index + 1)
|
||||
elsif result = example.result.as?(FailResult)
|
||||
io.puts Components::FailureBlock.new(example, result, index + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue