From 1525317e2ced4a4e99e07098c560d8c71c25867e Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 16 May 2021 20:38:02 -0600 Subject: [PATCH] Pass along and output random seed --- src/spectator/formatting/components/stats.cr | 8 ++++++++ src/spectator/spec.cr | 2 +- src/spectator/spec/runner.cr | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/spectator/formatting/components/stats.cr b/src/spectator/formatting/components/stats.cr index 3daa837..cd5baea 100644 --- a/src/spectator/formatting/components/stats.cr +++ b/src/spectator/formatting/components/stats.cr @@ -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 diff --git a/src/spectator/spec.cr b/src/spectator/spec.cr index e85d5dc..1e275d3 100644 --- a/src/spectator/spec.cr +++ b/src/spectator/spec.cr @@ -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 diff --git a/src/spectator/spec/runner.cr b/src/spectator/spec/runner.cr index d5696ea..81e86c2 100644 --- a/src/spectator/spec/runner.cr +++ b/src/spectator/spec/runner.cr @@ -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)