File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 11
2+ #include < cerrno>
3+ #include < cstring>
24#include < exception>
3- #include < filesystem>
45#include < iostream>
56#include < system_error>
67
8+ #if __has_include(<filesystem>)
9+ #include < filesystem>
10+ #elif __has_include(<unistd.h>)
11+ #include < unistd.h>
12+ #endif
13+
714#define CATCH_CONFIG_RUNNER
815#include " catch.hpp"
916
@@ -19,6 +26,7 @@ int main(int argc, char* argv[])
1926 // For now, set the app's CWD (Current Working Directory) to where the
2027 // app's executable is, presuming this info is available.
2128 if (argc >= 1 && argv[0 ] != nullptr ) {
29+ #if __has_include(<filesystem>)
2230 try {
2331 using namespace std ::filesystem;
2432 current_path (path (argv[0 ]).parent_path ());
@@ -29,6 +37,20 @@ int main(int argc, char* argv[])
2937 " \"\n " ;
3038 return 1 ; // Return a non-zero integer to indicate failure
3139 }
40+ #elif __has_include(<unistd.h>)
41+ std::string p = argv[0 ];
42+ const auto last_path_sep = p.find_last_of (' /' );
43+ if (last_path_sep != std::string::npos && last_path_sep > 0 ) {
44+ p = p.substr (0 , last_path_sep);
45+ if (chdir (p.c_str ()) != 0 ) {
46+ std::cerr <<
47+ " ERROR: Unable to set CWD via chdir(). strerror(errno)=\" " <<
48+ strerror (errno) <<
49+ " \"\n " ;
50+ return 1 ; // Return a non-zero integer to indicate failure
51+ }
52+ }
53+ #endif
3254 }
3355
3456 return Catch::Session ().run (argc, argv);
You can’t perform that action at this time.
0 commit comments