|
2 | 2 |
|
3 | 3 | @doc """ |
4 | 4 |
|
5 | | -`tests, net_on, exit_on_error = choosetests(choices)` selects a set of tests to be |
| 5 | +`tests, net_on, exit_on_error, seed = choosetests(choices)` selects a set of tests to be |
6 | 6 | run. `choices` should be a vector of test names; if empty or set to |
7 | 7 | `["all"]`, all tests are selected. |
8 | 8 |
|
9 | 9 | This function also supports "test collections": specifically, "linalg" |
10 | 10 | refers to collections of tests in the correspondingly-named |
11 | 11 | directories. |
12 | 12 |
|
13 | | -Upon return, `tests` is a vector of fully-expanded test names, |
14 | | -`net_on` is true if networking is available (required for some tests), |
15 | | -and `exit_on_error` is true if an error in one test should cancel |
16 | | -remaining tests to be run (otherwise, all tests are run unconditionally). |
17 | | -
|
18 | | -Two options can be passed to `choosetests` by including a special token |
19 | | -in the `choices` argument: "--skip", which makes all tests coming after |
20 | | -be skipped, and "--exit-on-error" which sets the value of `exit_on_error`. |
| 13 | +Upon return: |
| 14 | + - `tests` is a vector of fully-expanded test names, |
| 15 | + - `net_on` is true if networking is available (required for some tests), |
| 16 | + - `exit_on_error` is true if an error in one test should cancel |
| 17 | + remaining tests to be run (otherwise, all tests are run unconditionally), |
| 18 | + - `seed` is a seed which will be used to initialize the global RNG for each |
| 19 | + test to be run. |
| 20 | +
|
| 21 | +Three options can be passed to `choosetests` by including a special token |
| 22 | +in the `choices` argument: |
| 23 | + - "--skip", which makes all tests coming after be skipped, |
| 24 | + - "--exit-on-error" which sets the value of `exit_on_error`, |
| 25 | + - "--seed=SEED", which sets the value of `seed` to `SEED` |
| 26 | + (parsed as an `UInt128`); `seed` is otherwise initialized randomly. |
| 27 | + This option can be used to reproduce failed tests. |
21 | 28 | """ -> |
22 | 29 | function choosetests(choices = []) |
23 | 30 | testnames = [ |
@@ -58,13 +65,16 @@ function choosetests(choices = []) |
58 | 65 | tests = [] |
59 | 66 | skip_tests = [] |
60 | 67 | exit_on_error = false |
| 68 | + seed = rand(RandomDevice(), UInt128) |
61 | 69 |
|
62 | 70 | for (i, t) in enumerate(choices) |
63 | 71 | if t == "--skip" |
64 | 72 | skip_tests = choices[i + 1:end] |
65 | 73 | break |
66 | 74 | elseif t == "--exit-on-error" |
67 | 75 | exit_on_error = true |
| 76 | + elseif startswith(t, "--seed=") |
| 77 | + seed = parse(UInt128, t[8:end]) |
68 | 78 | else |
69 | 79 | push!(tests, t) |
70 | 80 | end |
@@ -177,5 +187,5 @@ function choosetests(choices = []) |
177 | 187 |
|
178 | 188 | filter!(x -> !(x in skip_tests), tests) |
179 | 189 |
|
180 | | - tests, net_on, exit_on_error |
| 190 | + tests, net_on, exit_on_error, seed |
181 | 191 | end |
0 commit comments