File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,29 @@ class RestoreEnvVar
6161 const std::string value_;
6262};
6363
64+ // TODO(cottsay): Remove when ros2/rcpputils#63 is resolved
65+ static fs::path current_path ()
66+ {
67+ char * cwd;
68+ #ifdef _WIN32
69+ #ifdef UNICODE
70+ #error "rcpputils::fs does not support Unicode paths"
71+ #endif
72+ cwd = _getcwd (NULL , 0 );
73+ #else
74+ cwd = getcwd (NULL , 0 );
75+ #endif
76+ if (nullptr == cwd) {
77+ std::error_code ec{errno, std::system_category ()};
78+ errno = 0 ;
79+ throw std::system_error{ec, " cannot get current working directory" };
80+ }
81+
82+ std::string ret (cwd);
83+ free (cwd);
84+ return fs::path (ret);
85+ }
86+
6487TEST_F (LoggingTest, init_invalid)
6588{
6689 // Config files are not supported by spdlog
@@ -84,7 +107,7 @@ TEST_F(LoggingTest, init_failure)
84107 rcutils_reset_error ();
85108
86109 // Force failure to create directories
87- fs::path fake_home ( " fake_home_dir" ) ;
110+ fs::path fake_home = current_path () / " fake_home_dir" ;
88111 ASSERT_TRUE (fs::create_directories (fake_home));
89112 ASSERT_EQ (true , rcutils_set_env (" HOME" , fake_home.string ().c_str ()));
90113
You can’t perform that action at this time.
0 commit comments