|
1 | | -@eval module $(gensym()) |
2 | | -using Test: @testset |
| 1 | +using SafeTestsets: @safetestset |
| 2 | +using Suppressor: Suppressor |
3 | 3 |
|
4 | | -@testset "FusionTensors.jl" begin |
5 | | - filenames = filter(readdir(@__DIR__)) do f |
6 | | - startswith("test_")(f) && endswith(".jl")(f) |
| 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 | +) |
| 15 | + |
| 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") |
| 22 | + |
| 23 | +@time begin |
| 24 | + # tests in groups based on folder structure |
| 25 | + for testgroup in filter(isdir, readdir(@__DIR__)) |
| 26 | + if GROUP == "ALL" || GROUP == uppercase(testgroup) |
| 27 | + for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) |
| 28 | + @eval @safetestset $file begin |
| 29 | + include($file) |
| 30 | + end |
| 31 | + end |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + # single files in top folder |
| 36 | + for file in filter(istestfile, readdir(@__DIR__)) |
| 37 | + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion |
| 38 | + @eval @safetestset $file begin |
| 39 | + include($file) |
| 40 | + end |
7 | 41 | end |
8 | | - @testset "Test $filename" for filename in filenames |
9 | | - include(filename) |
| 42 | + |
| 43 | + # test examples |
| 44 | + examplepath = joinpath(@__DIR__, "..", "examples") |
| 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 |
| 59 | + end |
10 | 60 | end |
11 | 61 | end |
12 | | -end |
|
0 commit comments