Skip to content

Commit a705b98

Browse files
authored
[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
1 parent 7e025e5 commit a705b98

File tree

10 files changed

+109
-41
lines changed

10 files changed

+109
-41
lines changed

.github/workflows/Documentation.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ jobs:
4343
with:
4444
cache-name: Documentation
4545
- name: Instantiate docs environment
46-
shell: julia --color=yes --project=docs {0}
46+
# Use `--check-bounds=yes` so that when we run tests we don't need to
47+
# precompile again all the packages.
48+
shell: julia --color=yes --check-bounds=yes --project=docs {0}
4749
run: |
4850
using Pkg
4951
Pkg.instantiate()
5052
- name: Build documentation
5153
run:
52-
julia --color=yes --project=docs docs/make.jl
54+
julia --color=yes --project=docs --check-bounds=yes docs/make.jl
5355
env:
5456
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5557
- name: Save Julia depot cache on cancel or failure
@@ -94,15 +96,15 @@ jobs:
9496
name: documentation-build
9597
path: docs/build
9698
- name: Instantiate docs environment
97-
shell: julia --color=yes {0}
99+
shell: julia --color=yes --check-bounds=yes {0}
98100
run: |
99101
# We only need `Documenter` for publishing the docs, let's not
100102
# reinstall the world all over again.
101103
using Pkg
102104
Pkg.add(; name="Documenter", version="1")
103105
- name: Deploy documentation
104106
run:
105-
julia --color=yes docs/deploy.jl
107+
julia --color=yes --check-bounds=yes docs/deploy.jl
106108
env:
107109
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108110
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

docs/MyPackage/Project.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "MyPackage"
2+
uuid = "0b48ad8b-a282-4514-80d9-bf0add6b76ed"
3+
4+
[deps]
5+
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
6+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
8+
[sources]
9+
ParallelTestRunner = {path = ".."}
10+
11+
[compat]
12+
julia = "1.10"

docs/MyPackage/src/MyPackage.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module MyPackage
2+
end # module MyPackage

docs/MyPackage/test/advanced.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using Test
2+
3+
@test true

docs/MyPackage/test/basic.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using Test
2+
3+
@test true

docs/MyPackage/test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
using MyPackage
2+
using ParallelTestRunner

docs/Project.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
MyPackage = "0b48ad8b-a282-4514-80d9-bf0add6b76ed"
34
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
4-
5-
[compat]
6-
Documenter = "1"
5+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
76

87
[sources]
8+
MyPackage = {path = "MyPackage"}
99
ParallelTestRunner = {path = ".."}
10+
11+
[compat]
12+
Documenter = "1"

docs/src/advanced.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
```@setup mypackage
2+
using ParallelTestRunner
3+
using MyPackage
4+
test_dir = joinpath(pkgdir(ParallelTestRunner), "docs", "MyPackage", "test")
5+
```
6+
17
# Advanced Usage
28

39
```@meta
@@ -14,40 +20,51 @@ This page covers advanced features of `ParallelTestRunner` for customizing test
1420
By default, [`runtests`](@ref) automatically discovers all `.jl` files in your `test/` directory (excluding `runtests.jl` itself) using the `find_tests` function.
1521
You can customize which tests to run by providing a custom `testsuite` dictionary:
1622

17-
```julia
23+
```@example mypackage
24+
using ParallelTestRunner
25+
using MyPackage
26+
1827
# Manually define your test suite
1928
testsuite = Dict(
2029
"basic" => quote
2130
include("basic.jl")
2231
end,
2332
"advanced" => quote
2433
include("advanced.jl")
34+
@test 40 + 2 ≈ 42
2535
end
2636
)
2737
28-
runtests(MyModule, ARGS; testsuite)
38+
cd(test_dir) do # hide
39+
runtests(MyPackage, ARGS; testsuite)
40+
end # hide
2941
```
3042

3143
## Filtering Test Files
3244

3345
You can also use [`find_tests`](@ref) to automatically discover test files and then filter or modify them.
3446
This requires manually parsing arguments so that filtering is only applied when the user did not request specific tests to run:
3547

36-
```julia
48+
```@example mypackage
49+
using ParallelTestRunner
50+
using MyPackage
51+
3752
# Start with autodiscovered tests
53+
cd(test_dir) do # hide
3854
testsuite = find_tests(pwd())
3955
4056
# Parse arguments
4157
args = parse_args(ARGS)
4258
4359
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")
4763
end
4864
end
4965
50-
runtests(MyModule, args; testsuite)
66+
runtests(MyPackage, args; testsuite)
67+
end # hide
5168
```
5269

5370
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:
6077
- Defining constants, defaults or helper functions
6178
- Setting up test infrastructure
6279

63-
```julia
80+
```@example mypackage
6481
using ParallelTestRunner
82+
using MyPackage
6583
6684
const init_code = quote
67-
using Test
68-
using MyPackage
69-
7085
# Define a helper function available to all tests
7186
function test_helper(x)
7287
return x * 2
7388
end
7489
end
7590
91+
cd(test_dir) do # hide
7692
runtests(MyPackage, ARGS; init_code)
93+
end # hide
7794
```
7895

7996
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
8299

83100
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:
84101

85-
```julia
102+
```@example mypackage
86103
using ParallelTestRunner
104+
using MyPackage
87105
88106
function test_worker(name)
89107
if name == "needs_env_var"
@@ -120,8 +138,9 @@ The `test_worker` function receives the test name and should return either:
120138

121139
If your package needs to accept its own command-line arguments in addition to `ParallelTestRunner`'s options, use [`parse_args`](@ref) with custom flags:
122140

123-
```julia
141+
```@example mypackage
124142
using ParallelTestRunner
143+
using MyPackage
125144
126145
# Parse arguments with custom flags
127146
args = parse_args(ARGS; custom=["myflag", "another-flag"])
@@ -132,10 +151,12 @@ if args.custom["myflag"] !== nothing
132151
end
133152
134153
# Pass parsed args to runtests
154+
cd(test_dir) do # hide
135155
runtests(MyPackage, args)
156+
end # hide
136157
```
137158

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).
139160

140161
## Interactive use
141162

@@ -146,11 +167,11 @@ For example, here is how we could run the subset of test files that start with t
146167
# Start julia in an environment where `MyPackage.jl` is available
147168
julia --project
148169
```
149-
```julia-repl
150-
julia> using Pkg
170+
```@repl mypackage
171+
using Pkg
151172
152173
# No need to start a fresh session to change threading
153-
julia> Pkg.test("MyModule"; test_args=`--verbose test_cool_feature`, julia_args=`--threads=auto`);
174+
Pkg.test("MyPackage"; test_args=`--verbose advanced`, julia_args=`--threads=auto`);
154175
```
155176

156177
Alternatively, arguments can be passed directly from the command line with a shell alias like the one below:

docs/src/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ DocTestSetup = quote
77
end
88
```
99

10+
```@setup mypackage
11+
using ParallelTestRunner
12+
using MyPackage
13+
test_dir = joinpath(pkgdir(ParallelTestRunner), "docs", "MyPackage", "test")
14+
```
15+
1016
[ParallelTestRunner.jl](https://github.com/JuliaTesting/ParallelTestRunner.jl) is a simple parallel test runner for Julia tests with automatic test discovery.
1117
It runs each test file concurrently in isolated worker processes, providing real-time progress output and efficient resource management.
1218

@@ -19,11 +25,13 @@ It runs each test file concurrently in isolated worker processes, providing real
1925

2026
2. **Update your `test/runtests.jl`**:
2127

22-
```julia
28+
```@example mypackage
2329
using MyPackage
2430
using ParallelTestRunner
2531
32+
cd(test_dir) do # hide
2633
runtests(MyPackage, ARGS)
34+
end # hide
2735
```
2836

2937
That's it! `ParallelTestRunner` will automatically:
@@ -108,14 +116,6 @@ The test runner provides real-time output showing:
108116
- Memory allocation
109117
- RSS (Resident Set Size) memory usage
110118

111-
Example output:
112-
113-
```
114-
Test | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB) |
115-
basic (1) | 0.12 | 0.01 | 8.3 | 5.23 | 125.45 |
116-
integration (2) | 2.45 | 0.15 | 6.1 | 45.67 | 234.12 |
117-
```
118-
119119
### Graceful Interruption
120120

121121
Press `Ctrl+C` to interrupt the test run. The framework will:

src/ParallelTestRunner.jl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,29 +679,49 @@ Several keyword arguments are also supported:
679679
680680
## Examples
681681
682+
Run all tests with default settings (auto-discovers `.jl` files)
683+
684+
```julia
685+
using ParallelTestRunner
686+
using MyPackage
687+
688+
runtests(MyPackage, ARGS)
689+
```
690+
691+
Run only tests matching "integration" (matched with `startswith`):
682692
```julia
683-
# Run all tests with default settings (auto-discovers .jl files)
684-
runtests(MyModule, ARGS)
693+
using ParallelTestRunner
694+
using MyPackage
695+
696+
runtests(MyPackage, ["integration"])
697+
```
685698
686-
# Run only tests matching "integration"
687-
runtests(MyModule, ["integration"])
699+
Define a custom test suite
700+
```julia
701+
using ParallelTestRunner
702+
using MyPackage
688703
689-
# Define a custom test suite
690704
testsuite = Dict(
691705
"custom" => quote
692706
@test 1 + 1 == 2
693707
end
694708
)
695-
runtests(MyModule, ARGS; testsuite)
696709
697-
# Customize the test suite
710+
runtests(MyPackage, ARGS; testsuite)
711+
```
712+
713+
Customize the test suite
714+
```julia
715+
using ParallelTestRunner
716+
using MyPackage
717+
698718
testsuite = find_tests(pwd())
699719
args = parse_args(ARGS)
700720
if filter_tests!(testsuite, args)
701721
# Remove a specific test
702722
delete!(testsuite, "slow_test")
703723
end
704-
runtests(MyModule, args; testsuite)
724+
runtests(MyPackage, args; testsuite)
705725
```
706726
707727
## Memory Management

0 commit comments

Comments
 (0)