Implement random generator and seed

This commit is contained in:
Michael Miller 2019-03-23 19:18:29 -06:00
parent 5d95e1b5dd
commit 21a0f78219
4 changed files with 17 additions and 0 deletions

View file

@ -22,6 +22,7 @@ module Spectator
parser.on("-l", "--line LINE", "Run examples whose line matches LINE") { |line| raise NotImplementedError.new("-l") }
parser.on("-p", "--profile", "Display the 10 slowest specs") { raise NotImplementedError.new("-p") }
parser.on("--location FILE:LINE", "Run the example at line 'LINE' in the file 'FILE', multiple allowed") { |location| raise NotImplementedError.new("--location") }
parser.on("--seed INTEGER", "Set the seed for the random number generator") { |seed| builder.seed = seed.to_i }
parser.on("--json", "Generate JSON output") { builder.formatter = Formatting::JsonFormatter.new }
parser.on("--junit_output OUTPUT_DIR", "Generate JUnit XML output") { |output_dir| builder.add_formatter(Formatting::JUnitFormatter.new(output_dir)) }
parser.on("--tap", "Generate TAP output (Test Anything Protocol)") { builder.formatter = Formatting::TAPFormatter.new }

View file

@ -13,12 +13,16 @@ module Spectator
# Examples won't run, but the output will show that they did.
getter? dry_run : Bool
# Seed for the random number generator.
getter seed : Int32
# Creates a new configuration.
def initialize(builder)
@formatters = builder.formatters
@fail_fast = builder.fail_fast?
@fail_blank = builder.fail_blank?
@dry_run = builder.dry_run?
@seed = builder.seed
end
# Yields each formatter that should be reported to.

View file

@ -8,6 +8,9 @@ module Spectator
new.build
end
# Seed for the random number generator.
property seed = 0
@primary_formatter : Formatting::Formatter?
@additional_formatters = [] of Formatting::Formatter
@fail_fast = false