Skip to content

Commit 4922c29

Browse files
committed
Added some use of Catch::getResultCapture().getCurrentTestName() to make temporary files unique to unit test
1 parent a5f7b04 commit 4922c29

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

check/TestBasis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ void testBasisRestart(Highs& highs, const std::string& basis_file, const bool fr
1313
// No commas in test case name.
1414
TEST_CASE("Basis-file", "[highs_basis_file]") {
1515
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
16-
const std::string basis_file = test_name + "adlittle.bas";
17-
const std::string invalid_basis_file = test_name + "InvalidBasis.bas";
16+
const std::string basis_file = test_name + ".bas";
17+
const std::string invalid_basis_file = test_name + "-Invalid.bas";
1818

1919
HighsStatus return_status;
2020
std::string model0_file =

check/TestCheckSolution.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
const bool dev_run = false;
1010

11-
void runWriteReadCheckSolution(Highs& highs, const std::string model,
11+
void runWriteReadCheckSolution(Highs& highs, const std::string& test_name, const std::string& model,
1212
const HighsModelStatus require_model_status,
1313
const HighsInt write_solution_style);
1414

1515
void runSetLpSolution(const std::string model);
1616

1717
TEST_CASE("check-solution", "[highs_check_solution]") {
18+
std::string test_name = Catch::getResultCapture().getCurrentTestName();
1819
std::string model = "";
1920
std::string model_file;
2021
HighsStatus read_status;
@@ -42,7 +43,8 @@ TEST_CASE("check-solution", "[highs_check_solution]") {
4243
REQUIRE(read_status == require_read_status);
4344

4445
require_model_status = HighsModelStatus::kOptimal;
45-
runWriteReadCheckSolution(highs, model, require_model_status,
46+
test_name += "-";
47+
runWriteReadCheckSolution(highs, test_name, model, require_model_status,
4648
write_solution_style);
4749
SpecialLps special_lps;
4850
HighsLp lp;
@@ -51,21 +53,24 @@ TEST_CASE("check-solution", "[highs_check_solution]") {
5153
model = "distillation";
5254
special_lps.distillationMip(lp, require_model_status, optimal_objective);
5355
highs.passModel(lp);
54-
runWriteReadCheckSolution(highs, model, require_model_status,
56+
test_name += "-";
57+
runWriteReadCheckSolution(highs, test_name, model, require_model_status,
5558
write_solution_style);
5659

5760
lp.clear();
5861
model = "primalDualInfeasible1Lp";
5962
special_lps.primalDualInfeasible1Lp(lp, require_model_status);
6063
highs.passModel(lp);
61-
runWriteReadCheckSolution(highs, model, require_model_status,
64+
test_name += "-";
65+
runWriteReadCheckSolution(highs, test_name, model, require_model_status,
6266
write_solution_style);
6367
// Second pass uses sparse format
6468
write_solution_style = kSolutionStyleSparse;
6569
}
6670
}
6771

6872
TEST_CASE("check-set-mip-solution", "[highs_check_solution]") {
73+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
6974
HighsStatus return_status;
7075
const std::string model = "flugpl";
7176
std::string model_file =
@@ -83,7 +88,7 @@ TEST_CASE("check-set-mip-solution", "[highs_check_solution]") {
8388
HighsInt scratch_num_nodes = info.mip_node_count;
8489
if (dev_run) printf("Num nodes = %d\n", int(scratch_num_nodes));
8590

86-
std::string solution_file = model + ".sol";
91+
std::string solution_file = test_name + model + ".sol";
8792
if (dev_run) return_status = highs.writeSolution("");
8893
return_status = highs.writeSolution(solution_file);
8994
REQUIRE(return_status == HighsStatus::kOk);
@@ -354,8 +359,9 @@ TEST_CASE("check-set-rowwise-lp-solution", "[highs_check_solution]") {
354359
}
355360

356361
TEST_CASE("check-set-mip-solution-extra-row", "[highs_check_solution]") {
362+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
363+
const std::string solution_file_name = test_name + ".sol";
357364
Highs highs;
358-
const std::string solution_file_name = "temp.sol";
359365
highs.setOptionValue("output_flag", dev_run);
360366
highs.addVar(0, 2);
361367
highs.addVar(0, 2);
@@ -396,6 +402,7 @@ TEST_CASE("check-set-illegal-solution", "[highs_check_solution]") {
396402
}
397403

398404
TEST_CASE("read-miplib-solution", "[highs_check_solution]") {
405+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
399406
HighsLp lp;
400407
lp.num_col_ = 5;
401408
lp.num_row_ = 1;
@@ -417,7 +424,7 @@ TEST_CASE("read-miplib-solution", "[highs_check_solution]") {
417424
REQUIRE(h.run() == HighsStatus::kOk);
418425
// REQUIRE(h.writeSolution("", kSolutionStylePretty) == HighsStatus::kOk);
419426
const std::vector<double>& col_value = h.getSolution().col_value;
420-
std::string miplib_sol_file = "miplib.sol";
427+
std::string miplib_sol_file = test_name + ".sol";
421428
FILE* file = fopen(miplib_sol_file.c_str(), "w");
422429
REQUIRE(file != 0);
423430
fprintf(file, "=obj= 22\n");
@@ -441,7 +448,8 @@ TEST_CASE("read-miplib-solution", "[highs_check_solution]") {
441448
std::remove(miplib_sol_file.c_str());
442449
}
443450

444-
void runWriteReadCheckSolution(Highs& highs, const std::string model,
451+
void runWriteReadCheckSolution(Highs& highs, const std::string& test_name,
452+
const std::string& model,
445453
const HighsModelStatus require_model_status,
446454
const HighsInt write_solution_style) {
447455
HighsStatus run_status;
@@ -455,7 +463,7 @@ void runWriteReadCheckSolution(Highs& highs, const std::string model,
455463
status = highs.getModelStatus();
456464
REQUIRE(status == require_model_status);
457465

458-
solution_file = model + ".sol";
466+
solution_file = test_name + model + ".sol";
459467
if (dev_run)
460468
printf("Writing solution in style %d to %s\n", int(write_solution_style),
461469
solution_file.c_str());

check/TestFilereader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ TEST_CASE("filereader-free-format-parser-lp", "[highs_filereader]") {
199199

200200
// No commas in test case name.
201201
TEST_CASE("filereader-read-mps-ems-lp", "[highs_filereader]") {
202+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
202203
std::string filename;
203204
filename = std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
204205

@@ -212,14 +213,14 @@ TEST_CASE("filereader-read-mps-ems-lp", "[highs_filereader]") {
212213
HighsLp lp_mps = highs.getLp();
213214

214215
// Write lp
215-
std::string filename_lp = "adlittle.lp";
216+
std::string filename_lp = test_name + ".lp";
216217
status = highs.writeModel(filename_lp);
217218
REQUIRE(status == HighsStatus::kOk);
218219

219220
/*
220221
bool are_the_same;
221222
// Write ems
222-
std::string filename_ems = "adlittle.ems";
223+
std::string filename_ems = test_name + ".ems";
223224
status = highs.writeModel(filename_ems);
224225
REQUIRE(status == HighsStatus::kOk);
225226
@@ -357,9 +358,10 @@ TEST_CASE("filereader-dD2e", "[highs_filereader]") {
357358
// }
358359

359360
TEST_CASE("writeLocalModel", "[highs_filereader]") {
361+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
362+
std::string write_model_file = test_name + ".mps";
360363
Highs h;
361364
h.setOptionValue("output_flag", dev_run);
362-
std::string write_model_file = "foo.mps";
363365
HighsModel model;
364366
HighsLp& lp = model.lp_;
365367
;
@@ -415,7 +417,8 @@ TEST_CASE("writeLocalModel", "[highs_filereader]") {
415417
}
416418

417419
TEST_CASE("write-MI-bound-model", "[highs_filereader]") {
418-
std::string write_model_file = "temp.mps";
420+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
421+
std::string write_model_file = test_name + ".mps";
419422
Highs h;
420423
h.setOptionValue("output_flag", dev_run);
421424
h.addCol(1, -kHighsInf, 1, 0, nullptr, nullptr);

check/TestInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
const bool dev_run = false;
1010

1111
TEST_CASE("highs-info", "[highs_info]") {
12+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
13+
const std::string highs_info_file = test_name + ".info";
1214
std::string filename;
1315
filename = std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
1416
filename = std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
@@ -62,7 +64,6 @@ TEST_CASE("highs-info", "[highs_info]") {
6264
REQUIRE(return_status == HighsStatus::kOk);
6365
}
6466

65-
std::string highs_info_file = "Highs.info";
6667
return_status = highs.writeInfo(highs_info_file);
6768
REQUIRE(return_status == HighsStatus::kOk);
6869

check/TestLogging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
const bool dev_run = false;
88

99
TEST_CASE("logging", "[highs_logging]") {
10+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
11+
const std::string log_file = test_name + ".log";
1012
std::string model;
1113
std::string model_file;
12-
std::string log_file;
1314
HighsStatus return_status;
1415

1516
model = "avgas";
1617
model_file = std::string(HIGHS_DIR) + "/check/instances/" + model + ".mps";
17-
log_file = "temp.log";
1818

1919
Highs highs;
2020
if (!dev_run) highs.setOptionValue("output_flag", false);

0 commit comments

Comments
 (0)