Skip to content

Commit fc0d624

Browse files
committed
doc: add "Quick start" section
1 parent f72de2b commit fc0d624

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

docs/make.jl

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ makedocs(sitename = "ReTest.jl",
66

77
deploydocs(
88
repo = "github.com/JuliaTesting/ReTest.jl.git",
9+
push_preview = true,
910
)

docs/src/index.md

+104
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,110 @@ parent modules), say `M`, such that `M.runtests(...)` is equivalent to
5353
calling `retest(M, ...)`.
5454

5555

56+
## Quick start
57+
58+
Both `ReTest` and `InlineTest` are registered packages and can be installed
59+
the usual way. Let's create a package `MyPackage`, which is initially a
60+
single file located in a directory known to `LOAD_PATH`. We want to test
61+
its `greet` function, by writing tests directly in the same file;
62+
this is a use-case for `InlineTest`, which loads faster than `ReTest`:
63+
```julia
64+
# MyPackage.jl file
65+
66+
module MyPackage
67+
using InlineTest
68+
69+
greet() = "Hello World!"
70+
71+
@testset "greet" begin
72+
@test greet() == "Hello World!"
73+
end
74+
75+
end # module
76+
```
77+
78+
Now, in a Julia session, we load `MyPackage` and `ReTest` (needed to actually
79+
run the tests):
80+
```julia
81+
julia> using MyPackage, ReTest
82+
83+
julia> MyPackage.runtests()
84+
Pass
85+
MyPackage:
86+
greet | 1
87+
```
88+
89+
Suppose now that we organize `MyPackage` as a standard package, with
90+
a proper "runtests.jl" file. We can still keep testsets within "MyPackage.jl",
91+
while adding more thorough tests in the "test" folder, which can contain
92+
two files, "runtests.jl" and "MyPackageTests.jl":
93+
```julia
94+
# MyPackage/test/runtests.jl file
95+
96+
using ReTest, MyPackage
97+
include("MyPackageTests.jl")
98+
99+
# when including this file (e.g. with `Pkg.test`), all the tests
100+
# in both modules will be run:
101+
102+
retest(MyPackage, MyPackageTests)
103+
```
104+
105+
```julia
106+
# MyPackage/test/MyPackageTests.jl file
107+
108+
module MyPackageTests
109+
using MyPackage, ReTest
110+
111+
@testset "more greet" begin
112+
@testset "concatenation" begin
113+
@test MyPackage.greet()^2 == "Hello World!Hello World!"
114+
end
115+
end
116+
117+
@testset "stuff" begin
118+
@test true
119+
end
120+
121+
end # module
122+
```
123+
124+
We can now load tests either via `using MyPackageTests`, if `LOAD_PATH` is configured
125+
appropriately, or via `include`, and run whichever tests we want:
126+
```julia
127+
julia> include("test/MyPackageTests.jl");
128+
129+
julia> using ReTest # to use the `retest` function
130+
131+
julia> retest(dry=true, verbose=2) # just list tests, showing nested ones
132+
MyPackage
133+
1| greet
134+
135+
Main.MyPackageTests
136+
1| more greet
137+
2| concatenation
138+
3| stuff
139+
140+
julia> retest("greet", verbose=2) # run only tests related to `greet()`
141+
Pass
142+
MyPackage:
143+
greet | 1
144+
145+
Main.MyPackageTests:
146+
more greet | 1
147+
concatenation | 1
148+
149+
Overall | 2
150+
151+
julia> MyPackageTests.runtests(3) # run only testset with ID 3 in MyPackageTests
152+
Pass
153+
Main.MyPackageTests:
154+
3| stuff | 1
155+
```
156+
157+
Here it is for basic usage!
158+
159+
56160
## API
57161

58162
```@meta

0 commit comments

Comments
 (0)