Skip to content

Commit

Permalink
Add functionality for loading setup code
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 9, 2024
1 parent 478dbf0 commit 5ed825c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
19 changes: 14 additions & 5 deletions templates/test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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") &&
Expand All @@ -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
Expand All @@ -32,16 +42,15 @@ 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)
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
Expand Down
19 changes: 14 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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") &&
Expand All @@ -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
Expand All @@ -32,16 +42,15 @@ 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)
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
Expand Down
5 changes: 5 additions & 0 deletions test/setup/Setup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Setup

const dummy_true = true

end
4 changes: 4 additions & 0 deletions test/test_setupmodule.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Setup, Test

# simple stub test to see if setup code was loaded correctly
@test Setup.dummy_true

0 comments on commit 5ed825c

Please sign in to comment.