mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fully implemented test filtering by tags
Addresses https://gitlab.com/arctic-fox/spectator/-/issues/16
This commit is contained in:
parent
ffb99a21d5
commit
8d366bf637
4 changed files with 34 additions and 3 deletions
|
@ -20,6 +20,9 @@ module Spectator
|
|||
# Filter used to select which examples to run.
|
||||
getter node_filter : NodeFilter
|
||||
|
||||
# Filter used to select which examples to _not_ run.
|
||||
getter node_reject : NodeFilter
|
||||
|
||||
# List of hooks to run before all examples in the test suite.
|
||||
protected getter before_suite_hooks : Deque(ExampleGroupHook)
|
||||
|
||||
|
@ -49,6 +52,7 @@ module Spectator
|
|||
@run_flags = source.run_flags
|
||||
@random_seed = source.random_seed
|
||||
@node_filter = source.node_filter
|
||||
@node_reject = source.node_reject
|
||||
|
||||
@before_suite_hooks = source.before_suite_hooks
|
||||
@before_all_hooks = source.before_all_hooks
|
||||
|
@ -86,7 +90,7 @@ module Spectator
|
|||
|
||||
# Creates an iterator configured to select the filtered examples.
|
||||
def iterator(group : ExampleGroup)
|
||||
FilteredExampleIterator.new(group, @node_filter)
|
||||
FilteredExampleIterator.new(group, @node_filter).reject(@node_reject)
|
||||
end
|
||||
|
||||
# Retrieves the configured random number generator.
|
||||
|
|
|
@ -19,6 +19,7 @@ module Spectator
|
|||
@primary_formatter : Formatting::Formatter?
|
||||
@additional_formatters = [] of Formatting::Formatter
|
||||
@filters = [] of NodeFilter
|
||||
@rejects = [] of NodeFilter
|
||||
|
||||
# List of hooks to run before all examples in the test suite.
|
||||
protected getter before_suite_hooks = Deque(ExampleGroupHook).new
|
||||
|
@ -263,6 +264,11 @@ module Spectator
|
|||
@filters << filter
|
||||
end
|
||||
|
||||
# Adds a filter to prevent examples from running.
|
||||
def add_node_reject(filter : NodeFilter)
|
||||
@rejects << filter
|
||||
end
|
||||
|
||||
# Retrieves a filter that determines which examples can run.
|
||||
# If no filters were added with `#add_node_filter`,
|
||||
# then the returned filter will allow all examples to be run.
|
||||
|
@ -273,6 +279,17 @@ module Spectator
|
|||
else CompositeNodeFilter.new(filters)
|
||||
end
|
||||
end
|
||||
|
||||
# Retrieves a filter that prevents examples from running.
|
||||
# If no filters were added with `#add_node_reject`,
|
||||
# then the returned filter will allow all examples to be run.
|
||||
protected def node_reject
|
||||
case (filters = @rejects)
|
||||
when .empty? then NullNodeFilter.new(false)
|
||||
when .one? then filters.first
|
||||
else CompositeNodeFilter.new(filters)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -148,8 +148,13 @@ module Spectator
|
|||
tag = parts.first
|
||||
value = parts.last
|
||||
end
|
||||
|
||||
filter = TagNodeFilter.new(tag, value)
|
||||
builder.add_node_filter(filter)
|
||||
if negated
|
||||
builder.add_node_reject(filter)
|
||||
else
|
||||
builder.add_node_filter(filter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,9 +3,14 @@ require "./node_filter"
|
|||
module Spectator
|
||||
# Filter that matches all nodes.
|
||||
class NullNodeFilter < NodeFilter
|
||||
# Creates the filter.
|
||||
# The *match* flag indicates whether all examples should match or not.
|
||||
def initialize(@match : Bool = true)
|
||||
end
|
||||
|
||||
# Checks whether the node satisfies the filter.
|
||||
def includes?(_node) : Bool
|
||||
true
|
||||
@match
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue