shard-spectator/src/spectator/report.cr

62 lines
1.5 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
2018-09-15 19:51:07 +00:00
@results.count(&.successful?)
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
2018-09-15 19:51:07 +00:00
@results.count(&.failed?)
end
2019-02-13 06:13:03 +00:00
# Returns a set of results for all failed examples.
2018-09-24 00:00:01 +00:00
def failures
2019-02-13 06:34:56 +00:00
@results.select(&.failed?).map(&.as(FailedResult))
2018-09-24 00:00:01 +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
2018-09-15 19:51:07 +00:00
@results.count(&.errored?)
end
2019-02-13 06:13:03 +00:00
# Returns a set of results for all errored examples.
2018-09-24 00:00:01 +00:00
def errors
2019-02-13 06:34:56 +00:00
@results.select(&.errored?).map(&.as(ErroredResult))
2018-09-24 00:00:01 +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
2018-09-15 19:51:07 +00:00
@results.count(&.pending?)
2018-08-31 05:38:20 +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
@results.map(&.elapsed).sum
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