Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for loading setup code #41

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions templates/test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
isexamplefile(fn) =
endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")

@time begin
# tests in groups based on folder structure
Expand All @@ -33,24 +34,27 @@ 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
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
lkdvos marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
36 changes: 20 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,24 +34,27 @@ 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
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
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading