Skip to content

Commit 0aa9742

Browse files
committed
Add support for custom tests.
1 parent 26ec179 commit 0aa9742

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/ParallelTestRunner.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function runtest(::Type{TestRecord}, f, name)
151151
Random.seed!(1)
152152

153153
res = @timed @testset $name begin
154-
Main.include($f)
154+
$f()
155155
end
156156
(res...,)
157157
end
@@ -200,7 +200,8 @@ function runtest(::Type{TestRecord}, f, name)
200200
return res
201201
end
202202

203-
function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
203+
function runtests(ARGS; testfilter = _ -> true, RecordType = TestRecord,
204+
custom_tests::Dict{String}=Dict{String}())
204205
do_help, _ = extract_flag!(ARGS, "--help")
205206
if do_help
206207
println(
@@ -232,6 +233,11 @@ function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
232233
# choose tests
233234
tests = []
234235
test_runners = Dict()
236+
## custom tests by the user
237+
for (name, runner) in custom_tests
238+
push!(tests, name)
239+
test_runners[name] = runner
240+
end
235241
## files in the test folder
236242
for (rootpath, dirs, files) in walkdir(WORKDIR)
237243
# find Julia files
@@ -260,10 +266,10 @@ function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
260266

261267
append!(tests, files)
262268
for file in files
263-
test_runners[file] = joinpath("$WORKDIR", "$file.jl")
269+
test_runners[file] = ()->Main.include(joinpath(WORKDIR, "$file.jl"))
264270
end
265271
end
266-
sort!(tests; by = (file) -> stat(joinpath("$WORKDIR", "$file.jl")).size, rev = true)
272+
sort!(tests; by = (file) -> stat(joinpath(WORKDIR, "$file.jl")).size, rev = true)
267273
## finalize
268274
unique!(tests)
269275

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ using ParallelTestRunner
22

33
pushfirst!(ARGS, "--verbose")
44

5-
runtests(ARGS)
5+
custom_tests = Dict(
6+
"whatever" => Returns(nothing)
7+
)
8+
9+
runtests(ARGS; custom_tests)

0 commit comments

Comments
 (0)