Skip to content

Commit e93d3aa

Browse files
committed
retest: put kwargs default values in a global NamedTuple
These defaults were used in three different places, so a central places storing the default values helps with maintaining consistency. Also this is a first step towards user-overridable defaults.
1 parent 7d04a6f commit e93d3aa

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/ReTest.jl

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,26 @@ const ArgType = Union{Module,PatternX,AbstractString,AbstractArray,Tuple,Symbol,
478478
Pair{Module,
479479
<:Union{PatternX,AbstractString,AbstractArray,Tuple}}}
480480

481+
const retest_defaults = (
482+
dry = false,
483+
stats = false,
484+
shuffle = false,
485+
group = true,
486+
verbose = true,
487+
recursive = true,
488+
id = nothing,
489+
strict = true,
490+
dup = false,
491+
static = nothing,
492+
load = false,
493+
seed = false,
494+
marks = true,
495+
spin = true,
496+
)
497+
498+
def(kw::Symbol) = retest_defaults[kw]
499+
500+
481501
"""
482502
retest(mod..., pattern...;
483503
dry::Bool=false, stats::Bool=false, verbose::Real=true,
@@ -608,20 +628,21 @@ i.e. this is equivalent to specifying `sub => (pattern, subpat)`.
608628
module in which it was written (e.g. `mod`, when specified).
609629
"""
610630
function retest(@nospecialize(args::ArgType...);
611-
dry::Bool=false,
612-
stats::Bool=false,
613-
shuffle::Bool=false,
614-
group::Bool=true,
615-
verbose::Real=true, # should be @nospecialize, but not supported on old Julia
616-
recursive::Bool=true,
617-
id::Maybe{Bool}=nothing,
618-
strict::Bool=true,
619-
dup::Bool=false,
620-
static::Maybe{Bool}=nothing,
621-
load::Bool=false,
622-
seed::Integer=false,
623-
marks::Bool=true,
624-
spin::Bool=true,
631+
dry::Bool = def(:dry),
632+
stats::Bool = def(:stats),
633+
shuffle::Bool = def(:shuffle),
634+
group::Bool = def(:group),
635+
# should be @nospecialize, but not supported on old Julia
636+
verbose::Real = def(:verbose),
637+
recursive::Bool = def(:recursive),
638+
id::Maybe{Bool} = def(:id),
639+
strict::Bool = def(:strict),
640+
dup::Bool = def(:dup),
641+
static::Maybe{Bool} = def(:static),
642+
load::Bool = def(:load),
643+
seed::Integer = def(:seed),
644+
marks::Bool = def(:marks),
645+
spin::Bool = def(:spin),
625646
)
626647

627648
dry, stats, shuffle, group, verbose, recursive, id, strict, dup, static, marks, spin =
@@ -1107,8 +1128,8 @@ end
11071128
function process_args(@nospecialize(args);
11081129
# defaults for keywords are added just for process_args to be more
11091130
# easily called from test code
1110-
# TODO: set defaults in global variables to help stay in sync?
1111-
verbose=true, shuffle=false, recursive=true, load::Bool=false)
1131+
verbose=def(:verbose), shuffle=def(:shuffle),
1132+
recursive=def(:recursive), load::Bool=def(:load))
11121133
########## process args
11131134
patterns = PatternX[] # list of standalone patterns
11141135
modpats = Dict{Module,Any}() # pairs module => pattern

test/setup.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ end
1313
end
1414

1515
# NOTE: all keywords have the same defaults as `retest`, except `marks`
16+
# Also, not sure why ReTest.def has to be qualified, when we just import def from ReTest
17+
# in this module and call it unqualified, then `def` is said to not exist when running
18+
# the test suite, from within a call to @chapter
1619
function check(x...; runtests=false, output::Union{Nothing,String}=nothing,
17-
verbose=true, stats=false, dry=false, strict::Bool=true,
18-
recursive=true, static=nothing, id=nothing, load=false, marks::Bool=false)
20+
verbose=ReTest.def(:verbose), stats=ReTest.def(:stats), dry=ReTest.def(:dry),
21+
strict::Bool=ReTest.def(:strict), recursive=ReTest.def(:recursive),
22+
static=ReTest.def(:static), id=ReTest.def(:id), load=ReTest.def(:load),
23+
marks::Bool=false)
1924
@assert !(runtests & (output !== nothing)) "unimplemented"
2025
args = x[1:end-1]
2126
expected = x[end]

0 commit comments

Comments
 (0)