|
1 | | -using ITensorFormatter: ITensorFormatter |
| 1 | +using SafeTestsets: @safetestset |
| 2 | +using Suppressor: Suppressor |
2 | 3 |
|
3 | | -ITensorFormatter.runtests(; testdir = @__DIR__, args = ARGS) |
| 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 | + arg = get(ENV, "GROUP", "ALL") |
| 11 | + # For some reason `ENV["GROUP"]` is set to `""` |
| 12 | + # when running via GitHub Actions, so handle that case: |
| 13 | + arg == "" ? "ALL" : arg |
| 14 | + else |
| 15 | + only(match(pat, ARGS[arg_id]).captures) |
| 16 | + end |
| 17 | +) |
| 18 | + |
| 19 | +""" |
| 20 | +match files of the form `test_*.jl`, but exclude `*setup*.jl` |
| 21 | +""" |
| 22 | +function istestfile(path) |
| 23 | + fn = basename(path) |
| 24 | + return endswith(fn, ".jl") && startswith(basename(fn), "test_") && |
| 25 | + !contains(fn, "setup") |
| 26 | +end |
| 27 | +""" |
| 28 | +match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl` |
| 29 | +""" |
| 30 | +function isexamplefile(path) |
| 31 | + fn = basename(path) |
| 32 | + return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") |
| 33 | +end |
| 34 | + |
| 35 | +@time begin |
| 36 | + # tests in groups based on folder structure |
| 37 | + for testgroup in filter(isdir, readdir(@__DIR__; join = true)) |
| 38 | + if GROUP == "ALL" || GROUP == uppercase(basename(testgroup)) |
| 39 | + for filename in filter(istestfile, readdir(testgroup; join = true)) |
| 40 | + @eval @safetestset $(basename(filename)) begin |
| 41 | + include($filename) |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + # single files in top folder |
| 48 | + for file in filter(istestfile, readdir(@__DIR__; join = true)) |
| 49 | + (basename(file) == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion |
| 50 | + @eval @safetestset $(basename(file)) begin |
| 51 | + include($file) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + # test examples |
| 56 | + examplepath = joinpath(@__DIR__, "..", "examples") |
| 57 | + for (root, _, files) in walkdir(examplepath) |
| 58 | + contains(chopprefix(root, @__DIR__), "setup") && continue |
| 59 | + for file in filter(isexamplefile, files) |
| 60 | + filename = joinpath(root, file) |
| 61 | + @eval begin |
| 62 | + @safetestset $file begin |
| 63 | + $( |
| 64 | + Expr( |
| 65 | + :macrocall, |
| 66 | + GlobalRef(Suppressor, Symbol("@suppress")), |
| 67 | + LineNumberNode(@__LINE__, @__FILE__), |
| 68 | + :(include($filename)) |
| 69 | + ) |
| 70 | + ) |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments