From 5869703de41404d9f5cd98a79c1cdf75ad76685f Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 9 Dec 2024 13:48:25 -0500 Subject: [PATCH 1/3] Add functionality for setup Revert "Add functionality for loading setup code" This reverts commit 5ed825c1735352666ec7f2426add171c5b52c1d4. setup file logic --- templates/test/test/runtests.jl | 36 ++++++++++++++++++--------------- test/runtests.jl | 36 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/templates/test/test/runtests.jl b/templates/test/test/runtests.jl index 1140eea..a058468 100644 --- a/templates/test/test/runtests.jl +++ b/templates/test/test/runtests.jl @@ -13,11 +13,12 @@ const GROUP = uppercase( end, ) -function istestfile(filename) - return isfile(filename) && - endswith(filename, ".jl") && - startswith(basename(filename), "test") -end +"match files of the form `test_*.jl`, but exclude `*setup*.jl`" +istestfile(fn) = + endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") +"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" +isexamplefile(fn) = + endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") @time begin # tests in groups based on folder structure @@ -33,7 +34,7 @@ end # single files in top folder for file in filter(istestfile, readdir(@__DIR__)) - (file == basename(@__FILE__)) && continue + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion @eval @safetestset $file begin include($file) end @@ -41,16 +42,19 @@ end # test examples examplepath = joinpath(@__DIR__, "..", "examples") - for file in filter(endswith(".jl"), readdir(examplepath; join=true)) - filename = basename(file) - @eval begin - @safetestset $filename begin - $(Expr( - :macrocall, - GlobalRef(Suppressor, Symbol("@suppress")), - LineNumberNode(@__LINE__, @__FILE__), - :(include($file)), - )) + for (root, _, files) in walkdir(examplepath) + contains(root, "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 diff --git a/test/runtests.jl b/test/runtests.jl index 1140eea..a058468 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,11 +13,12 @@ const GROUP = uppercase( end, ) -function istestfile(filename) - return isfile(filename) && - endswith(filename, ".jl") && - startswith(basename(filename), "test") -end +"match files of the form `test_*.jl`, but exclude `*setup*.jl`" +istestfile(fn) = + endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") +"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" +isexamplefile(fn) = + endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") @time begin # tests in groups based on folder structure @@ -33,7 +34,7 @@ end # single files in top folder for file in filter(istestfile, readdir(@__DIR__)) - (file == basename(@__FILE__)) && continue + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion @eval @safetestset $file begin include($file) end @@ -41,16 +42,19 @@ end # test examples examplepath = joinpath(@__DIR__, "..", "examples") - for file in filter(endswith(".jl"), readdir(examplepath; join=true)) - filename = basename(file) - @eval begin - @safetestset $filename begin - $(Expr( - :macrocall, - GlobalRef(Suppressor, Symbol("@suppress")), - LineNumberNode(@__LINE__, @__FILE__), - :(include($file)), - )) + for (root, _, files) in walkdir(examplepath) + contains(root, "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 From a169328a9f4e6443cb4790a978991fd4ec35f40b Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 9 Dec 2024 16:34:34 -0500 Subject: [PATCH 2/3] correct for abspath filtercorrect for abspath filter --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index a058468..bd97441 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,7 +43,7 @@ isexamplefile(fn) = # test examples examplepath = joinpath(@__DIR__, "..", "examples") for (root, _, files) in walkdir(examplepath) - contains(root, "setup") && continue + contains(chopprefix(root, @__DIR__), "setup") && continue for file in filter(isexamplefile, files) filename = joinpath(root, file) @eval begin From 489179f740f0abe9ab5b4fbe28a9628b5ba4f776 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 9 Dec 2024 16:59:54 -0500 Subject: [PATCH 3/3] update template file --- templates/test/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/test/test/runtests.jl b/templates/test/test/runtests.jl index a058468..bd97441 100644 --- a/templates/test/test/runtests.jl +++ b/templates/test/test/runtests.jl @@ -43,7 +43,7 @@ isexamplefile(fn) = # test examples examplepath = joinpath(@__DIR__, "..", "examples") for (root, _, files) in walkdir(examplepath) - contains(root, "setup") && continue + contains(chopprefix(root, @__DIR__), "setup") && continue for file in filter(isexamplefile, files) filename = joinpath(root, file) @eval begin