mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Shuffle code around for runner
This commit is contained in:
parent
c29748ede5
commit
6c5da5a703
3 changed files with 28 additions and 10 deletions
|
@ -76,7 +76,8 @@ module Spectator
|
||||||
private def self.run
|
private def self.run
|
||||||
# Build the root-level example group and run it.
|
# Build the root-level example group and run it.
|
||||||
group = ::Spectator::DSL::Builder.build
|
group = ::Spectator::DSL::Builder.build
|
||||||
Runner.new(group).run
|
suite = ::Spectator::TestSuite.new(group)
|
||||||
|
Runner.new(suite).run
|
||||||
rescue ex
|
rescue ex
|
||||||
# Catch all unhandled exceptions here.
|
# Catch all unhandled exceptions here.
|
||||||
# Examples are already wrapped, so any exceptions they throw are caught.
|
# Examples are already wrapped, so any exceptions they throw are caught.
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
module Spectator
|
module Spectator
|
||||||
# Main driver for executing tests and feeding results to formatters.
|
# Main driver for executing tests and feeding results to formatters.
|
||||||
class Runner
|
class Runner
|
||||||
def initialize(@group : ExampleGroup,
|
def initialize(@suite : TestSuite,
|
||||||
@formatter : Formatters::Formatter = Formatters::DefaultFormatter.new)
|
@formatter : Formatters::Formatter = Formatters::DefaultFormatter.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run : Nil
|
def run : Nil
|
||||||
iterator = ExampleIterator.new(@group)
|
|
||||||
results = [] of Result
|
results = [] of Result
|
||||||
elapsed = Time.measure do
|
|
||||||
@formatter.start_suite
|
@formatter.start_suite
|
||||||
results = iterator.map do |example|
|
elapsed = Time.measure do
|
||||||
@formatter.start_example(example)
|
results = @suite.map do |example|
|
||||||
Internals::Harness.run(example).tap do |result|
|
run_example(example)
|
||||||
@formatter.end_example(result)
|
end
|
||||||
end.as(Result)
|
|
||||||
end.to_a
|
|
||||||
end
|
end
|
||||||
@formatter.end_suite(TestSuiteResults.new(results, elapsed))
|
@formatter.end_suite(TestSuiteResults.new(results, elapsed))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private def run_example(example)
|
||||||
|
@formatter.start_example(example)
|
||||||
|
result = Internals::Harness.run(example)
|
||||||
|
@formatter.end_example(result)
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
module Spectator
|
module Spectator
|
||||||
# Encapsulates the tests to run and additional properties about them.
|
# Encapsulates the tests to run and additional properties about them.
|
||||||
class TestSuite
|
class TestSuite
|
||||||
|
include Enumerable(Example)
|
||||||
|
|
||||||
|
def initialize(@group : ExampleGroup)
|
||||||
|
end
|
||||||
|
|
||||||
|
def each
|
||||||
|
iterator.each do |example|
|
||||||
|
yield example
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private def iterator
|
||||||
|
ExampleIterator.new(@group)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue