Skip to content

Commit 667ad66

Browse files
authored
[Test] migrate Utilities/print.jl to the new MOI.Test (#1444)
1 parent 7f8ce09 commit 667ad66

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

src/Utilities/Utilities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ end
2828
function replace_acronym(s::AbstractString)
2929
s = replace(s, "MathOptInterface.Utilities" => "MOIU")
3030
s = replace(s, "MathOptInterface.Bridges" => "MOIB")
31+
# TODO(odow): remove once deprecated tests are deleted.
3132
s = replace(s, "MathOptInterface.DeprecatedTest" => "MOIT")
33+
s = replace(s, "MathOptInterface.Test" => "MOIT")
3234
s = replace(s, "MathOptInterface" => "MOI")
3335
return s
3436
end

test/Utilities/print.jl

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
module TestPrint
22

3+
using Test
4+
35
using MathOptInterface
46
const MOI = MathOptInterface
57
const MOIU = MOI.Utilities
68

7-
using Test
9+
function runtests()
10+
for name in names(@__MODULE__; all = true)
11+
if startswith("$(name)", "test_")
12+
@testset "$(name)" begin
13+
getfield(@__MODULE__, name)()
14+
end
15+
end
16+
end
17+
return
18+
end
819

920
const LATEX = MIME("text/latex")
1021
const PLAIN = MIME("text/plain")
@@ -523,7 +534,7 @@ function test_nlp()
523534
MOI.set(model, MOI.VariableName(), v[i], "x[$i]")
524535
end
525536
lb, ub = [25.0, 40.0], [Inf, 40.0]
526-
evaluator = MOI.DeprecatedTest.HS071(true)
537+
evaluator = MOI.Test.HS071(true)
527538
block_data = MOI.NLPBlockData(MOI.NLPBoundsPair.(lb, ub), evaluator, true)
528539
MOI.set(model, MOI.NLPBlock(), block_data)
529540
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
@@ -573,14 +584,28 @@ function test_nlp()
573584
return
574585
end
575586

576-
function runtests()
577-
for name in names(@__MODULE__; all = true)
578-
if startswith("$(name)", "test_")
579-
@testset "$(name)" begin
580-
getfield(@__MODULE__, name)()
581-
end
582-
end
583-
end
587+
function test_print_with_acronym()
588+
@test sprint(MOIU.print_with_acronym, "MathOptInterface") == "MOI"
589+
@test sprint(
590+
MOIU.print_with_acronym,
591+
"MathOptInterface.MathOptInterface",
592+
) == "MOI.MOI"
593+
@test sprint(
594+
MOIU.print_with_acronym,
595+
"MathOptInterface.Utilities.MathOptInterface",
596+
) == "MOIU.MOI"
597+
@test sprint(MOIU.print_with_acronym, "MathOptInterfaceXXBridges") ==
598+
"MOIXXBridges"
599+
@test sprint(MOIU.print_with_acronym, "MathOptInterface.BridgesXX") ==
600+
"MOIBXX"
601+
@test sprint(MOIU.print_with_acronym, "MathOptInterface.Test.x") == "MOIT.x"
602+
@test sprint(MOIU.print_with_acronym, "MathOptInterface.x.Test") ==
603+
"MOI.x.Test"
604+
@test sprint(MOIU.print_with_acronym, "MathOptInterface.Utilities.Test") ==
605+
"MOIU.Test"
606+
@test sprint(MOIU.print_with_acronym, "MathOptInterface.Utilities.Test") ==
607+
"MOIU.Test"
608+
return
584609
end
585610

586611
end

test/Utilities/print_with_acronym.jl

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)