Pass along and output random seed

This commit is contained in:
Michael Miller 2021-05-16 20:38:02 -06:00
parent 36f9f2b434
commit 1525317e2c
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,4 @@
require "colorize"
require "./runtime"
require "./totals"
@ -10,6 +11,9 @@ module Spectator::Formatting::Components
def to_s(io)
runtime(io)
totals(io)
if seed = @report.random_seed?
random(io, seed)
end
end
private def runtime(io)
@ -20,5 +24,9 @@ module Spectator::Formatting::Components
private def totals(io)
io.puts Totals.colorize(@report.counts)
end
private def random(io, seed)
io.puts "Randomized with seed: #{seed}".colorize(:cyan)
end
end
end

View file

@ -16,7 +16,7 @@ module Spectator
# True will be returned if the spec ran successfully,
# or false if there was at least one failure.
def run : Bool
runner = Runner.new(examples, @config.formatter, @config.run_flags)
runner = Runner.new(examples, @config.formatter, @config.run_flags, @config.random_seed)
runner.run
end

View file

@ -16,8 +16,8 @@ module Spectator
# The collection of *examples* should be pre-filtered and shuffled.
# This runner will run each example in the order provided.
# The *formatter* will be called for various events.
def initialize(@examples : Array(Example),
@formatter : Formatting::Formatter, @run_flags = RunFlags::None)
def initialize(@examples : Array(Example), @formatter : Formatting::Formatter,
@run_flags = RunFlags::None, @random_seed : UInt64? = nil)
end
# Runs the spec.
@ -30,7 +30,7 @@ module Spectator
elapsed = Time.measure { run_examples }
stop
report = Report.generate(@examples, elapsed, nil) # TODO: Provide random seed.
report = Report.generate(@examples, elapsed, @random_seed)
profile = Profile.generate(@examples) if @run_flags.profile? && report.counts.run > 0
summarize(report, profile)