11using SafeTestsets: @safetestset
2- using Suppressor: @suppress
3- using Test: @testset
2+ using Suppressor: Suppressor
43
5- @testset " DerivableInterfaces.jl tests" begin
6- # check for filtered groups
7- # either via `--group=ALL` or through ENV["GROUP"]
8- pat = r" (?:--group=)(\w +)"
9- arg_id = findfirst (contains (pat), ARGS )
10- GROUP = uppercase (
11- if isnothing (arg_id)
12- get (ENV , " GROUP" , " ALL" )
13- else
14- only (match (pat, ARGS [arg_id]). captures)
15- end ,
16- )
4+ # check for filtered groups
5+ # either via `--group=ALL` or through ENV["GROUP"]
6+ const pat = r" (?:--group=)(\w +)"
7+ arg_id = findfirst (contains (pat), ARGS )
8+ const GROUP = uppercase (
9+ if isnothing (arg_id)
10+ get (ENV , " GROUP" , " ALL" )
11+ else
12+ only (match (pat, ARGS [arg_id]). captures)
13+ end ,
14+ )
1715
18- function istestfile (filename)
19- return isfile (filename) &&
20- endswith (filename, " .jl" ) &&
21- startswith (basename (filename), " test" )
22- end
16+ " match files of the form `test_*.jl`, but exclude `*setup*.jl`"
17+ istestfile (fn) =
18+ endswith (fn, " .jl" ) && startswith (basename (fn), " test_" ) && ! contains (fn, " setup" )
19+ " match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`"
20+ isexamplefile (fn) =
21+ endswith (fn, " .jl" ) && ! endswith (fn, " _notest.jl" ) && ! contains (fn, " setup" )
2322
23+ @time begin
2424 # tests in groups based on folder structure
2525 for testgroup in filter (isdir, readdir (@__DIR__ ))
2626 if GROUP == " ALL" || GROUP == uppercase (testgroup)
2727 for file in filter (istestfile, readdir (joinpath (@__DIR__ , testgroup); join= true ))
28- @eval @safetestset $ file begin
28+ @eval @safetestset $ ( last ( splitdir ( file))) begin
2929 include ($ file)
3030 end
3131 end
@@ -34,17 +34,28 @@ using Test: @testset
3434
3535 # single files in top folder
3636 for file in filter (istestfile, readdir (@__DIR__ ))
37- (file == basename (@__FILE__ )) && continue
37+ (file == basename (@__FILE__ )) && continue # exclude this file to avoid infinite recursion
3838 @eval @safetestset $ file begin
3939 include ($ file)
4040 end
4141 end
4242
4343 # test examples
4444 examplepath = joinpath (@__DIR__ , " .." , " examples" )
45- for file in filter (endswith (" .jl" ), readdir (examplepath; join= true ))
46- @suppress @eval @safetestset $ file begin
47- include ($ file)
45+ for (root, _, files) in walkdir (examplepath)
46+ contains (chopprefix (root, @__DIR__ ), " setup" ) && continue
47+ for file in filter (isexamplefile, files)
48+ filename = joinpath (root, file)
49+ @eval begin
50+ @safetestset $ file begin
51+ $ (Expr (
52+ :macrocall ,
53+ GlobalRef (Suppressor, Symbol (" @suppress" )),
54+ LineNumberNode (@__LINE__ , @__FILE__ ),
55+ :(include ($ filename)),
56+ ))
57+ end
58+ end
4859 end
4960 end
5061end
0 commit comments