mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add base classes for defining example run order
This commit is contained in:
parent
c100651680
commit
9fb1a3b664
4 changed files with 21 additions and 3 deletions
|
@ -16,6 +16,6 @@ module Spectator
|
|||
end
|
||||
|
||||
at_exit do
|
||||
Runner.new(ALL_EXAMPLES).run
|
||||
Runner.new(ALL_EXAMPLES, DefinedRunOrder.new).run
|
||||
end
|
||||
end
|
||||
|
|
9
src/spectator/defined_run_order.cr
Normal file
9
src/spectator/defined_run_order.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
require "./run_order"
|
||||
|
||||
module Spectator
|
||||
private class DefinedRunOrder < RunOrder
|
||||
def sort(a : Example, b : Example) : Int32
|
||||
-1
|
||||
end
|
||||
end
|
||||
end
|
5
src/spectator/run_order.cr
Normal file
5
src/spectator/run_order.cr
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Spectator
|
||||
private abstract class RunOrder
|
||||
abstract def sort(a : Example, b : Example) : Int32
|
||||
end
|
||||
end
|
|
@ -5,17 +5,21 @@ module Spectator
|
|||
class Runner
|
||||
getter results : Enumerable(ExampleResult)
|
||||
|
||||
def initialize(@examples : Enumerable(Example))
|
||||
def initialize(@examples : Enumerable(Example), @run_order : RunOrder)
|
||||
@results = Array(ExampleResult).new(@examples.size)
|
||||
end
|
||||
|
||||
def run : Nil
|
||||
@examples.each do |example|
|
||||
sorted_examples.each do |example|
|
||||
result = run_example(example)
|
||||
pp result
|
||||
end
|
||||
end
|
||||
|
||||
private def sorted_examples
|
||||
@examples.to_a.sort { |a, b| @run_order.sort(a, b) }
|
||||
end
|
||||
|
||||
private def run_example(example)
|
||||
example.run
|
||||
SuccessfulExampleResult.new(example)
|
||||
|
|
Loading…
Reference in a new issue