shard-spectator/src/spectator/report.cr

68 lines
1.7 KiB
Crystal
Raw Normal View History

2018-08-31 05:38:20 +00:00
module Spectator
# Outcome of all tests in a suite.
2019-02-11 20:50:57 +00:00
class Report
2019-02-13 06:13:03 +00:00
# Total length of time it took to execute the test suite.
# This includes examples, hooks, and framework processes.
2018-08-31 05:38:20 +00:00
getter runtime : Time::Span
2019-02-13 06:13:03 +00:00
# Creates the report.
# The `results` are from running the examples in the test suite.
# The `runtime` is the total time it took to execute the suite.
2019-02-13 06:18:04 +00:00
def initialize(@results : Array(Result), @runtime)
2018-08-31 05:38:20 +00:00
end
2019-02-13 06:13:03 +00:00
# Number of examples.
2019-02-13 06:18:04 +00:00
def example_count
2018-09-15 19:51:07 +00:00
@results.size
end
2019-02-13 06:13:03 +00:00
# Number of passing examples.
2019-02-13 06:18:04 +00:00
def successful_count
@results.count(&.is_a?(SuccessfulResult))
2018-08-31 05:38:20 +00:00
end
2019-02-13 06:13:03 +00:00
# Number of failing examples (includes errors).
2019-02-13 06:18:04 +00:00
def failed_count
@results.count(&.is_a?(FailedResult))
2018-09-15 19:51:07 +00:00
end
2019-02-13 06:13:03 +00:00
# Number of examples that had errors.
2019-02-13 06:18:04 +00:00
def error_count
@results.count(&.is_a?(ErroredResult))
2018-09-15 19:51:07 +00:00
end
2019-02-13 06:13:03 +00:00
# Number of pending examples.
2019-02-13 06:18:04 +00:00
def pending_count
@results.count(&.is_a?(PendingResult))
2018-08-31 05:38:20 +00:00
end
2019-02-13 06:43:43 +00:00
# Returns a set of results for all failed examples.
def failures
@results.select(&.is_a?(FailedResult)).map(&.as(FailedResult))
2019-02-13 06:43:43 +00:00
end
# Returns a set of results for all errored examples.
def errors
@results.select(&.is_a?(ErroredResult)).map(&.as(ErroredResult))
2019-02-13 06:43:43 +00:00
end
2019-02-13 06:13:03 +00:00
# Length of time it took to run just example code.
# This does not include hooks,
# but it does include pre- and post-conditions.
2018-08-31 05:38:20 +00:00
def example_runtime
2019-02-14 21:25:46 +00:00
@results.sum do |result|
if result.is_a?(FinishedResult)
result.elapsed
else
Time::Span.zero
end
end
2018-08-31 05:38:20 +00:00
end
2019-02-13 06:13:03 +00:00
# Length of time spent in framework processes and hooks.
2018-08-31 05:38:20 +00:00
def overhead_time
@runtime - example_runtime
end
end
end