Skip to content

Commit f4507c6

Browse files
committed
small docs improvements
1 parent 1d5942b commit f4507c6

File tree

4 files changed

+67
-35
lines changed

4 files changed

+67
-35
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: CI
22
on:
33
- push
44
- pull_request
5+
56
jobs:
67
test:
78
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}

InlineTest/src/InlineTest.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ function retest end
4343
"""
4444
@testset args...
4545
46-
Similar to `Test.@testset args...`, but the contained tests are not run immediately,
47-
and are instead stored for later execution, triggered by `runtests()`.
46+
Similar to `Test.@testset args...`, but the contained tests are not run
47+
immediately, and are instead stored for later execution, triggered by
48+
`runtests()`.
4849
Invocations of `@testset` can be nested, but qualified invocations of
4950
`ReTest.@testset` can't.
50-
Internally, `@testset` invocations are converted to `Test.@testset` at execution time.
51+
Internally, `@testset` expressions are converted to an equivalent of
52+
`Test.@testset` at execution time.
5153
"""
5254
macro testset(args...)
5355
if !isdefined(__module__, :runtests)

docs/src/index.md

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ possible to use `ReTest` features without changing a line, e.g. on Julia's
3434
## Usage
3535

3636
The exported [`ReTest.@testset`](@ref) macro can be used as a direct
37-
replacement for `Test.@testset` (with limitations, see below), and `retest()`
38-
has to be called for the tests to be executed. See [`retest`](@ref)'s
39-
docstrings for more details. Moreover, `ReTest` re-exports (almost) all
40-
exported symbols from `Test`, so there should not be any need to import `Test`
41-
together with `ReTest`.
37+
replacement for `Test.@testset` (with limitations, [see below](@ref Caveats)),
38+
and `retest()` has to be called for the tests to be executed. See
39+
[`retest`](@ref)'s docstrings for more details. Moreover, `ReTest` re-exports
40+
(almost) all exported symbols from `Test`, so there should not be any need to
41+
import `Test` together with `ReTest`.
4242

4343
When using `@testset` "inline", i.e. within the source-code of a package, one
4444
can use the `InlineTest` package instead of `ReTest`, which only defines the
@@ -47,9 +47,9 @@ if `ReTest` itself loads fast, it can be desirable to have an even lighter
4747
dependency). But `ReTest` still has to be loaded (as a "test" dependency) in
4848
order to call `retest`.
4949

50-
Finally, for convenience, `@testset` also implicitly defines a `runtests`
51-
function within the enclosing module, say `M`, such that `M.runtests(...)` is
52-
equivalent to calling `retest(M, ...)`.
50+
Finally, for convenience, `ReTest.@testset` also implicitly defines a
51+
`runtests` function within the enclosing module, say `M`, such that
52+
`M.runtests(...)` is equivalent to calling `retest(M, ...)`.
5353

5454

5555
## `retest` and `@testset`
@@ -66,27 +66,29 @@ retest
6666

6767
## Caveats
6868

69-
`ReTest.@testset` comes with a couple of caveats/limitations:
69+
`ReTest.@testset` comes with a couple of caveats/limitations, some of which
70+
should be fixable:
7071

7172
* Toplevel testsets (which are not nested within other testsets), when run,
7273
are `eval`ed at the toplevel of their parent module, which means that they
73-
can't depend on local variables for example. This is probably the only
74-
fundamental limitation compared to `Test.@testset`, and might not be
75-
fixable.
74+
can't depend on local variables for example.
7675

7776
* "testsets-for" (`@testset "description" for ...`), when run, imply `eval`ing
78-
their loop variables at the toplevel of their parent module; moreover,
79-
"testsets-for" currently accept only "non-cartesian" looping (e.g. `for i=I,
80-
j=J` is not supported, PRs welcome :) ).
77+
their loop variables at the toplevel of their parent module; this implies
78+
that iteration expressions shouldn't depend on local variables (otherwise,
79+
the testset subject usually can't be known statically and the testset can't
80+
be filtered out with a `Regex`).
8181

82-
* Testsets can not be "custom testsets" (cf. `Test` documentation; this should
83-
be easy to support).
82+
* "testsets-for" currently accept only "non-cartesian" looping (e.g. `for i=I,
83+
j=J` is not supported, PRs welcome!)
84+
85+
* Testsets can not be "custom testsets" (cf. `Test` documentation).
8486

8587
* Nested testsets can't be "qualified" (i.e. written as `ReTest.@testset`).
8688

8789
* Regex filtering logic might improve in future versions, which means that
8890
with the same regex, less tests might be run (or more!). See
89-
[`retest`](@ref)'s docstring to know what testsets are guaranteed to run.
91+
[`retest`](@ref)'s docstring to know which testsets are guaranteed to run.
9092

9193
* Descriptions of testsets must be unique within a module, otherwise they are
9294
overwritten and a warning is issued, unless `Revise` is loaded; the reason
@@ -104,14 +106,16 @@ When used in a package `MyPackage`, the test code can be organized as follows:
104106
`include("tests.jl"); MyPackageTests.runtests()`
105107

106108
This means that running "runtests.jl" will have the same net effect as before.
107-
The "tests.jl" file can now be `include`d in your REPL session (`include("tests.jl")`),
108-
and you can run all or some of its tests
109-
(e.g. `MyPackageTests.runtests("addition")`).
110-
Wrapping the tests in `MyPackageTests` allows to not pollute `Main`, it keeps the tests
111-
of different packages separated, but more importantly, you can modify "tests.jl" and
112-
re-include it to have the corresponding tests updated (otherwise, without
113-
a `MyPackageTests` module, including the file a second time would add the new tests
114-
without removing the old ones).
109+
The "tests.jl" file can now be `include`d in your REPL session
110+
(`include("tests.jl")`), and you can run all or some of its tests (e.g.
111+
`MyPackageTests.runtests("addition")`).
112+
113+
Wrapping the tests in `MyPackageTests` allows to not pollute `Main` and keeps
114+
the tests of different packages separated. Also, you can
115+
modify "tests.jl" and re-include it to have the corresponding tests updated
116+
(the `MyPackageTests` module is replaced in `Main`);
117+
otherwise, without a `MyPackageTests` module, including the file a second
118+
time currently triggers a warning for each overwritten toplevel testset.
115119

116120

117121
## Filtering
@@ -135,6 +139,24 @@ instead of `@test true`, it could be useful to wrap it in its own testset, so th
135139
it can be filtered out.
136140

137141

142+
## Running tests in parallel with `Distributed`
143+
144+
Currently, the tests are automatically run in parallel whenever there are
145+
multiple workers, which have to be set manually. The workflow looks like:
146+
```julia
147+
using Distributed
148+
addprocs(2)
149+
@everywhere include("test/tests.jl")
150+
MyPackageTests.runtests()
151+
```
152+
153+
It should be relatively easy to support threaded execution of testsets (it was
154+
actually implemented at one point). But it often happens that compiling
155+
package code and testset code (which currently is not threaded) takes quite
156+
more time than actually running the code, in which case using `Distributed`
157+
has more tangible benefits.
158+
159+
138160
## Working with `Revise`
139161

140162
When `Revise` is loaded and a testset is updated, `ReTest` will observe that a
@@ -169,7 +191,7 @@ end
169191
## Working with test files which use `Test`
170192

171193
It's sometimes possible to use `ReTest` features on a test code base which
172-
uses `Test`:
194+
uses `Test`, without modifications:
173195

174196
- if you have a package `Package`, you can try `ReTest.hijack(Package)`, which
175197
will define a `PackageTests` module when successful, on which you can call

src/ReTest.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,23 @@ end
809809
"""
810810
ReTest.hijack(source, [modname]; parentmodule::Module=Main)
811811
812-
Given test files defined in `source` using the `Test` package,
813-
try to load them by replacing `Test` with `ReTest`, wrapping them in a module `modname`
814-
defined withing `parentmodule`. If successful, the newly created module `modname` is
815-
returned and `modname.runtests()` should be callable.
812+
Given test files defined in `source` using the `Test` package, try to load
813+
them by replacing `Test` with `ReTest`, wrapping them in a module `modname`
814+
defined within `parentmodule`. If successful, the newly created module
815+
`modname` is returned and `modname.runtests()` should be callable.
816816
817817
If `source::AbstractString`, then it's interpreted as the top level test file
818-
(possibly including other files).
818+
(possibly including other files), and `modname` defaults to an arbitrary name.
819+
819820
If `source::Module`, then it's interpreted as the name of a package, and the
820821
"test/runtests.jl" file from this package is loaded. In this case, `modname`
821822
defaults to `Symbol(source, :Tests)`.
823+
824+
The current procedure is as follows:
825+
1. replace toplevel `using Test` occurrences by `using ReTest` (`using` can
826+
have multiple arguments);
827+
2. apply recursively these two rules for all `include`d files, provided
828+
the `include` statement is at the toplevel.
822829
"""
823830
function hijack end
824831

0 commit comments

Comments
 (0)