Skip to content

Commit a5f7b04

Browse files
committed
Using Catch::getResultCapture().getCurrentTestName() (deprecated back in 2015\!) to set up temporary file names local to a test case
1 parent 8d5040a commit a5f7b04

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

check/TestBasis.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
#include "catch.hpp"
66

77
const bool dev_run = false;
8-
const std::string basis_file = "adlittle.bas";
98
HighsBasis basis_data;
109

11-
void testBasisReloadModel(Highs& highs, const bool from_file);
12-
void testBasisRestart(Highs& highs, const bool from_file);
10+
void testBasisReloadModel(Highs& highs, const std::string& basis_file, const bool from_file);
11+
void testBasisRestart(Highs& highs, const std::string& basis_file, const bool from_file);
1312

1413
// No commas in test case name.
1514
TEST_CASE("Basis-file", "[highs_basis_file]") {
15+
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";
18+
1619
HighsStatus return_status;
1720
std::string model0_file =
1821
std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
1922
std::string model1_file =
2023
std::string(HIGHS_DIR) + "/check/instances/avgas.mps";
2124

25+
2226
Highs highs;
2327
if (!dev_run) {
2428
highs.setOptionValue("output_flag", false);
@@ -38,7 +42,6 @@ TEST_CASE("Basis-file", "[highs_basis_file]") {
3842
REQUIRE(return_status == HighsStatus::kError);
3943

4044
// Check error return for some invalid basis files
41-
std::string invalid_basis_file = "InvalidBasis.bas";
4245
std::ofstream f;
4346
// Write and read a file for unsupported HiGHS version
4447
f.open(invalid_basis_file, std::ios::out);
@@ -64,14 +67,16 @@ TEST_CASE("Basis-file", "[highs_basis_file]") {
6467
return_status = highs.readBasis(invalid_basis_file);
6568
REQUIRE(return_status == HighsStatus::kError);
6669

67-
testBasisRestart(highs, true);
68-
testBasisReloadModel(highs, true);
70+
testBasisRestart(highs, basis_file, true);
71+
testBasisReloadModel(highs, basis_file, true);
6972

7073
std::remove(basis_file.c_str());
7174
std::remove(invalid_basis_file.c_str());
7275
}
7376

7477
TEST_CASE("Basis-data", "[highs_basis_data]") {
78+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
79+
const std::string basis_file = test_name + "adlittle.bas";
7580
HighsStatus return_status;
7681
std::string model0_file =
7782
std::string(HIGHS_DIR) + "/check/instances/adlittle.mps";
@@ -93,8 +98,8 @@ TEST_CASE("Basis-data", "[highs_basis_data]") {
9398
basis_data = highs.getBasis();
9499
REQUIRE(return_status == HighsStatus::kOk);
95100

96-
testBasisRestart(highs, false);
97-
testBasisReloadModel(highs, false);
101+
testBasisRestart(highs, basis_file, false);
102+
testBasisReloadModel(highs, basis_file, false);
98103
}
99104

100105
TEST_CASE("set-pathological-basis", "[highs_basis_data]") {
@@ -179,7 +184,7 @@ TEST_CASE("Basis-singular", "[highs_basis_data]") {
179184
}
180185

181186
// No commas in test case name.
182-
void testBasisReloadModel(Highs& highs, const bool from_file) {
187+
void testBasisReloadModel(Highs& highs, const std::string& basis_file, const bool from_file) {
183188
// Checks that no simplex iterations are required if a saved optimal
184189
// basis is used for the original LP after solving a different LP
185190
HighsStatus return_status;
@@ -227,7 +232,7 @@ void testBasisReloadModel(Highs& highs, const bool from_file) {
227232
REQUIRE(highs.getInfo().simplex_iteration_count == 0);
228233
}
229234

230-
void testBasisRestart(Highs& highs, const bool from_file) {
235+
void testBasisRestart(Highs& highs, const std::string& basis_file, const bool from_file) {
231236
// Checks that no simplex iterations are required if a saved optimal
232237
// basis is used for the original LP after changing a bound, solving
233238
// - so that the internal basis changes - and then restoring the

0 commit comments

Comments
 (0)