Store random seed

This commit is contained in:
Michael Miller 2020-07-27 10:36:53 -06:00
parent f7d7e2440e
commit a8e2e5c021
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 14 additions and 2 deletions

View file

@ -19,6 +19,9 @@ module Spectator
# Indicates whether tests are run in a random order.
getter? randomize : Bool
# Random seed used for number generation.
getter! random_seed : UInt64?
# Indicates whether profiling information should be displayed.
getter? profile : Bool
@ -33,6 +36,7 @@ module Spectator
@dry_run = builder.dry_run?
@random = builder.random
@randomize = builder.randomize?
@random_seed = builder.seed?
@profile = builder.profile?
@example_filter = builder.example_filter
end

View file

@ -90,8 +90,12 @@ module Spectator
@dry_run
end
# Seed used for random number generation.
getter! seed : UInt64?
# Sets the seed for the random number generator.
def seed=(seed)
@seed = seed
@random = Random.new(seed)
end

View file

@ -25,12 +25,16 @@ module Spectator
# This will be greater than zero only in fail-fast mode.
getter remaining_count
# Random seed used to determine test ordering.
getter! random_seed : UInt64?
# Creates the report.
# The *results* are from running the examples in the test suite.
# The *runtime* is the total time it took to execute the suite.
# The *remaining_count* is the number of tests skipped due to fail-fast.
# The *fail_blank* flag indicates whether it is a failure if there were no tests run.
def initialize(@results : Array(Result), @runtime, @remaining_count = 0, @fail_blank = false)
# The *random_seed* is the seed used for random number generation.
def initialize(@results : Array(Result), @runtime, @remaining_count = 0, @fail_blank = false, @random_seed = nil)
@results.each do |result|
case result
when SuccessfulResult

View file

@ -25,7 +25,7 @@ module Spectator
# Generate a report and pass it along to the formatter.
remaining = @suite.size - results.size
report = Report.new(results, elapsed, remaining, @config.fail_blank?)
report = Report.new(results, elapsed, remaining, @config.fail_blank?, @config.random_seed?)
@config.each_formatter(&.end_suite(report, profile(report)))
!report.failed?