2020-10-17 23:40:38 +00:00
|
|
|
require "./composite_example_filter"
|
2020-10-18 03:39:41 +00:00
|
|
|
require "./config"
|
2020-10-17 23:40:38 +00:00
|
|
|
require "./example_filter"
|
|
|
|
require "./null_example_filter"
|
|
|
|
|
2018-12-13 20:50:59 +00:00
|
|
|
module Spectator
|
2018-12-13 21:16:49 +00:00
|
|
|
# Mutable configuration used to produce a final configuration.
|
|
|
|
# Use the setters in this class to incrementally build a configuration.
|
|
|
|
# Then call `#build` to create the final configuration.
|
2018-12-13 20:50:59 +00:00
|
|
|
class ConfigBuilder
|
2019-02-12 20:45:48 +00:00
|
|
|
# Creates a default configuration.
|
|
|
|
def self.default
|
|
|
|
new.build
|
|
|
|
end
|
|
|
|
|
2020-10-18 04:11:04 +00:00
|
|
|
# Seed used for random number generation.
|
2020-10-18 04:12:02 +00:00
|
|
|
property random_seed : UInt64 = Random.rand(UInt64)
|
2020-10-18 04:11:04 +00:00
|
|
|
|
2019-03-23 23:00:21 +00:00
|
|
|
@primary_formatter : Formatting::Formatter?
|
|
|
|
@additional_formatters = [] of Formatting::Formatter
|
2019-03-22 05:40:00 +00:00
|
|
|
@fail_fast = false
|
2019-03-22 19:21:37 +00:00
|
|
|
@fail_blank = false
|
2019-03-22 20:05:48 +00:00
|
|
|
@dry_run = false
|
2019-03-24 01:43:41 +00:00
|
|
|
@randomize = false
|
2019-03-25 18:26:45 +00:00
|
|
|
@profile = false
|
2019-03-25 17:17:53 +00:00
|
|
|
@filters = [] of ExampleFilter
|
2018-12-13 20:50:59 +00:00
|
|
|
|
2020-10-18 03:39:41 +00:00
|
|
|
# Creates a configuration.
|
|
|
|
def build : Config
|
|
|
|
Config.new(self)
|
|
|
|
end
|
|
|
|
|
2019-03-23 23:00:21 +00:00
|
|
|
# Sets the primary formatter to use for reporting test progress and results.
|
2019-03-01 02:14:03 +00:00
|
|
|
def formatter=(formatter : Formatting::Formatter)
|
2019-03-23 23:00:21 +00:00
|
|
|
@primary_formatter = formatter
|
2018-12-13 21:16:49 +00:00
|
|
|
end
|
|
|
|
|
2019-03-23 23:00:21 +00:00
|
|
|
# Adds an extra formater to use for reporting test progress and results.
|
|
|
|
def add_formatter(formatter : Formatting::Formatter)
|
|
|
|
@additional_formatters << formatter
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieves the formatters to use.
|
2018-12-13 21:16:49 +00:00
|
|
|
# If one wasn't specified by the user,
|
|
|
|
# then `#default_formatter` is returned.
|
2019-03-24 02:01:42 +00:00
|
|
|
protected def formatters
|
2019-03-23 23:00:21 +00:00
|
|
|
@additional_formatters + [(@primary_formatter || default_formatter)]
|
2018-12-13 21:16:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# The formatter that should be used,
|
|
|
|
# if one wasn't provided.
|
|
|
|
private def default_formatter
|
2019-03-01 02:14:03 +00:00
|
|
|
Formatting::DotsFormatter.new
|
2018-12-13 21:16:49 +00:00
|
|
|
end
|
|
|
|
|
2019-03-22 05:40:00 +00:00
|
|
|
# Enables fail-fast mode.
|
|
|
|
def fail_fast
|
|
|
|
self.fail_fast = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets the fail-fast flag.
|
|
|
|
def fail_fast=(flag)
|
|
|
|
@fail_fast = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
# Indicates whether fail-fast mode is enabled.
|
2019-03-24 02:01:42 +00:00
|
|
|
protected def fail_fast?
|
2019-03-22 05:40:00 +00:00
|
|
|
@fail_fast
|
|
|
|
end
|
|
|
|
|
2019-03-22 19:21:37 +00:00
|
|
|
# Enables fail-blank mode (fail on no tests).
|
|
|
|
def fail_blank
|
|
|
|
self.fail_blank = true
|
|
|
|
end
|
|
|
|
|
2019-03-22 20:05:48 +00:00
|
|
|
# Enables or disables fail-blank mode.
|
2019-03-22 19:21:37 +00:00
|
|
|
def fail_blank=(flag)
|
|
|
|
@fail_blank = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
# Indicates whether fail-fast mode is enabled.
|
|
|
|
# That is, it is a failure if there are no tests.
|
2019-03-24 02:01:42 +00:00
|
|
|
protected def fail_blank?
|
2019-03-22 19:21:37 +00:00
|
|
|
@fail_blank
|
|
|
|
end
|
|
|
|
|
2019-03-22 20:05:48 +00:00
|
|
|
# Enables dry-run mode.
|
|
|
|
def dry_run
|
|
|
|
self.dry_run = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enables or disables dry-run mode.
|
|
|
|
def dry_run=(flag)
|
|
|
|
@dry_run = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
# Indicates whether dry-run mode is enabled.
|
|
|
|
# In this mode, no tests are run, but output acts like they were.
|
2019-03-24 02:01:42 +00:00
|
|
|
protected def dry_run?
|
2019-03-22 20:05:48 +00:00
|
|
|
@dry_run
|
|
|
|
end
|
|
|
|
|
2019-03-24 01:43:41 +00:00
|
|
|
# Randomizes test execution order.
|
|
|
|
def randomize
|
|
|
|
self.randomize = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enables or disables running tests in a random order.
|
|
|
|
def randomize=(flag)
|
|
|
|
@randomize = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
# Indicates whether tests are run in a random order.
|
2019-03-24 02:01:42 +00:00
|
|
|
protected def randomize?
|
2019-03-24 01:43:41 +00:00
|
|
|
@randomize
|
|
|
|
end
|
|
|
|
|
2019-03-25 18:26:45 +00:00
|
|
|
# Displays profiling information
|
|
|
|
def profile
|
|
|
|
self.profile = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enables or disables displaying profiling information.
|
|
|
|
def profile=(flag)
|
|
|
|
@profile = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
# Indicates whether profiling information should be displayed.
|
|
|
|
protected def profile?
|
|
|
|
@profile
|
|
|
|
end
|
|
|
|
|
2019-03-25 17:17:53 +00:00
|
|
|
# Adds a filter to determine which examples can run.
|
|
|
|
def add_example_filter(filter : ExampleFilter)
|
|
|
|
@filters << filter
|
|
|
|
end
|
|
|
|
|
|
|
|
# Retrieves a filter that determines which examples can run.
|
|
|
|
# If no filters were added with `#add_example_filter`,
|
|
|
|
# then the returned filter will allow all examples to be run.
|
|
|
|
protected def example_filter
|
|
|
|
if @filters.empty?
|
|
|
|
NullExampleFilter.new
|
|
|
|
else
|
|
|
|
CompositeExampleFilter.new(@filters)
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 20:50:59 +00:00
|
|
|
end
|
|
|
|
end
|