shard-spectator/src/spectator/report.cr

65 lines
1.6 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
2018-09-15 19:25:11 +00:00
@results : Array(Result)
2018-08-31 05:38:20 +00:00
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.
2018-09-15 19:25:11 +00:00
def initialize(results : Enumerable(Result), @runtime)
2018-08-31 05:38:20 +00:00
@results = results.to_a
end
2019-02-13 06:13:03 +00:00
# Number of examples.
2018-09-15 19:51:07 +00:00
def examples
@results.size
end
2019-02-13 06:13:03 +00:00
# Number of passing examples.
2018-08-31 05:38:20 +00:00
def successful_examples
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).
2018-08-31 05:38:20 +00:00
def failed_examples
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
@results.select(&.failed?)
end
2019-02-13 06:13:03 +00:00
# Number of examples that had errors.
2018-09-15 19:51:07 +00:00
def errored_examples
@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
@results.select(&.errored?)
end
2019-02-13 06:13:03 +00:00
# Number of pending examples.
2018-09-15 19:51:07 +00:00
def pending_examples
@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