Skip to content

Commit 90a6c00

Browse files
committed
Add support for custom tests.
1 parent 9106148 commit 90a6c00

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/ParallelTestRunner.jl

Lines changed: 21 additions & 9 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
@@ -201,15 +201,21 @@ function runtest(::Type{TestRecord}, f, name)
201201
end
202202

203203
"""
204-
runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
204+
runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord, custom_tests = Dict())
205205
206206
Run Julia tests in parallel across multiple worker processes.
207207
208208
## Arguments
209209
210-
- `ARGS`: Command line arguments array, typically from `Base.ARGS`. When you run the tests with `Pkg.test`, this can be changed with the `test_args` keyword argument
210+
The primary argument is a command line arguments array, typically from `Base.ARGS`. When you
211+
run the tests with `Pkg.test`, this can be changed with the `test_args` keyword argument.
212+
213+
Several keyword arguments are also supported:
214+
211215
- `testfilter`: Optional function to filter which tests to run (default: run all tests)
212216
- `RecordType`: Type of test record to use for tracking test results (default: `TestRecord`)
217+
- `custom_tests`: Optional dictionary of custom tests, mapping test names to a zero-argument
218+
function
213219
214220
## Command Line Options
215221
@@ -222,7 +228,8 @@ Run Julia tests in parallel across multiple worker processes.
222228
223229
## Behavior
224230
225-
- Automatically discovers all `.jl` files in the test directory (excluding `setup.jl` and `runtests.jl`)
231+
- Automatically discovers all `.jl` files in the test directory (excluding `setup.jl` and
232+
`runtests.jl`)
226233
- Sorts tests by file size (largest first) for load balancing
227234
- Launches worker processes with appropriate Julia flags for testing
228235
- Monitors memory usage and recycles workers that exceed memory limits
@@ -248,11 +255,11 @@ runtests(ARGS, Returns(true), MyCustomTestRecord)
248255
249256
## Memory Management
250257
251-
Workers are automatically recycled when they exceed memory limits to prevent
252-
out-of-memory issues during long test runs. The memory limit is set based on
253-
system architecture.
258+
Workers are automatically recycled when they exceed memory limits to prevent out-of-memory
259+
issues during long test runs. The memory limit is set based on system architecture.
254260
"""
255-
function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
261+
function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
262+
custom_tests::Dict{String}=Dict{String}())
256263
do_help, _ = extract_flag!(ARGS, "--help")
257264
if do_help
258265
println(
@@ -284,6 +291,11 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
284291
# choose tests
285292
tests = []
286293
test_runners = Dict()
294+
## custom tests by the user
295+
for (name, runner) in custom_tests
296+
push!(tests, name)
297+
test_runners[name] = runner
298+
end
287299
## files in the test folder
288300
for (rootpath, dirs, files) in walkdir(WORKDIR)
289301
# find Julia files
@@ -312,7 +324,7 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
312324

313325
append!(tests, files)
314326
for file in files
315-
test_runners[file] = joinpath(WORKDIR, file * ".jl")
327+
test_runners[file] = ()->Main.include(joinpath(WORKDIR, file * ".jl"))
316328
end
317329
end
318330
sort!(tests; by = (file) -> stat(joinpath(WORKDIR, file * ".jl")).size, rev = true)

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)