Skip to content

Commit 5249d93

Browse files
committed
seed: allow false for not seeding and true for random seeds
1 parent e654903 commit 5249d93

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/ReTest.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ const ArgType = Union{Module,PatternX,AbstractString,AbstractArray,Tuple,Symbol,
483483
dry::Bool=false, stats::Bool=false, verbose::Real=true,
484484
[id::Bool], shuffle::Bool=false, recursive::Bool=true,
485485
static::Union{Bool,Nothing}=nothing, dup::Bool=false,
486-
load::Bool=false, [seed::Integer], marks::Bool=true)
486+
load::Bool=false, seed::Union{Integer,Bool}=false,
487+
marks::Bool=true)
487488
488489
Run tests declared with [`@testset`](@ref) blocks, within modules `mod` if specified,
489490
or within all currently loaded modules otherwise.
@@ -523,7 +524,8 @@ Filtering `pattern`s can be specified to run only a subset of the tests.
523524
are associated to `Mod` (they inherit its pattern specification as
524525
above), and are cached and used again on subsequent invocations.
525526
* If `seed` is provided, it is used to seed the global RNG before running
526-
the tests.
527+
the tests. As a special case, if `seed === false` (the default), no seeding
528+
is performed, and if `seed === true`, a seed is chosen randomly.
527529
* When `marks` and `dry` are `true`, "check marks" are printed next to testsets
528530
which passed or failed in previous runs.
529531
@@ -611,7 +613,7 @@ function retest(@nospecialize(args::ArgType...);
611613
dup::Bool=false,
612614
static::Maybe{Bool}=nothing,
613615
load::Bool=false,
614-
seed::Maybe{Integer}=nothing,
616+
seed::Integer=false,
615617
marks::Bool=true,
616618
)
617619

@@ -920,10 +922,18 @@ function retest(@nospecialize(args::ArgType...);
920922
@async put!(computechan, nothing)
921923
end
922924

923-
if seed !== nothing
924-
let includestr = """
925+
if seed !== false
926+
let seedstr =
927+
if seed === true
928+
# seed!(nothing) doesn't work on old Julia, so we can't just set
929+
# `seed = nothing` and interpolate `seed` directly in includestr
930+
""
931+
else
932+
string(seed)
933+
end,
934+
includestr = """
925935
using Random
926-
Random.seed!($seed)
936+
Random.seed!($seedstr)
927937
nothing
928938
"""
929939
# can't use `@everywhere using Random`, as here is not toplevel

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,19 @@ end
819819
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[1]
820820
MiscSeed.runtests(verbose=0, seed=2)
821821
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[2]
822+
MiscSeed.runtests(verbose=0) # no seeding
823+
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[2]
824+
MiscSeed.runtests(verbose=0, seed=false) # no seeding
825+
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[2]
826+
827+
rand1 = MiscSeed.RAND1
828+
MiscSeed.runtests(verbose=0, seed=true) # random seeding
829+
@test MiscSeed.RAND1 === MiscSeed.RAND2
830+
rand2 = MiscSeed.RAND1
831+
MiscSeed.runtests(verbose=0, seed=true) # random seeding
832+
@test MiscSeed.RAND1 === MiscSeed.RAND2
833+
rand3 = MiscSeed.RAND1
834+
@test rand1 != rand2 || rand1 != rand3 # || to reduce failure rate
822835
# TODO: test in a distributed setting
823836
end
824837

0 commit comments

Comments
 (0)