Skip to content

Commit 5d507cd

Browse files
vtjnashstaticfloat
authored andcommitted
tests: add help and reflection abilities to choosetests option parser (#42462)
(cherry picked from commit 091594e)
1 parent f46a20a commit 5d507cd

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

test/choosetests.jl

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ Upon return:
2323
- `seed` is a seed which will be used to initialize the global RNG for each
2424
test to be run.
2525
26-
Three options can be passed to `choosetests` by including a special token
26+
Several options can be passed to `choosetests` by including a special token
2727
in the `choices` argument:
2828
- "--skip", which makes all tests coming after be skipped,
2929
- "--exit-on-error" which sets the value of `exit_on_error`,
3030
- "--seed=SEED", which sets the value of `seed` to `SEED`
3131
(parsed as an `UInt128`); `seed` is otherwise initialized randomly.
3232
This option can be used to reproduce failed tests.
33+
- "--help", which prints a help message and then skips all tests.
34+
- "--help-list", which prints the options computed without running them.
3335
"""
3436
function choosetests(choices = [])
3537
testnames = [
@@ -59,26 +61,52 @@ function choosetests(choices = [])
5961
]
6062

6163
tests = []
62-
skip_tests = []
64+
skip_tests = Set()
6365
exit_on_error = false
6466
use_revise = false
6567
seed = rand(RandomDevice(), UInt128)
68+
dryrun = false
6669

6770
for (i, t) in enumerate(choices)
6871
if t == "--skip"
69-
skip_tests = choices[i + 1:end]
72+
union!(skip_tests, choices[i + 1:end])
7073
break
7174
elseif t == "--exit-on-error"
7275
exit_on_error = true
7376
elseif t == "--revise"
7477
use_revise = true
7578
elseif startswith(t, "--seed=")
7679
seed = parse(UInt128, t[8:end])
80+
elseif t == "--help-list"
81+
dryrun = true
82+
elseif t == "--help"
83+
println("""
84+
USAGE: ./julia runtests.jl [options] [tests]
85+
OPTIONS:
86+
--exit-on-error : stop tests immediately when a test group fails
87+
--help : prints this help message
88+
--help-list : prints the options computed without running them
89+
--revise : load Revise
90+
--seed=<SEED> : set the initial seed for all testgroups (parsed as a UInt128)
91+
--skip <NAMES>... : skip test or collection tagged with <NAMES>
92+
TESTS:
93+
Can be special tokens, such as "all", "unicode", "stdlib", the names of stdlib \
94+
modules, or the names of any file in the TESTNAMES array (defaults to "all").
95+
96+
Or prefix a name with `-` (such as `-core`) to skip a particular test.
97+
""")
98+
return [], false, false, false, UInt128(0)
99+
elseif startswith(t, "--")
100+
error("unknown option: $t")
101+
elseif startswith(t, "-")
102+
push!(skip_tests, t[2:end])
77103
else
78104
push!(tests, t)
79105
end
80106
end
81107

108+
unhandled = copy(skip_tests)
109+
82110
if tests == ["all"] || isempty(tests)
83111
tests = testnames
84112
end
@@ -87,6 +115,7 @@ function choosetests(choices = [])
87115
flt = x -> (x != name && !(x in files))
88116
if name in skip_tests
89117
filter!(flt, tests)
118+
pop!(unhandled, name)
90119
elseif name in tests
91120
filter!(flt, tests)
92121
prepend!(tests, files)
@@ -133,6 +162,7 @@ function choosetests(choices = [])
133162
filter!(x -> x != "rounding", tests)
134163
end
135164

165+
filter!(!in(tests), unhandled)
136166
filter!(!in(skip_tests), tests)
137167

138168
new_tests = String[]
@@ -154,7 +184,26 @@ function choosetests(choices = [])
154184
explicit_libgit2 || filter!(x -> x != "LibGit2/online", tests)
155185

156186
# Filter out tests from the test groups in the stdlibs
187+
filter!(!in(tests), unhandled)
157188
filter!(!in(skip_tests), tests)
158189

190+
if !isempty(unhandled)
191+
@warn "Not skipping tests: $(join(unhandled, ", "))"
192+
end
193+
194+
if dryrun
195+
print("Tests enabled to run:")
196+
foreach(t -> print("\n ", t), tests)
197+
if !isempty(skip_tests)
198+
print("\n\nTests skipped:")
199+
foreach(t -> print("\n ", t), skip_tests)
200+
end
201+
print("\n")
202+
exit_on_error && (print("\nwith option "); printstyled("exit_on_error", bold=true))
203+
use_revise && (print("\nwith option "); printstyled("use_revise", bold=true); print(" (Revise.jl)"))
204+
print("\n\n")
205+
empty!(tests)
206+
end
207+
159208
tests, net_on, exit_on_error, use_revise, seed
160209
end

0 commit comments

Comments
 (0)