Skip to content

Commit ed0f74f

Browse files
authored
Add support for custom tests. (#6)
1 parent 637a241 commit ed0f74f

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
@@ -214,15 +214,21 @@ function default_njobs(; cpu_threads = Sys.CPU_THREADS, free_memory = Sys.free_m
214214
end
215215

216216
"""
217-
runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
217+
runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord, custom_tests = Dict())
218218
219219
Run Julia tests in parallel across multiple worker processes.
220220
221221
## Arguments
222222
223-
- `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
223+
The primary argument is a command line arguments array, typically from `Base.ARGS`. When you
224+
run the tests with `Pkg.test`, this can be changed with the `test_args` keyword argument.
225+
226+
Several keyword arguments are also supported:
227+
224228
- `testfilter`: Optional function to filter which tests to run (default: run all tests)
225229
- `RecordType`: Type of test record to use for tracking test results (default: `TestRecord`)
230+
- `custom_tests`: Optional dictionary of custom tests, mapping test names to a zero-argument
231+
function
226232
227233
## Command Line Options
228234
@@ -235,7 +241,8 @@ Run Julia tests in parallel across multiple worker processes.
235241
236242
## Behavior
237243
238-
- Automatically discovers all `.jl` files in the test directory (excluding `setup.jl` and `runtests.jl`)
244+
- Automatically discovers all `.jl` files in the test directory (excluding `setup.jl` and
245+
`runtests.jl`)
239246
- Sorts tests by file size (largest first) for load balancing
240247
- Launches worker processes with appropriate Julia flags for testing
241248
- Monitors memory usage and recycles workers that exceed memory limits
@@ -261,11 +268,11 @@ runtests(ARGS, Returns(true), MyCustomTestRecord)
261268
262269
## Memory Management
263270
264-
Workers are automatically recycled when they exceed memory limits to prevent
265-
out-of-memory issues during long test runs. The memory limit is set based on
266-
system architecture.
271+
Workers are automatically recycled when they exceed memory limits to prevent out-of-memory
272+
issues during long test runs. The memory limit is set based on system architecture.
267273
"""
268-
function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
274+
function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
275+
custom_tests::Dict{String}=Dict{String}())
269276
do_help, _ = extract_flag!(ARGS, "--help")
270277
if do_help
271278
println(
@@ -297,6 +304,11 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
297304
# choose tests
298305
tests = []
299306
test_runners = Dict()
307+
## custom tests by the user
308+
for (name, runner) in custom_tests
309+
push!(tests, name)
310+
test_runners[name] = runner
311+
end
300312
## files in the test folder
301313
for (rootpath, dirs, files) in walkdir(WORKDIR)
302314
# find Julia files
@@ -325,7 +337,7 @@ function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
325337

326338
append!(tests, files)
327339
for file in files
328-
test_runners[file] = joinpath(WORKDIR, file * ".jl")
340+
test_runners[file] = ()->Main.include(joinpath(WORKDIR, file * ".jl"))
329341
end
330342
end
331343
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)