diff --git a/src/Test/Test.jl b/src/Test/Test.jl index 2453297878..fd1f12c59b 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -11,7 +11,31 @@ import LinearAlgebra import MathOptInterface as MOI import MathOptInterface.Utilities as MOIU +#= +We made a bit of a mistake calling the `Test/Test.jl` submodule "Test" because +it conflicts with the standard library "Test" which is imported by MOI.Test. + +In present (and previous) versions of Julia, this has never been a problem. +But every module `Foo` has a self-referential global constant `Foo`: +```julia +julia> module Foo end +Main.Foo + +julia> Foo.Foo +Main.Foo +``` +MOI has the problematic feature that MOI.Test.Test is not self-referential, +and JET.jl appropriately complains with "invalid redefinition of constant +Test." + +The work-around is to wrap `Test` in a module so that `MOI.Test.Test` is +`MOI.Test`. +=# +module _BaseTest using Test +end + +using ._BaseTest: @testset, @test, @test_throws, @inferred # Be wary of adding new fields to this Config struct. Always think: can it be # achieved a different way? @@ -201,7 +225,9 @@ function runtests( warn_unsupported::Bool = false, exclude_tests_after::VersionNumber = v"999.0.0", ) - tests = filter(n -> startswith("$n", "test_"), names(MOI.Test; all = true)) + tests = filter(names(@__MODULE__; all = true)) do name + return startswith("$name", "test_") + end tests = string.(tests) for ex in exclude if ex in tests && any(t -> ex != t && occursin(ex, t), tests) diff --git a/src/Test/test_nonlinear.jl b/src/Test/test_nonlinear.jl index 57d2509d47..d7dacbf610 100644 --- a/src/Test/test_nonlinear.jl +++ b/src/Test/test_nonlinear.jl @@ -484,7 +484,7 @@ function test_nonlinear_hs071_NLPBlockDual( cu = MOI.add_constraint.(model, v, MOI.LessThan.(u)) MOI.set.(model, MOI.VariablePrimalStart(), v, start) lb, ub = [25.0, 40.0], [Inf, 40.0] - evaluator = MOI.Test.HS071(true) + evaluator = HS071(true) block_data = MOI.NLPBlockData(MOI.NLPBoundsPair.(lb, ub), evaluator, true) MOI.set(model, MOI.NLPBlock(), block_data) @@ -931,7 +931,7 @@ This is mainly for the internal purpose of checking their correctness as written. External solvers can exclude this test without consequence. """ function test_nonlinear_HS071_internal(::MOI.ModelLike, ::Config) - d = MOI.Test.HS071(true, true) + d = HS071(true, true) @test MOI.objective_expr(d) == :( x[$(MOI.VariableIndex(1))] * x[$(MOI.VariableIndex(4))] * @@ -994,7 +994,7 @@ This is mainly for the internal purpose of checking their correctness as written. External solvers can exclude this test without consequence. """ function test_nonlinear_Feasibility_internal(::MOI.ModelLike, ::Config) - d = MOI.Test.FeasibilitySenseEvaluator(true) + d = FeasibilitySenseEvaluator(true) @test MOI.objective_expr(d) == :() @test MOI.constraint_expr(d, 1) == :(x[$(MOI.VariableIndex(1))]^2 == 1.0) @test_throws AssertionError MOI.constraint_expr(d, 2) @@ -1118,7 +1118,7 @@ end function test_nonlinear_expression_hs071( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1173,7 +1173,7 @@ end function test_nonlinear_expression_hs071_epigraph( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1229,7 +1229,7 @@ end function test_nonlinear_expression_hs109( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1296,7 +1296,7 @@ end function test_nonlinear_expression_hs110( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1358,7 +1358,7 @@ end function test_nonlinear_expression_quartic( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1406,7 +1406,7 @@ end function test_nonlinear_expression_overrides_objective( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1457,7 +1457,7 @@ end function test_nonlinear_expression_univariate_function( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1493,7 +1493,7 @@ end function test_nonlinear_expression_multivariate_function( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @@ -1544,10 +1544,7 @@ end Tests dual solutions with `ScalarNonlinearFunction`. We use a linear program so that the duals are easy to compute. """ -function test_nonlinear_duals( - model::MOI.ModelLike, - config::MOI.Test.Config{T}, -) where {T} +function test_nonlinear_duals(model::MOI.ModelLike, config::Config{T}) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) @requires _supports(config, MOI.ConstraintDual) @@ -1676,7 +1673,7 @@ end function test_nonlinear_vector_complements( model::MOI.ModelLike, - config::MOI.Test.Config{T}, + config::Config{T}, ) where {T} @requires T == Float64 @requires _supports(config, MOI.optimize!) diff --git a/test/Bridges/Variable/vectorize.jl b/test/Bridges/Variable/vectorize.jl index 8fe459a906..fc6a9bdde4 100644 --- a/test/Bridges/Variable/vectorize.jl +++ b/test/Bridges/Variable/vectorize.jl @@ -145,7 +145,7 @@ function test_exp3_with_add_constrained_variable_y() err = ArgumentError( "Variable bridge of type `$(MOI.Bridges.Variable.VectorizeBridge{Float64,MOI.Nonpositives})`" * - " does not support accessing the attribute `MathOptInterface.Test.UnknownVariableAttribute()`.", + " does not support accessing the attribute `$(MOI.Test.UnknownVariableAttribute())`.", ) @test_throws err MOI.get( bridged_mock, diff --git a/test/Bridges/Variable/zeros.jl b/test/Bridges/Variable/zeros.jl index 06ad086f75..876189a88a 100644 --- a/test/Bridges/Variable/zeros.jl +++ b/test/Bridges/Variable/zeros.jl @@ -97,7 +97,7 @@ function test_zeros() err = ArgumentError( "Variable bridge of type `MathOptInterface.Bridges.Variable.ZerosBridge{Float64}`" * - " does not support accessing the attribute `MathOptInterface.Test.UnknownVariableAttribute()`.", + " does not support accessing the attribute `$(MOI.Test.UnknownVariableAttribute())`.", ) @test_throws err MOI.get( bridged_mock,