mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Dedicated example runner type
This commit is contained in:
parent
b8901d485d
commit
347e1a84e5
1 changed files with 21 additions and 5 deletions
|
@ -30,12 +30,10 @@ module Spectator
|
||||||
# Returns the result of the execution.
|
# Returns the result of the execution.
|
||||||
# The result will also be stored in `#result`.
|
# The result will also be stored in `#result`.
|
||||||
def run : Result
|
def run : Result
|
||||||
Log.debug { "Running example #{self}" }
|
runner = Runner.new(self, @delegate)
|
||||||
elapsed = Time.measure do
|
@result = runner.run
|
||||||
@delegate.call(self)
|
ensure
|
||||||
end
|
|
||||||
@finished = true
|
@finished = true
|
||||||
@result = PassResult.new(elapsed)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exposes information about the example useful for debugging.
|
# Exposes information about the example useful for debugging.
|
||||||
|
@ -53,5 +51,23 @@ module Spectator
|
||||||
|
|
||||||
io << result
|
io << result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Responsible for executing example code and reporting results.
|
||||||
|
private struct Runner
|
||||||
|
# Creates the runner.
|
||||||
|
# *example* is the example being tested.
|
||||||
|
# The *delegate* is the entrypoint of the example's test code.
|
||||||
|
def initialize(@example : Example, @delegate : ExampleContextDelegate)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Executes the example's test code and produces a result.
|
||||||
|
def run : Result
|
||||||
|
Log.debug { "Running example #{@example}" }
|
||||||
|
elapsed = Time.measure do
|
||||||
|
@delegate.call(@example)
|
||||||
|
end
|
||||||
|
PassResult.new(elapsed)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue