Skip to content

Commit 635f294

Browse files
authored
Split tests into groups + SafeTestsets (#30)
1 parent 9bc0e97 commit 635f294

File tree

12 files changed

+98
-67
lines changed

12 files changed

+98
-67
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ Git_jll = "2.46.2"
2020
LibGit2 = "1.10"
2121
PkgSkeleton = "1.3.1"
2222
Preferences = "1.4.3"
23+
SafeTestsets = "0.1"
2324
Suppressor = "0.2.8"
2425
Test = "1.10"
2526
julia = "1.10"
2627

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

3133
[targets]
32-
test = ["Aqua", "Test"]
34+
test = ["Aqua", "Test", "SafeTestsets"]

templates/project/Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ version = "0.1.0"
55

66
[compat]
77
Aqua = "0.8.9"
8+
SafeTestsets = "0.1"
9+
Suppressor = "0.2"
810
Test = "1.10"
911
julia = "1.10"
1012

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

1519
[targets]
16-
test = ["Aqua", "Test"]
20+
test = ["Aqua", "Test", "Suppressor", "SafeTestsets"]

templates/test/test/Project.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
@eval module $(gensym())
21
using {PKGNAME}: {PKGNAME}
32
using Test: @test, @testset
43

54
@testset "{PKGNAME}" begin
65
# Tests go here.
76
end
8-
end

templates/test/test/runtests.jl

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
1-
@eval module $(gensym())
2-
using Test: @testset
1+
using SafeTestsets: @safetestset
2+
using Suppressor: @suppress
33

4-
@testset "{PKGNAME}.jl" begin
5-
filenames = filter(readdir(@__DIR__)) do f
6-
startswith("test_")(f) && endswith(".jl")(f)
4+
# check for filtered groups
5+
# either via `--group=ALL` or through ENV["GROUP"]
6+
const pat = r"(?:--group=)(\w+)"
7+
arg_id = findfirst(contains(pat), ARGS)
8+
const GROUP = uppercase(
9+
if isnothing(arg_id)
10+
get(ENV, "GROUP", "ALL")
11+
else
12+
only(match(pat, ARGS[arg_id]).captures)
13+
end,
14+
)
15+
16+
function istestfile(filename)
17+
return isfile(filename) &&
18+
endswith(filename, ".jl") &&
19+
startswith(basename(filename), "test")
20+
end
21+
22+
@time begin
23+
# tests in groups based on folder structure
24+
for testgroup in filter(isdir, readdir(@__DIR__))
25+
if GROUP == "ALL" || GROUP == uppercase(testgroup)
26+
for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true))
27+
@eval @safetestset $file begin
28+
include($file)
29+
end
30+
end
31+
end
732
end
8-
@testset "Test $filename" for filename in filenames
9-
include(filename)
33+
34+
# single files in top folder
35+
for file in filter(istestfile, readdir(@__DIR__))
36+
(file == basename(@__FILE__)) && continue
37+
@eval @safetestset $file begin
38+
include($file)
39+
end
40+
end
41+
42+
# test examples
43+
examplepath = joinpath(@__DIR__, "..", "examples")
44+
for file in filter(endswith(".jl"), readdir(examplepath; join=true))
45+
@suppress @eval @safetestset $file begin
46+
include($file)
47+
end
1048
end
11-
end
1249
end

templates/test/test/test_aqua.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
@eval module $(gensym())
21
using {PKGNAME}: {PKGNAME}
32
using Aqua: Aqua
43
using Test: @testset
54

65
@testset "Code quality (Aqua.jl)" begin
76
Aqua.test_all({PKGNAME})
87
end
9-
end

templates/test/test/test_examples.jl

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/Project.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/test_basics.jl renamed to test/basics/test_basics.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@eval module $(gensym())
21
using ITensorPkgSkeleton: ITensorPkgSkeleton
32
using Test: @test, @testset
43

@@ -43,4 +42,3 @@ using Test: @test, @testset
4342
end
4443
end
4544
end
46-
end

test/runtests.jl

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
1-
@eval module $(gensym())
2-
using Test: @testset
1+
using SafeTestsets: @safetestset
2+
using Suppressor: @suppress
33

4-
@testset "ITensorPkgSkeleton.jl" begin
5-
filenames = filter(readdir(@__DIR__)) do f
6-
startswith("test_")(f) && endswith(".jl")(f)
4+
# check for filtered groups
5+
# either via `--group=ALL` or through ENV["GROUP"]
6+
const pat = r"(?:--group=)(\w+)"
7+
arg_id = findfirst(contains(pat), ARGS)
8+
const GROUP = uppercase(
9+
if isnothing(arg_id)
10+
get(ENV, "GROUP", "ALL")
11+
else
12+
only(match(pat, ARGS[arg_id]).captures)
13+
end,
14+
)
15+
16+
function istestfile(filename)
17+
return isfile(filename) &&
18+
endswith(filename, ".jl") &&
19+
startswith(basename(filename), "test")
20+
end
21+
22+
@time begin
23+
# tests in groups based on folder structure
24+
for testgroup in filter(isdir, readdir(@__DIR__))
25+
if GROUP == "ALL" || GROUP == uppercase(testgroup)
26+
for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true))
27+
@eval @safetestset $file begin
28+
include($file)
29+
end
30+
end
31+
end
732
end
8-
@testset "Test $filename" for filename in filenames
9-
include(filename)
33+
34+
# single files in top folder
35+
for file in filter(istestfile, readdir(@__DIR__))
36+
(file == basename(@__FILE__)) && continue
37+
@eval @safetestset $file begin
38+
include($file)
39+
end
40+
end
41+
42+
# test examples
43+
examplepath = joinpath(@__DIR__, "..", "examples")
44+
for file in filter(endswith(".jl"), readdir(examplepath; join=true))
45+
@suppress @eval @safetestset $file begin
46+
include($file)
47+
end
1048
end
11-
end
1249
end

0 commit comments

Comments
 (0)