@@ -14,6 +14,7 @@ using Distributed: myid, nworkers
14
14
15
15
import InlineTest: @testset
16
16
17
+ import .. ReTest
17
18
using .. ReTest: Pattern, Marks, matches, setresult!
18
19
19
20
# mostly copied from Test stdlib
@@ -514,17 +515,19 @@ function testset_beginend(mod::Module, isfinal::Bool, pat::Pattern, id::Int64, d
514
515
put! ($ (chan. preview), ($ id, $ desc))
515
516
end
516
517
push_testset (ts)
518
+
517
519
# we reproduce the logic of guardseed, but this function
518
520
# cannot be used as it changes slightly the semantic of @testset,
519
521
# by wrapping the body in a function
520
- local RNG = default_rng ()
521
- local oldrng = copy (RNG)
522
+ local default_rng_orig = copy (default_rng ())
523
+ @static if VERSION >= v " 1.11"
524
+ local tls_seed_orig = copy (Random. get_tls_seed ())
525
+ end
526
+
522
527
try
523
- # RNG is re-seeded with its own seed to ease reproduce a failed test
524
- if VERSION >= v " 1.7.0-DEV.1225"
525
- Random. seed! (Random. GLOBAL_SEED)
526
- else
527
- Random. seed! (RNG. seed)
528
+ # RNG is re-seeded with the desired seed for the test
529
+ if ReTest. test_seed[] != = false
530
+ Random. seed! (ReTest. test_seed[])
528
531
end
529
532
let
530
533
ts. timed = @stats $ stats $ (esc (tests))
@@ -536,14 +539,19 @@ function testset_beginend(mod::Module, isfinal::Bool, pat::Pattern, id::Int64, d
536
539
record (ts, Error (:nontest_error , Expr (:tuple ), err,
537
540
current_exceptions (), $ (QuoteNode (source))))
538
541
finally
539
- copy! (RNG, oldrng)
542
+ copy! (default_rng (), default_rng_orig)
543
+ @static if VERSION >= v " 1.11"
544
+ copy! (Random. get_tls_seed (), tls_seed_orig)
545
+ end
546
+
540
547
setresult! ($ marks, ts. subject, ! anyfailed (ts))
541
548
pop_testset ()
542
549
ret = finish (ts, $ chan)
543
550
end
544
551
ret
545
552
end
546
553
end
554
+
547
555
# preserve outer location if possible
548
556
if tests isa Expr && tests. head === :block &&
549
557
! isempty (tests. args) && tests. args[1 ] isa LineNumberNode
@@ -578,7 +586,7 @@ function testset_forloop(mod::Module, isfinal::Bool, pat::Pattern, id::Int64,
578
586
break
579
587
end
580
588
# it's 1000 times faster to copy from tmprng rather than calling Random.seed!
581
- copy! (RNG , tmprng)
589
+ copy! (default_rng () , tmprng)
582
590
end
583
591
ts = ts0
584
592
if nworkers () == 1 && get_testset_depth () == 0 && $ (chan. preview) != = nothing
@@ -600,19 +608,22 @@ function testset_forloop(mod::Module, isfinal::Bool, pat::Pattern, id::Int64,
600
608
end
601
609
end
602
610
end
611
+
603
612
quote
604
613
local arr = Vector {Any} ()
605
614
local first_iteration = true
606
615
local iter = 0
607
616
local ts
608
- local RNG = default_rng ()
609
- local oldrng = copy (RNG)
610
- if VERSION >= v " 1.7.0-DEV.1225"
611
- Random. seed! (Random. GLOBAL_SEED)
612
- else
613
- Random. seed! (RNG. seed)
617
+
618
+ local default_rng_orig = copy (default_rng ())
619
+ @static if VERSION >= v " 1.11"
620
+ local tls_seed_orig = copy (Random. get_tls_seed ())
621
+ end
622
+
623
+ local tmprng = copy (default_rng ())
624
+ if ReTest. test_seed[] != = false
625
+ tmprng = copy (Random. seed! (ReTest. test_seed[]))
614
626
end
615
- local tmprng = copy (RNG)
616
627
try
617
628
let
618
629
$ (Expr (:for , Expr (:block , [esc (v) for v in loops]. .. ), blk))
@@ -623,7 +634,11 @@ function testset_forloop(mod::Module, isfinal::Bool, pat::Pattern, id::Int64,
623
634
pop_testset ()
624
635
push! (arr, finish (ts, $ chan))
625
636
end
626
- copy! (RNG, oldrng)
637
+
638
+ copy! (default_rng (), default_rng_orig)
639
+ @static if VERSION >= v " 1.11"
640
+ copy! (Random. get_tls_seed (), tls_seed_orig)
641
+ end
627
642
end
628
643
arr
629
644
end
0 commit comments