From 5ed825c1735352666ec7f2426add171c5b52c1d4 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 9 Dec 2024 13:48:25 -0500 Subject: [PATCH] Add functionality for loading setup code --- templates/test/test/runtests.jl | 19 ++++++++++++++----- test/runtests.jl | 19 ++++++++++++++----- test/setup/Setup.jl | 5 +++++ test/test_setupmodule.jl | 4 ++++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 test/setup/Setup.jl create mode 100644 test/test_setupmodule.jl diff --git a/templates/test/test/runtests.jl b/templates/test/test/runtests.jl index 1140eea..ea5fe07 100644 --- a/templates/test/test/runtests.jl +++ b/templates/test/test/runtests.jl @@ -13,6 +13,16 @@ const GROUP = uppercase( end, ) +# define paths +testdir = @__DIR__ +testsetupdir = joinpath(testdir, "setup/") +exampledir = joinpath(@__DIR__, "..", "examples/") +examplesetupdir = joinpath(exampledir, "setup/") + +# Load setup code into path, so `using SetupModule` works +isdir(testsetupdir) && push!(LOAD_PATH, testsetupdir) +isdir(examplesetupdir) && push!(LOAD_PATH, examplesetupdir) + function istestfile(filename) return isfile(filename) && endswith(filename, ".jl") && @@ -21,9 +31,9 @@ end @time begin # tests in groups based on folder structure - for testgroup in filter(isdir, readdir(@__DIR__)) + for testgroup in filter(isdir, readdir(testdir)) if GROUP == "ALL" || GROUP == uppercase(testgroup) - for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) + for file in filter(istestfile, readdir(joinpath(testdir, testgroup); join=true)) @eval @safetestset $file begin include($file) end @@ -32,7 +42,7 @@ end end # single files in top folder - for file in filter(istestfile, readdir(@__DIR__)) + for file in filter(istestfile, readdir(testdir)) (file == basename(@__FILE__)) && continue @eval @safetestset $file begin include($file) @@ -40,8 +50,7 @@ end end # test examples - examplepath = joinpath(@__DIR__, "..", "examples") - for file in filter(endswith(".jl"), readdir(examplepath; join=true)) + for file in filter(endswith(".jl"), readdir(exampledir; join=true)) filename = basename(file) @eval begin @safetestset $filename begin diff --git a/test/runtests.jl b/test/runtests.jl index 1140eea..ea5fe07 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,6 +13,16 @@ const GROUP = uppercase( end, ) +# define paths +testdir = @__DIR__ +testsetupdir = joinpath(testdir, "setup/") +exampledir = joinpath(@__DIR__, "..", "examples/") +examplesetupdir = joinpath(exampledir, "setup/") + +# Load setup code into path, so `using SetupModule` works +isdir(testsetupdir) && push!(LOAD_PATH, testsetupdir) +isdir(examplesetupdir) && push!(LOAD_PATH, examplesetupdir) + function istestfile(filename) return isfile(filename) && endswith(filename, ".jl") && @@ -21,9 +31,9 @@ end @time begin # tests in groups based on folder structure - for testgroup in filter(isdir, readdir(@__DIR__)) + for testgroup in filter(isdir, readdir(testdir)) if GROUP == "ALL" || GROUP == uppercase(testgroup) - for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) + for file in filter(istestfile, readdir(joinpath(testdir, testgroup); join=true)) @eval @safetestset $file begin include($file) end @@ -32,7 +42,7 @@ end end # single files in top folder - for file in filter(istestfile, readdir(@__DIR__)) + for file in filter(istestfile, readdir(testdir)) (file == basename(@__FILE__)) && continue @eval @safetestset $file begin include($file) @@ -40,8 +50,7 @@ end end # test examples - examplepath = joinpath(@__DIR__, "..", "examples") - for file in filter(endswith(".jl"), readdir(examplepath; join=true)) + for file in filter(endswith(".jl"), readdir(exampledir; join=true)) filename = basename(file) @eval begin @safetestset $filename begin diff --git a/test/setup/Setup.jl b/test/setup/Setup.jl new file mode 100644 index 0000000..8724864 --- /dev/null +++ b/test/setup/Setup.jl @@ -0,0 +1,5 @@ +module Setup + +const dummy_true = true + +end diff --git a/test/test_setupmodule.jl b/test/test_setupmodule.jl new file mode 100644 index 0000000..02dd1de --- /dev/null +++ b/test/test_setupmodule.jl @@ -0,0 +1,4 @@ +using Setup, Test + +# simple stub test to see if setup code was loaded correctly +@test Setup.dummy_true