Skip to content

Allow using Test.runtests in other packages #2710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/Test/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@
warn_unsupported::Bool = false,
exclude_tests_after::VersionNumber = v"999.0.0",
verbose::Bool = false,
test_module = MathOptInterface.Test,
)

Run all tests in `MathOptInterface.Test` on `model`.
Run all tests in `test_module`, which defaults to `MathOptInterface.Test`, on `model`.

## Configuration arguments

Expand All @@ -201,6 +202,8 @@
is released with a new test.
* `verbose` is a `Bool` that controls whether the name of the test is printed
before executing it. This can be helpful when debugging.
* `test_module` is a `Module` where all the functions starting with `test_`
are considered as tests.

See also: [`setup_test`](@ref).

Expand All @@ -227,13 +230,14 @@
warn_unsupported::Bool = false,
verbose::Bool = false,
exclude_tests_after::VersionNumber = v"999.0.0",
test_module = @__MODULE__,
)
tests = filter(names(@__MODULE__; all = true)) do name
tests = filter(names(test_module; all = true)) do name
return startswith("$name", "test_")
end
tests = string.(tests)
test_names = string.(tests)
for ex in exclude
if ex in tests && any(t -> ex != t && occursin(ex, t), tests)
if ex in test_names && any(t -> ex != t && occursin(ex, t), test_names)

Check warning on line 240 in src/Test/Test.jl

View check run for this annotation

Codecov / codecov/patch

src/Test/Test.jl#L240

Added line #L240 was not covered by tests
@warn(
"The exclude string \"$ex\" is ambiguous because it exactly " *
"matches a test, but it also partially matches another. Use " *
Expand All @@ -242,19 +246,17 @@
)
end
end
for name_sym in names(@__MODULE__; all = true)
for name_sym in tests
name = string(name_sym)
if !startswith(name, "test_")
continue # All test functions start with test_
elseif !isempty(include) && !any(s -> occursin(s, name), include)
if !isempty(include) && !any(s -> occursin(s, name), include)
continue
elseif !isempty(exclude) && any(s -> occursin(s, name), exclude)
continue
end
if verbose
@info "Running $name"
end
test_function = getfield(@__MODULE__, name_sym)
test_function = getfield(test_module, name_sym)
if version_added(test_function) > exclude_tests_after
if verbose
println(" Skipping test because of `exclude_tests_after`")
Expand Down
Loading