You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[docs] Execute examples when building the docs (#76)
* [docs] Execute examples when building the docs
* [CI] Build documentation with `--check-bounds=yes`
This hopefully avoids recompiling packages when running the tests
@@ -14,40 +20,51 @@ This page covers advanced features of `ParallelTestRunner` for customizing test
14
20
By default, [`runtests`](@ref) automatically discovers all `.jl` files in your `test/` directory (excluding `runtests.jl` itself) using the `find_tests` function.
15
21
You can customize which tests to run by providing a custom `testsuite` dictionary:
16
22
17
-
```julia
23
+
```@example mypackage
24
+
using ParallelTestRunner
25
+
using MyPackage
26
+
18
27
# Manually define your test suite
19
28
testsuite = Dict(
20
29
"basic" => quote
21
30
include("basic.jl")
22
31
end,
23
32
"advanced" => quote
24
33
include("advanced.jl")
34
+
@test 40 + 2 ≈ 42
25
35
end
26
36
)
27
37
28
-
runtests(MyModule, ARGS; testsuite)
38
+
cd(test_dir) do # hide
39
+
runtests(MyPackage, ARGS; testsuite)
40
+
end # hide
29
41
```
30
42
31
43
## Filtering Test Files
32
44
33
45
You can also use [`find_tests`](@ref) to automatically discover test files and then filter or modify them.
34
46
This requires manually parsing arguments so that filtering is only applied when the user did not request specific tests to run:
35
47
36
-
```julia
48
+
```@example mypackage
49
+
using ParallelTestRunner
50
+
using MyPackage
51
+
37
52
# Start with autodiscovered tests
53
+
cd(test_dir) do # hide
38
54
testsuite = find_tests(pwd())
39
55
40
56
# Parse arguments
41
57
args = parse_args(ARGS)
42
58
43
59
if filter_tests!(testsuite, args)
44
-
# Remove tests that shouldn't run on Windows
45
-
if Sys.iswindows()
46
-
delete!(testsuite, "ext/specialfunctions")
60
+
# Remove tests that shouldn't run on non-Windows systems
61
+
if !Sys.iswindows()
62
+
delete!(testsuite, "advanced")
47
63
end
48
64
end
49
65
50
-
runtests(MyModule, args; testsuite)
66
+
runtests(MyPackage, args; testsuite)
67
+
end # hide
51
68
```
52
69
53
70
The [`filter_tests!`](@ref) function returns `true` if no positional arguments were provided (allowing additional filtering) and `false` if the user specified specific tests (preventing further filtering).
@@ -60,20 +77,20 @@ This is useful for:
60
77
- Defining constants, defaults or helper functions
61
78
- Setting up test infrastructure
62
79
63
-
```julia
80
+
```@example mypackage
64
81
using ParallelTestRunner
82
+
using MyPackage
65
83
66
84
const init_code = quote
67
-
using Test
68
-
using MyPackage
69
-
70
85
# Define a helper function available to all tests
71
86
function test_helper(x)
72
87
return x * 2
73
88
end
74
89
end
75
90
91
+
cd(test_dir) do # hide
76
92
runtests(MyPackage, ARGS; init_code)
93
+
end # hide
77
94
```
78
95
79
96
The `init_code` is evaluated in each test's sandbox module, so all definitions are available to your test files.
@@ -82,8 +99,9 @@ The `init_code` is evaluated in each test's sandbox module, so all definitions a
82
99
83
100
For tests that require specific environment variables or Julia flags, you can use the `test_worker` keyword argument to [`runtests`](@ref) to assign tests to custom workers:
84
101
85
-
```julia
102
+
```@example mypackage
86
103
using ParallelTestRunner
104
+
using MyPackage
87
105
88
106
function test_worker(name)
89
107
if name == "needs_env_var"
@@ -120,8 +138,9 @@ The `test_worker` function receives the test name and should return either:
120
138
121
139
If your package needs to accept its own command-line arguments in addition to `ParallelTestRunner`'s options, use [`parse_args`](@ref) with custom flags:
@@ -132,10 +151,12 @@ if args.custom["myflag"] !== nothing
132
151
end
133
152
134
153
# Pass parsed args to runtests
154
+
cd(test_dir) do # hide
135
155
runtests(MyPackage, args)
156
+
end # hide
136
157
```
137
158
138
-
Custom flags are stored in the `custom` field of the `ParsedArgs` object, with values of `nothing` (not set) or `Some(value)` (set, with optional value).
159
+
Custom flags are stored in the `custom` field of the [`ParsedArgs`](@ref) object, with values of `nothing` (not set) or `Some(value)` (set, with optional value).
139
160
140
161
## Interactive use
141
162
@@ -146,11 +167,11 @@ For example, here is how we could run the subset of test files that start with t
146
167
# Start julia in an environment where `MyPackage.jl` is available
147
168
julia --project
148
169
```
149
-
```julia-repl
150
-
julia> using Pkg
170
+
```@repl mypackage
171
+
using Pkg
151
172
152
173
# No need to start a fresh session to change threading
[ParallelTestRunner.jl](https://github.com/JuliaTesting/ParallelTestRunner.jl) is a simple parallel test runner for Julia tests with automatic test discovery.
11
17
It runs each test file concurrently in isolated worker processes, providing real-time progress output and efficient resource management.
12
18
@@ -19,11 +25,13 @@ It runs each test file concurrently in isolated worker processes, providing real
19
25
20
26
2.**Update your `test/runtests.jl`**:
21
27
22
-
```julia
28
+
```@example mypackage
23
29
using MyPackage
24
30
using ParallelTestRunner
25
31
32
+
cd(test_dir) do # hide
26
33
runtests(MyPackage, ARGS)
34
+
end # hide
27
35
```
28
36
29
37
That's it! `ParallelTestRunner` will automatically:
@@ -108,14 +116,6 @@ The test runner provides real-time output showing:
108
116
- Memory allocation
109
117
- RSS (Resident Set Size) memory usage
110
118
111
-
Example output:
112
-
113
-
```
114
-
Test | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB) |
0 commit comments