Skip to content

[Test] add verbose kwarg to MOI.Test.runtests #2347

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
Nov 8, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/Test/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ version_added(::F) where {F} = v"0.10.5" # The default for any unlabeled tests.
exclude::Vector{Union{String,Regex}} = String[],
warn_unsupported::Bool = false,
exclude_tests_after::VersionNumber = v"999.0.0",
verbose::Bool = false,
)

Run all tests in `MathOptInterface.Test` on `model`.
Expand All @@ -200,6 +201,8 @@ Run all tests in `MathOptInterface.Test` on `model`.
added after that version number. This is useful for solvers who can declare a
fixed set of tests, and not cause their tests to break if a new patch of MOI
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.

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

Expand All @@ -213,6 +216,7 @@ MathOptInterface.Test.runtests(
include = ["test_linear_", r"^test_model_Name\$"],
exclude = ["VariablePrimalStart"],
warn_unsupported = true,
verbose = true,
exclude_tests_after = v"0.10.5",
)
```
Expand All @@ -223,6 +227,7 @@ function runtests(
include::Vector = String[],
exclude::Vector = String[],
warn_unsupported::Bool = false,
verbose::Bool = false,
exclude_tests_after::VersionNumber = v"999.0.0",
)
tests = filter(names(@__MODULE__; all = true)) do name
Expand All @@ -248,8 +253,14 @@ function runtests(
elseif !isempty(exclude) && any(s -> occursin(s, name), exclude)
continue
end
if verbose
@info "Running $name"
end
test_function = getfield(@__MODULE__, name_sym)
if version_added(test_function) > exclude_tests_after
if verbose
println(" Skipping test because of `exclude_tests_after`")
end
continue
end
@testset "$(name)" begin
Expand All @@ -260,6 +271,9 @@ function runtests(
try
test_function(model, c)
catch err
if verbose
println(" Test errored with $(typeof(err))")
end
_error_handler(err, name, warn_unsupported)
end
if tear_down !== nothing
Expand Down
3 changes: 2 additions & 1 deletion test/Test/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MOI.Test.runtests(
MOI.Utilities.Model{Float64}(),
scalar_function_constant_non_zero = true,
),
MOI.Test.Config(),
MOI.Test.Config();
include = [
r"^test_model_ScalarFunctionConstantNotZero$",
"test_model_copy_to_UnsupportedAttribute",
Expand All @@ -43,6 +43,7 @@ MOI.Test.runtests(
"test_model_supports_constraint_VariableIndex_EqualTo",
"test_model_supports_constraint_VectorOfVariables_Nonnegatives",
],
verbose = true,
)

# Test for Issue #1757
Expand Down