Skip to content

Commit 121f8c3

Browse files
committed
bug-fix: 'tests' app would fail, depending on what directory it was
launched from
1 parent 5c9e910 commit 121f8c3

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

P0267_RefImpl/Tests/main.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
#define CATCH_CONFIG_MAIN
1+
2+
#include <exception>
3+
#include <filesystem>
4+
#include <iostream>
5+
#include <system_error>
6+
7+
#define CATCH_CONFIG_RUNNER
28
#include "catch.hpp"
39

4-
// this is a stub to generate main() jazz.
10+
// io2d uses its own main(), rather than Catch's, so as to set the running
11+
// process' current working directory to that where input data files are
12+
// located.
13+
//
14+
// Catch2 describes how to do a custom main(), at:
15+
// https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
16+
17+
int main(int argc, char* argv[])
18+
{
19+
// For now, set the app's CWD (Current Working Directory) to where the
20+
// app's executable is, presuming this info is available.
21+
if (argc >= 1 && argv[0] != nullptr) {
22+
try {
23+
using namespace std::filesystem;
24+
current_path(path(argv[0]).parent_path());
25+
} catch (const std::exception & ex) {
26+
std::cerr <<
27+
"ERROR: Unable to set CWD via current_path(). what()=\"" <<
28+
ex.what() <<
29+
"\"\n";
30+
return 1; // Return a non-zero integer to indicate failure
31+
}
32+
}
33+
34+
return Catch::Session().run(argc, argv);
35+
}

0 commit comments

Comments
 (0)