-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntests.jl
More file actions
72 lines (67 loc) · 2.21 KB
/
runtests.jl
File metadata and controls
72 lines (67 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using SafeTestsets: @safetestset
using Suppressor: Suppressor
# check for filtered groups
# either via `--group=ALL` or through ENV["GROUP"]
const pat = r"(?:--group=)(\w+)"
arg_id = findfirst(contains(pat), ARGS)
const GROUP = uppercase(
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end
)
"""
match files of the form `test_*.jl`, but exclude `*setup*.jl`
"""
function istestfile(fn)
return endswith(fn, ".jl") && startswith(basename(fn), "test_") &&
!contains(fn, "setup")
end
"""
match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`
"""
function isexamplefile(fn)
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
end
@time begin
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
groupdir = joinpath(@__DIR__, testgroup)
for file in filter(istestfile, readdir(groupdir))
filename = joinpath(groupdir, file)
@eval @safetestset $file begin
include($filename)
end
end
end
end
# single files in top folder
for file in filter(istestfile, readdir(@__DIR__))
(file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
@eval @safetestset $file begin
include($file)
end
end
# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for (root, _, files) in walkdir(examplepath)
contains(chopprefix(root, @__DIR__), "setup") && continue
for file in filter(isexamplefile, files)
filename = joinpath(root, file)
@eval begin
@safetestset $file begin
$(
Expr(
:macrocall,
GlobalRef(Suppressor, Symbol("@suppress")),
LineNumberNode(@__LINE__, @__FILE__),
:(include($filename))
)
)
end
end
end
end
end