Skip to content

Commit deb97ec

Browse files
committed
more adapting to out-of-tree builds
1 parent 41ea429 commit deb97ec

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

src/herder/test/TxSetTests.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,16 +2260,10 @@ TEST_CASE("txset nomination", "[txset]")
22602260
{
22612261
runIteration();
22622262
}
2263-
namespace fs = std::filesystem;
2264-
fs::path resultsPath = "testdata/txset/" + testName;
2265-
char* srcdir = getenv("top_srcdir");
2266-
if (srcdir)
2267-
{
2268-
resultsPath = fs::path(srcdir) / "src" / resultsPath;
2269-
}
2263+
auto resultsPath = getTestDataPath(testName);
22702264
if (getenv("GENERATE_TEST_TXSETS"))
22712265
{
2272-
fs::create_directories(resultsPath.parent_path());
2266+
std::filesystem::create_directories(resultsPath.parent_path());
22732267
std::ofstream resultsStream(resultsPath);
22742268
for (auto const& result : testResults)
22752269
{

src/history/test/SerializeTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "history/HistoryArchive.h"
66
#include "test/Catch2.h"
7+
#include "test/test.h"
78

89
#include <fstream>
910
#include <string>
@@ -19,9 +20,8 @@ TEST_CASE("Serialization round trip", "[history]")
1920
"stellar-history.testnet.6714239.networkPassphrase.v2.json"};
2021
for (size_t i = 0; i < testFiles.size(); i++)
2122
{
22-
std::string fnPath = "testdata/";
23-
std::string testFilePath = fnPath + testFiles[i];
24-
SECTION("Serialize " + testFilePath)
23+
auto testFilePath = getTestDataPath(testFiles[i]);
24+
SECTION("Serialize " + testFilePath.string())
2525
{
2626
std::ifstream in(testFilePath);
2727
REQUIRE(in);

src/ledger/test/LedgerCloseMetaStreamTests.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,11 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
515515

516516
if (ledgerSeq == targetSeq)
517517
{
518-
std::string refJsonPath;
519-
refJsonPath = fmt::format(
520-
FMT_STRING(
521-
"testdata/ledger-close-meta{}-v{}-protocol-{}{}.json"),
518+
auto refJsonPath = getTestDataPath(fmt::format(
519+
FMT_STRING("ledger-close-meta{}-v{}-protocol-{}{}.json"),
522520
enableClassicEvents ? "-enable-classic-events" : "",
523521
lcm.v(), cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION,
524-
isSoroban ? "-soroban" : "");
522+
isSoroban ? "-soroban" : ""));
525523
normalizeMeta(lcm);
526524
std::string have = xdrToCerealString(lcm, "LedgerCloseMeta");
527525
if (getenv("GENERATE_TEST_LEDGER_CLOSE_META"))

src/main/test/ApplicationUtilsTests.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,7 @@ TEST_CASE("application major version numbers", "[applicationutils]")
173173
TEST_CASE("standalone quorum intersection check", "[applicationutils]")
174174
{
175175
Config cfg = getTestConfig();
176-
namespace fs = std::filesystem;
177-
fs::path JSON_ROOT = "testdata/check-quorum-intersection-json";
178-
char* srcdir = getenv("top_srcdir");
179-
if (srcdir)
180-
{
181-
JSON_ROOT = fs::path(srcdir) / "src" / JSON_ROOT;
182-
}
176+
auto JSON_ROOT = getTestDataPath("check-quorum-intersection-json");
183177

184178
SECTION("enjoys quorum intersection")
185179
{

src/main/test/ConfigTests.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TEST_CASE("resolve node id", "[config]")
147147
TEST_CASE("load validators config", "[config]")
148148
{
149149
Config c;
150-
c.load("testdata/stellar-core_example_validators.cfg");
150+
c.load(getTestDataPath("stellar-core_example_validators.cfg"));
151151
auto actualS = c.toString(c.QUORUM_SET);
152152
std::string expected = R"({
153153
"t" : 4,
@@ -456,9 +456,8 @@ TEST_CASE("load example configs", "[config]")
456456
"stellar-core_testnet_validator.cfg"};
457457
for (auto const& fn : testFiles)
458458
{
459-
std::string fnPath = "testdata/";
460-
fnPath += fn;
461-
SECTION("load config " + fnPath)
459+
auto fnPath = getTestDataPath(fn);
460+
SECTION("load config " + fnPath.string())
462461
{
463462
c.load(fnPath);
464463
}
@@ -628,4 +627,4 @@ PUBLIC_KEY="GBVZFVEARURUJTN5ABZPKW36FHKVJK2GHXEVY2SZCCNU5I3CQMTZ3OES"
628627
)";
629628
std::stringstream ss(configStr);
630629
c.load(ss);
631-
}
630+
}

src/test/test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,19 @@ getTestConfig(int instanceNumber, Config::TestDbMode mode)
337337
return *cfgs[instanceNumber];
338338
}
339339

340+
std::filesystem::path
341+
getTestDataPath(std::filesystem::path rel)
342+
{
343+
namespace fs = std::filesystem;
344+
fs::path testdata("testdata");
345+
char* srcdir = getenv("top_srcdir");
346+
if (srcdir)
347+
{
348+
testdata = fs::path(srcdir) / "src" / testdata;
349+
}
350+
return testdata / rel;
351+
}
352+
340353
int
341354
runTest(CommandLineArgs const& args)
342355
{

src/test/test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct TransactionMeta;
1919
Config const& getTestConfig(int instanceNumber = 0,
2020
Config::TestDbMode mode = Config::TESTDB_DEFAULT);
2121

22+
std::filesystem::path getTestDataPath(std::filesystem::path rel);
23+
2224
void cleanupTmpDirs();
2325

2426
// Records or checks a TxMetadata value against a persistent record

0 commit comments

Comments
 (0)