|
1 | | -@eval module $(gensym()) |
2 | | -using Test: @testset |
| 1 | +using SafeTestsets: @safetestset |
| 2 | +using Suppressor: @suppress |
3 | 3 |
|
4 | | -@testset "ITensorPkgSkeleton.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 | +function istestfile(filename) |
| 17 | + return isfile(filename) && |
| 18 | + endswith(filename, ".jl") && |
| 19 | + startswith(basename(filename), "test") |
| 20 | +end |
| 21 | + |
| 22 | +@time begin |
| 23 | + # tests in groups based on folder structure |
| 24 | + for testgroup in filter(isdir, readdir(@__DIR__)) |
| 25 | + if GROUP == "ALL" || GROUP == uppercase(testgroup) |
| 26 | + for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) |
| 27 | + @eval @safetestset $file begin |
| 28 | + include($file) |
| 29 | + end |
| 30 | + end |
| 31 | + end |
7 | 32 | end |
8 | | - @testset "Test $filename" for filename in filenames |
9 | | - include(filename) |
| 33 | + |
| 34 | + # single files in top folder |
| 35 | + for file in filter(istestfile, readdir(@__DIR__)) |
| 36 | + (file == basename(@__FILE__)) && continue |
| 37 | + @eval @safetestset $file begin |
| 38 | + include($file) |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + # test examples |
| 43 | + examplepath = joinpath(@__DIR__, "..", "examples") |
| 44 | + for file in filter(endswith(".jl"), readdir(examplepath; join=true)) |
| 45 | + @suppress @eval @safetestset $file begin |
| 46 | + include($file) |
| 47 | + end |
10 | 48 | end |
11 | | -end |
12 | 49 | end |
0 commit comments