Skip to content

Commit f87561f

Browse files
authored
ParallelTestRunner.jl (#16)
This is a minor change to alter the tests to use the ParallelTestRunner.jl interface. To make this work, I also had to update the printing machinery slightly, since `string(x)` does not now about the context, so it would print types as if they are shown in the `Main` module, which doesn't necessarily have `AlgorithmsInterface` loaded. This became visible here since ParallelTestRunner starts new processes to really isolate the tests, therefore you can't really control what is visible in `Main` (and `@eval Main using AlgorithmsInterface` feels very wrong 😉 ) Let me know if the explanation is clear enough, I'm happy to include a small readme file in the tests as well if you think that could be helpful
1 parent 750916e commit f87561f

5 files changed

Lines changed: 34 additions & 32 deletions

File tree

src/stopping_criterion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function Base.show(io::IO, ::MIME"text/plain", stop_when_all::StopWhenAll)
156156
print(io, "StopWhenAll with the Stopping Criteria:")
157157
for stopping_criterion in stop_when_all.criteria
158158
print(io, "\n ")
159-
replace(io, string(stopping_criterion), "\n" => "\n ") #increase indent
159+
replace(io, sprint(show, stopping_criterion; context = io), "\n" => "\n ") #increase indent
160160
end
161161
return nothing
162162
end
@@ -207,7 +207,7 @@ function Base.show(io::IO, ::MIME"text/plain", stop_when_any::StopWhenAny)
207207
print(io, "StopWhenAny with the Stopping Criteria:")
208208
for stopping_criterion in stop_when_any.criteria
209209
print(io, "\n ")
210-
replace(io, string(stopping_criterion), "\n" => "\n ") #increase indent
210+
replace(io, sprint(show, stopping_criterion; context = io), "\n" => "\n ") #increase indent
211211
end
212212
return nothing
213213
end

test/Project.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ name = "AlgorithmsInterfaceTests"
44
AlgorithmsInterface = "d1e3940c-cd12-4505-8585-b0a4b322527d"
55
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
7-
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
7+
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
88
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
99

10+
[sources]
11+
AlgorithmsInterface = {path = ".."}
12+
1013
[compat]
1114
Aqua = "0.8"
12-
SafeTestsets = "0.1"
1315
Test = "1.10"
14-
15-
[sources]
16-
AlgorithmsInterface = {path = ".."}

test/aqua.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using AlgorithmsInterface
2+
using Aqua
3+
4+
Aqua.test_all(AlgorithmsInterface)

test/runtests.jl

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
using SafeTestsets, Test
1+
# Test entry point — uses ParallelTestRunner.jl to run test files in parallel
2+
# worker processes (auto-discovered from `test/`).
3+
#
4+
# Run locally:
5+
# julia --project=test test/runtests.jl # run all tests
6+
# julia --project=test test/runtests.jl --list # list discovered test files
7+
# julia --project=test test/runtests.jl --help # show full usage
8+
# julia --project=test test/runtests.jl <name> [<name>…] # only files whose
9+
# # name starts with <name>
10+
#
11+
# Or from the Julia REPL:
12+
# using Pkg; Pkg.test("AlgorithmsInterface";
13+
# test_args=["--jobs=4", "--verbose"])
14+
#
15+
# Useful CLI options:
16+
# --jobs=N number of worker processes (default: chosen from CPU/memory)
17+
# --verbose print per-test timing, compile time, and memory stats
18+
# --quickfail abort the whole run on the first failure
219

3-
# these have to be included here to make show tests behave
20+
using ParallelTestRunner
421
using AlgorithmsInterface
5-
using Dates
622

7-
@testset "AlgorithmsInterface.jl" begin
8-
@safetestset "Newton" begin
9-
include("newton.jl")
10-
end
11-
12-
@safetestset "Stopping Criteria" begin
13-
include("stopping_criterion.jl")
14-
end
15-
16-
@safetestset "Logging Infrastructure" begin
17-
include("logging.jl")
18-
end
19-
20-
@safetestset "Aqua" begin
21-
using AlgorithmsInterface, Aqua
22-
Aqua.test_all(AlgorithmsInterface)
23-
end
24-
end
23+
runtests(AlgorithmsInterface, ARGS)

test/stopping_criterion.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ problem = AIT.DummyProblem()
88
@testset "StopAfterIteration" begin
99
s1 = StopAfterIteration(2)
1010
@test s1 isa StoppingCriterion
11-
@test repr(s1) == "StopAfterIteration(2)"
11+
@test repr(s1; context = :module => @__MODULE__) == "StopAfterIteration(2)"
1212
@test !indicates_convergence(s1)
1313
algorithm = AIT.DummyAlgorithm(s1)
1414
s1_state = initialize_state(problem, algorithm, s1)
@@ -26,7 +26,7 @@ end
2626
@testset "StopAfter" begin
2727
s1 = StopAfter(Nanosecond(7))
2828
@test s1 isa StoppingCriterion
29-
@test string(s1) == "StopAfter(Nanosecond(7))"
29+
@test sprint(show, s1; context = :module => @__MODULE__) == "StopAfter(Nanosecond(7))"
3030
@test_throws ArgumentError StopAfter(Second(-1))
3131

3232
algorithm = AIT.DummyAlgorithm(s1)
@@ -53,7 +53,7 @@ end
5353
s1b = StopWhenAll([c1, c2])
5454
@test s1 == s1b
5555
@test s1 isa StoppingCriterion
56-
@test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1) ==
56+
@test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1; context = :module => @__MODULE__) ==
5757
"StopWhenAll with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Nanosecond(2))"
5858
algorithm = AIT.DummyAlgorithm(s1)
5959
s1_state = initialize_state(problem, algorithm, s1)
@@ -97,7 +97,7 @@ end
9797
s1 = c1 | c2
9898
@test s1 isa StoppingCriterion
9999
@test s1 == StopWhenAny([c1, c2])
100-
@test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1) ==
100+
@test sprint((io, x) -> show(io, MIME"text/plain"(), x), s1; context = :module => @__MODULE__) ==
101101
"StopWhenAny with the Stopping Criteria:\n StopAfterIteration(2)\n StopAfter(Second(1))"
102102
@test !indicates_convergence(s1)
103103

0 commit comments

Comments
 (0)