Skip to content

Commit ee6a8dc

Browse files
committed
Use absolute path in fake home directory
Signed-off-by: Scott K Logan <[email protected]>
1 parent 1f5dad1 commit ee6a8dc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

rcl_logging_spdlog/test/test_logging_interface.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
6487
TEST_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

0 commit comments

Comments
 (0)