Skip to content
Closed
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
4 changes: 2 additions & 2 deletions docs/src/submodules/Bridges/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ julia> MOI.Bridges.runtests(
""",
)
Test Summary: | Pass Total Time
Bridges.runtests | 29 29 0.0s
Bridges.runtests | 30 30 0.0s
```

There are a number of other useful keyword arguments.
Expand Down Expand Up @@ -123,5 +123,5 @@ Subject to:
ScalarAffineFunction{Int64}-in-LessThan{Int64}
(0) - (1) x <= (-1)
Test Summary: | Pass Total Time
Bridges.runtests | 29 29 0.0s
Bridges.runtests | 30 30 0.0s
```
20 changes: 18 additions & 2 deletions src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ julia> MOI.Bridges.runtests(
end,
)
Test Summary: | Pass Total Time
Bridges.runtests | 32 32 0.8s
Bridges.runtests | 33 33 0.8s
```
"""
function runtests(args...; kwargs...)
Expand All @@ -303,17 +303,24 @@ function _runtests(
model_eltype = eltype,
print_inner_model::Bool = false,
cannot_unbridge::Bool = false,
no_bridge_used::Bool = false,
)
# Load model and bridge it
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{model_eltype}())
model = _bridged_model(Bridge{eltype}, inner)
input_fn(model)
Test.@testset "Bridge used" begin
_check_bridged(model; no_bridge_used)
end
final_touch(model)
# Should be able to call final_touch multiple times.
final_touch(model)
if print_inner_model
print(inner)
end
if no_bridge_used
return
end
Test.@testset "Test outer bridged model appears like the input" begin # COV_EXCL_LINE
test =
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{model_eltype}())
Expand Down Expand Up @@ -437,7 +444,7 @@ julia> MOI.Bridges.runtests(
\"\"\",
)
Test Summary: | Pass Total Time
Bridges.runtests | 32 32 0.0s
Bridges.runtests | 33 33 0.0s
```
"""
function runtests(
Expand Down Expand Up @@ -512,6 +519,15 @@ function _general_bridge_tests(bridge::B) where {B<:AbstractBridge}
return
end

function _check_bridged(model; no_bridge_used)
unused =
isempty(MOI.Bridges.Variable.bridges(model)) &&
isempty(MOI.Bridges.Constraint.bridges(model)) &&
isempty(MOI.Bridges.Objective.bridges(model))
Test.@test unused == no_bridge_used
return
end

"""
BridgeRequiresFiniteDomainError{
B<:AbstractBridge,
Expand Down
1 change: 1 addition & 0 deletions test/Bridges/Constraint/IndicatorSOS1Bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function test_runtests()
[z, 2.0 * x * x] in Indicator{ACTIVATE_ON_ONE}(LessThan(2.0))
z in ZeroOne()
""",
no_bridge_used = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has an explicit comment that the model is unchanged. Is this PR really needed?

)
return
end
Expand Down
1 change: 1 addition & 0 deletions test/Bridges/Constraint/NumberConversionBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function test_runtests()
variables: x
::Float64: [x, x] in Zeros(2)
""",
no_bridge_used = true,
)
# VectorAffineFunction
MOI.Bridges.runtests(
Expand Down
3 changes: 2 additions & 1 deletion test/Bridges/Objective/VectorSlackBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function test_runtests()
"""
variables: x
maxobjective: [x]
""",
""";
no_bridge_used = true,
Copy link
Member

@odow odow Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also technically a breaking change because the tests fail without this change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only breaking for tests so it won't really break user code. And this breakage would be quite rare

)
return
end
Expand Down
Loading