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

Split tests into groups + SafeTestsets #30

Merged
merged 13 commits into from
Dec 4, 2024
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ Git_jll = "2.46.2"
LibGit2 = "1.10"
PkgSkeleton = "1.3.1"
Preferences = "1.4.3"
SafeTestsets = "0.1"
Suppressor = "0.2.8"
Test = "1.10"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test"]
test = ["Aqua", "Test", "SafeTestsets"]
6 changes: 5 additions & 1 deletion templates/project/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ version = "0.1.0"

[compat]
Aqua = "0.8.9"
SafeTestsets = "0.1"
Suppressor = "0.2"
Test = "1.10"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

[targets]
test = ["Aqua", "Test"]
test = ["Aqua", "Test", "Suppressor", "SafeTestsets"]
5 changes: 0 additions & 5 deletions templates/test/test/Project.toml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@eval module $(gensym())
using {PKGNAME}: {PKGNAME}
using Test: @test, @testset

@testset "{PKGNAME}" begin
# Tests go here.
end
end
40 changes: 32 additions & 8 deletions templates/test/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
@eval module $(gensym())
using Test: @testset
using SafeTestsets
using Suppressor: @suppress
lkdvos marked this conversation as resolved.
Show resolved Hide resolved

@testset "{PKGNAME}.jl" begin
filenames = filter(readdir(@__DIR__)) do f
startswith("test_")(f) && endswith(".jl")(f)
# check for filtered groups
# either via `--group=ALL` or through ENV["GROUP"]
const pat = r"(?:--group=)(\w+)"
arg_id = findfirst(contains(pat), ARGS)
const GROUP = uppercase(
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
)

@time begin
# tests in groups based on folder structure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't @testset report times now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. could we achieve this by wrapping all of this in @testset or @safetestset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, I mostly copied this from my other workflows. I think the main difference is that @time also reports splits in compiletime/runtime, which I find interesting, but I have absolutely no preference about this.
Just as an aside, wrapping things in nested @testset structures makes it such that output is only printed after all tests finish. Not a big deal, but something to keep in mind.

for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
for file in readdir(joinpath(@__DIR__, testgroup); join=true)
@eval :(@safetestset($file, include(file)))
end
end
end
@testset "Test $filename" for filename in filenames
include(filename)

# single files in top folder
for file in filter(isfile, readdir(@__DIR__))
@eval :(@safetestset($file, include(file)))
end

# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for file in filter(endswith(".jl"), readdir(examplepath; join=true))
@eval :(@safetestset($file, @suppress include(file)))
end
end
end
2 changes: 0 additions & 2 deletions templates/test/test/test_aqua.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@eval module $(gensym())
using {PKGNAME}: {PKGNAME}
using Aqua: Aqua
using Test: @testset

@testset "Code quality (Aqua.jl)" begin
Aqua.test_all({PKGNAME})
end
end
15 changes: 0 additions & 15 deletions templates/test/test/test_examples.jl

This file was deleted.

6 changes: 0 additions & 6 deletions test/Project.toml

This file was deleted.

File renamed without changes.
40 changes: 32 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
@eval module $(gensym())
using Test: @testset
using SafeTestsets
using Suppressor: @suppress

@testset "ITensorPkgSkeleton.jl" begin
filenames = filter(readdir(@__DIR__)) do f
startswith("test_")(f) && endswith(".jl")(f)
# check for filtered groups
# either via `--group=ALL` or through ENV["GROUP"]
const pat = r"(?:--group=)(\w+)"
arg_id = findfirst(contains(pat), ARGS)
const GROUP = uppercase(
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
)

@time begin
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
for file in readdir(joinpath(@__DIR__, testgroup); join=true)
@eval :(@safetestset($file, include(file)))
end
end
end
@testset "Test $filename" for filename in filenames
include(filename)

# single files in top folder
for file in filter(isfile, readdir(@__DIR__))
@eval :(@safetestset($file, include(file)))
end

# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for file in filter(endswith(".jl"), readdir(examplepath; join=true))
@eval :(@safetestset($file, @suppress include(file)))
end
end
end
2 changes: 0 additions & 2 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@eval module $(gensym())
using ITensorPkgSkeleton: ITensorPkgSkeleton
using Aqua: Aqua
using Test: @testset

@testset "Code quality (Aqua.jl)" begin
Aqua.test_all(ITensorPkgSkeleton)
end
end
15 changes: 0 additions & 15 deletions test/test_examples.jl

This file was deleted.

Loading