mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial code for summary output
This commit is contained in:
parent
7504536528
commit
49175e56ac
2 changed files with 98 additions and 1 deletions
45
src/spectator/formatters/failure_block.cr
Normal file
45
src/spectator/formatters/failure_block.cr
Normal file
|
@ -0,0 +1,45 @@
|
|||
module Spectator::Formatters
|
||||
class FailureBlock
|
||||
def initialize(@index : Int32, @result : FailedResult)
|
||||
end
|
||||
|
||||
def source(io)
|
||||
io << @result.example.source_file
|
||||
io << ':'
|
||||
io << @result.example.source_line
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
to_s_title(io)
|
||||
to_s_message(io)
|
||||
to_s_expected_actual(io)
|
||||
to_s_source(io)
|
||||
end
|
||||
|
||||
private def to_s_title(io)
|
||||
io << " "
|
||||
io << @index
|
||||
io << ')'
|
||||
io << @result.example
|
||||
io.puts
|
||||
end
|
||||
|
||||
private def to_s_message(io)
|
||||
io << " Failure: "
|
||||
io << @result.error
|
||||
io.puts
|
||||
end
|
||||
|
||||
private def to_s_expected_actual(io)
|
||||
io.puts
|
||||
io.puts " Expected: TODO"
|
||||
io.puts " got: TODO"
|
||||
io.puts
|
||||
end
|
||||
|
||||
private def to_s_source(io)
|
||||
io << " # "
|
||||
source(io)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,7 +10,59 @@ module Spectator::Formatters
|
|||
# A block describing each failure is displayed.
|
||||
# At the end, the totals and runtime are printed.
|
||||
def end_suite(report)
|
||||
raise NotImplementedError.new("SuiteSummary#end_suite")
|
||||
failures = report.failures.map_with_index { |result, index| FailureBlock.new(index + 1, result) }
|
||||
puts
|
||||
puts
|
||||
display_failures(failures) if failures.any?
|
||||
display_stats(report)
|
||||
display_failure_commands(failures) if failures.any?
|
||||
end
|
||||
|
||||
private def display_failures(failures)
|
||||
puts "Failures:"
|
||||
puts
|
||||
failures.each do |block|
|
||||
puts block
|
||||
puts
|
||||
end
|
||||
end
|
||||
|
||||
private def display_stats(report)
|
||||
puts "Finished in #{human_time(report.runtime)}"
|
||||
puts "#{report.example_count} examples, #{report.failed_count} failures, #{report.error_count} errors, #{report.pending_count} pending"
|
||||
end
|
||||
|
||||
private def display_failure_commands(failures)
|
||||
puts
|
||||
puts "Failed examples:"
|
||||
puts
|
||||
failures.each do |block|
|
||||
print "crystal spec "
|
||||
block.source(STDOUT)
|
||||
puts " # TODO"
|
||||
end
|
||||
end
|
||||
|
||||
private def human_time(span)
|
||||
millis = span.total_milliseconds
|
||||
return "#{(millis * 1000).round.to_i} microseconds" if millis < 1
|
||||
|
||||
seconds = span.total_seconds
|
||||
return "#{millis.round(2)} milliseconds" if seconds < 1
|
||||
return "#{seconds.round(2)} seconds" if seconds < 60
|
||||
|
||||
int_seconds = seconds.to_i
|
||||
minutes = int_seconds / 60
|
||||
int_seconds %= 60
|
||||
return sprintf("%i:%02i", minutes, int_seconds) if minutes < 60
|
||||
|
||||
hours = minutes / 60
|
||||
minutes %= 60
|
||||
return sprintf("%i:%02i:%02i", hours, minutes, int_seconds) if hours < 24
|
||||
|
||||
days = hours / 24
|
||||
hours %= 24
|
||||
return sprintf("%i days %i:%02i:%02i", days, hours, minutes, int_seconds)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue