Skip to content

Commit 7ae6758

Browse files
committed
Restore runtests
1 parent cb33694 commit 7ae6758

5 files changed

Lines changed: 79 additions & 69 deletions

File tree

Project.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1414
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1515
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1616
Runic = "62bfec6d-59d7-401d-8490-b29ee721c001"
17-
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
18-
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1917
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
2018
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
2119

@@ -27,8 +25,6 @@ Logging = "1.10"
2725
OrderedCollections = "1.8.1"
2826
PrecompileTools = "1"
2927
Runic = "1.5.1"
30-
SafeTestsets = "0.1"
31-
Suppressor = "0.2"
3228
TOML = "1.0.3"
3329
YAML = "0.4.16"
3430
julia = "1.10"

src/ITensorFormatter.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ITensorFormatter
22

33
if VERSION >= v"1.11.0-DEV.469"
4-
let str = "public ITensorPkgFormatter, generate_readme!, generate_readmes!, main, make_index!, make_readme!, runtests"
4+
let str = "public ITensorPkgFormatter, main, make_index!, make_readme!"
55
eval(Meta.parse(str))
66
end
77
end

src/generate_readme.jl

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Literate: Literate
2-
using SafeTestsets: @safetestset
3-
using Suppressor: @suppress
42

53
_pkgroot(pkg::Module) = pkgdir(pkg)
64
_pkgroot(pkg::AbstractString) = pkg
@@ -109,63 +107,3 @@ function generate_readme!(path::AbstractString)
109107
end
110108
return nothing
111109
end
112-
113-
function _istestfile(path::AbstractString)
114-
fn = basename(path)
115-
return endswith(fn, ".jl") && startswith(basename(fn), "test_") &&
116-
!contains(fn, "setup")
117-
end
118-
119-
function _isexamplefile(path::AbstractString)
120-
fn = basename(path)
121-
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
122-
end
123-
124-
function _group(; args = ARGS, env = ENV)
125-
pat = r"(?:--group=)(\w+)"
126-
arg_id = findfirst(contains(pat), args)
127-
return uppercase(
128-
if isnothing(arg_id)
129-
arg = get(env, "GROUP", "ALL")
130-
arg == "" ? "ALL" : arg
131-
else
132-
only(match(pat, args[arg_id]).captures)
133-
end
134-
)
135-
end
136-
137-
function runtests(; testdir = @__DIR__, args = ARGS, env = ENV)
138-
group = _group(; args, env)
139-
@time begin
140-
for testgroup in filter(isdir, readdir(testdir; join = true))
141-
if group == "ALL" || group == uppercase(basename(testgroup))
142-
for filename in filter(_istestfile, readdir(testgroup; join = true))
143-
@eval @safetestset $(basename(filename)) begin
144-
include($filename)
145-
end
146-
end
147-
end
148-
end
149-
150-
for file in filter(_istestfile, readdir(testdir; join = true))
151-
(basename(file) == "runtests.jl") && continue
152-
@eval @safetestset $(basename(file)) begin
153-
include($file)
154-
end
155-
end
156-
157-
examplepath = joinpath(testdir, "..", "examples")
158-
if isdir(examplepath)
159-
for (root, _, files) in walkdir(examplepath)
160-
contains(chopprefix(root, testdir), "setup") && continue
161-
for file in filter(_isexamplefile, files)
162-
filename = joinpath(root, file)
163-
@eval @safetestset $file begin
164-
@suppress include($filename)
165-
end
166-
end
167-
end
168-
end
169-
end
170-
return nothing
171-
end

test/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
33
ITensorFormatter = "b6bf39f1-c9d3-4bad-aad8-593d802f65fd"
44
JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4"
5+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
6+
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
57
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
68

79
[sources.ITensorFormatter]
@@ -11,4 +13,6 @@ path = ".."
1113
Aqua = "0.8"
1214
ITensorFormatter = "0.2"
1315
JuliaSyntax = "0.4.10, 1"
16+
SafeTestsets = "0.1"
17+
Suppressor = "0.2"
1418
Test = "1.10"

test/runtests.jl

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,75 @@
1-
using ITensorFormatter: ITensorFormatter
1+
using SafeTestsets: @safetestset
2+
using Suppressor: Suppressor
23

3-
ITensorFormatter.runtests(; testdir = @__DIR__, args = ARGS)
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+
arg = get(ENV, "GROUP", "ALL")
11+
# For some reason `ENV["GROUP"]` is set to `""`
12+
# when running via GitHub Actions, so handle that case:
13+
arg == "" ? "ALL" : arg
14+
else
15+
only(match(pat, ARGS[arg_id]).captures)
16+
end
17+
)
18+
19+
"""
20+
match files of the form `test_*.jl`, but exclude `*setup*.jl`
21+
"""
22+
function istestfile(path)
23+
fn = basename(path)
24+
return endswith(fn, ".jl") && startswith(basename(fn), "test_") &&
25+
!contains(fn, "setup")
26+
end
27+
"""
28+
match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`
29+
"""
30+
function isexamplefile(path)
31+
fn = basename(path)
32+
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
33+
end
34+
35+
@time begin
36+
# tests in groups based on folder structure
37+
for testgroup in filter(isdir, readdir(@__DIR__; join = true))
38+
if GROUP == "ALL" || GROUP == uppercase(basename(testgroup))
39+
for filename in filter(istestfile, readdir(testgroup; join = true))
40+
@eval @safetestset $(basename(filename)) begin
41+
include($filename)
42+
end
43+
end
44+
end
45+
end
46+
47+
# single files in top folder
48+
for file in filter(istestfile, readdir(@__DIR__; join = true))
49+
(basename(file) == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
50+
@eval @safetestset $(basename(file)) begin
51+
include($file)
52+
end
53+
end
54+
55+
# test examples
56+
examplepath = joinpath(@__DIR__, "..", "examples")
57+
for (root, _, files) in walkdir(examplepath)
58+
contains(chopprefix(root, @__DIR__), "setup") && continue
59+
for file in filter(isexamplefile, files)
60+
filename = joinpath(root, file)
61+
@eval begin
62+
@safetestset $file begin
63+
$(
64+
Expr(
65+
:macrocall,
66+
GlobalRef(Suppressor, Symbol("@suppress")),
67+
LineNumberNode(@__LINE__, @__FILE__),
68+
:(include($filename))
69+
)
70+
)
71+
end
72+
end
73+
end
74+
end
75+
end

0 commit comments

Comments
 (0)