44# Use of this source code is governed by an MIT-style license that can be found
55# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66
7+ # !!! info "COV_EXCL_LINE"
8+ #
9+ # The Julia coverage check is not perfect, particularly when it comes to
10+ # macros that produce code that is not executed. To work around
11+ # false-negatives, some lines in this file are excluded from coverage with
12+ # `# COV_EXCL_LINE`. (In most of the excluded cases, the default is for the
13+ # tests to pass, so the failure case of the testset macro is not executed,
14+ # and so no code is executed that can be tied back to the excluded lines.
15+
716module Bridges
817
918import MathOptInterface as MOI
@@ -153,11 +162,11 @@ function _test_structural_identical(
153162 # the variables are added in the same order to both models.
154163 a_x = MOI. get (a, MOI. ListOfVariableIndices ())
155164 b_x = MOI. get (b, MOI. ListOfVariableIndices ())
156- Test. @testset " Test NumberOfVariables" begin
165+ Test. @testset " Test NumberOfVariables" begin # COV_EXCL_LINE
157166 Test. @test MOI. get (a, MOI. NumberOfVariables ()) ==
158167 MOI. get (b, MOI. NumberOfVariables ())
159168 end
160- Test. @testset " Test length ListOfVariableIndices" begin
169+ Test. @testset " Test length ListOfVariableIndices" begin # COV_EXCL_LINE
161170 Test. @test length (a_x) == length (b_x)
162171 end
163172 # A dictionary that maps things from `b`-space to `a`-space.
@@ -180,7 +189,7 @@ function _test_structural_identical(
180189 # have zero constraints in `a`.
181190 Test. @test (F, S) in b_constraint_types ||
182191 MOI. get (a, MOI. NumberOfConstraints {F,S} ()) == 0
183- end
192+ end # COV_EXCL_LINE
184193 Test. @testset " $F -in-$S " for (F, S) in b_constraint_types
185194 Test. @test haskey (constraints, (F, S))
186195 # Check that the same number of constraints are present
@@ -204,11 +213,11 @@ function _test_structural_identical(
204213 return s_b == s && isapprox (f, f_b) && typeof (f) == typeof (f_b)
205214 end
206215 end
207- end
216+ end # COV_EXCL_LINE
208217 # Test model attributes are set, like ObjectiveSense and ObjectiveFunction.
209218 a_attrs = MOI. get (a, MOI. ListOfModelAttributesSet ())
210219 b_attrs = MOI. get (b, MOI. ListOfModelAttributesSet ())
211- Test. @testset " Test length ListOfModelAttributesSet" begin
220+ Test. @testset " Test length ListOfModelAttributesSet" begin # COV_EXCL_LINE
212221 Test. @test length (a_attrs) == length (b_attrs)
213222 end
214223 Test. @testset " $attr " for attr in b_attrs
@@ -220,7 +229,7 @@ function _test_structural_identical(
220229 attr_b = MOI. Utilities. map_indices (x_map, MOI. get (b, attr))
221230 Test. @test isapprox (MOI. get (a, attr), attr_b)
222231 end
223- end
232+ end # COV_EXCL_LINE
224233 return
225234end
226235
@@ -303,7 +312,7 @@ function _runtests(
303312 if print_inner_model
304313 print (inner)
305314 end
306- Test. @testset " Test outer bridged model appears like the input" begin
315+ Test. @testset " Test outer bridged model appears like the input" begin # COV_EXCL_LINE
307316 test = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
308317 input_fn (test)
309318 _test_structural_identical (
@@ -312,12 +321,12 @@ function _runtests(
312321 cannot_unbridge = cannot_unbridge,
313322 )
314323 end
315- Test. @testset " Test inner bridged model appears like the target" begin
324+ Test. @testset " Test inner bridged model appears like the target" begin # COV_EXCL_LINE
316325 target = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
317326 output_fn (target)
318327 _test_structural_identical (target, inner)
319328 end
320- Test. @testset " Test MOI.VariablePrimalStart" begin
329+ Test. @testset " Test MOI.VariablePrimalStart" begin # COV_EXCL_LINE
321330 attr = MOI. VariablePrimalStart ()
322331 bridge_supported = all (values (Variable. bridges (model))) do bridge
323332 return MOI. supports (model, attr, typeof (bridge))
@@ -334,7 +343,7 @@ function _runtests(
334343 end
335344 end
336345 end
337- Test. @testset " Test ConstraintPrimalStart and ConstraintDualStart" begin
346+ Test. @testset " Test ConstraintPrimalStart and ConstraintDualStart" begin # COV_EXCL_LINE
338347 list_of_constraints = MOI. get (model, MOI. ListOfConstraintTypesPresent ())
339348 Test. @testset " $F -in-$S " for (F, S) in list_of_constraints
340349 for ci in MOI. get (model, MOI. ListOfConstraintIndices {F,S} ())
@@ -366,28 +375,28 @@ function _runtests(
366375 continue
367376 end
368377 Test. @test returned_start ≈ start
369- end
378+ end # COV_EXCL_LINE
370379 end
371- end
380+ end # COV_EXCL_LINE
372381 end
373- Test. @testset " Test general bridge tests" begin
374- Test. @testset " Constraint" begin
382+ Test. @testset " Test general bridge tests" begin # COV_EXCL_LINE
383+ Test. @testset " Constraint" begin # COV_EXCL_LINE
375384 for b in values (Constraint. bridges (model))
376385 _general_bridge_tests (something (b))
377386 end
378387 end
379- Test. @testset " Objective" begin
388+ Test. @testset " Objective" begin # COV_EXCL_LINE
380389 for b in values (Objective. bridges (model))
381390 _general_bridge_tests (something (b))
382391 end
383392 end
384- Test. @testset " Variable" begin
393+ Test. @testset " Variable" begin # COV_EXCL_LINE
385394 for b in values (Variable. bridges (model))
386395 _general_bridge_tests (something (b))
387396 end
388397 end
389398 end
390- Test. @testset " Test delete" begin
399+ Test. @testset " Test delete" begin # COV_EXCL_LINE
391400 _test_delete (Bridge, model, inner)
392401 end
393402 return
0 commit comments