Skip to content

Commit

Permalink
Fix UNIT_Server_TEST on Windows (#1577)
Browse files Browse the repository at this point in the history
Signed-off-by: Silvio <[email protected]>
  • Loading branch information
traversaro authored Jul 6, 2022
1 parent 199237d commit f39bc25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/Server_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,9 @@ TEST_P(ServerFixture, IGN_UTILS_TEST_DISABLED_ON_WIN32(ResourcePath))
TEST_P(ServerFixture, GetResourcePaths)
{
ignition::common::setenv("IGN_GAZEBO_RESOURCE_PATH",
"/tmp/some/path:/home/user/another_path");
std::string("/tmp/some/path") +
common::SystemPaths::Delimiter() +
std::string("/home/user/another_path"));

ServerConfig serverConfig;
gazebo::Server server(serverConfig);
Expand Down Expand Up @@ -1034,7 +1036,9 @@ TEST_P(ServerFixture, GetResourcePaths)
TEST_P(ServerFixture, AddResourcePaths)
{
ignition::common::setenv("IGN_GAZEBO_RESOURCE_PATH",
"/tmp/some/path:/home/user/another_path");
std::string("/tmp/some/path") +
common::SystemPaths::Delimiter() +
std::string("/home/user/another_path"));
ignition::common::setenv("SDF_PATH", "");
ignition::common::setenv("IGN_FILE_PATH", "");

Expand Down Expand Up @@ -1063,7 +1067,9 @@ TEST_P(ServerFixture, AddResourcePaths)
// Add path
msgs::StringMsg_V req;
req.add_data("/tmp/new_path");
req.add_data("/tmp/more:/tmp/even_more");
req.add_data(std::string("/tmp/more") +
common::SystemPaths::Delimiter() +
std::string("/tmp/even_more"));
req.add_data("/tmp/some/path");
bool executed = node.Request("/gazebo/resource_paths/add", req);
EXPECT_TRUE(executed);
Expand All @@ -1082,7 +1088,7 @@ TEST_P(ServerFixture, AddResourcePaths)
{
char *pathCStr = std::getenv(env);

auto paths = common::Split(pathCStr, ':');
auto paths = common::Split(pathCStr, common::SystemPaths::Delimiter());
paths.erase(std::remove_if(paths.begin(), paths.end(),
[](std::string const &_path)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ std::vector<std::string> resourcePaths()
char *gzPathCStr = std::getenv(kResourcePathEnv.c_str());
if (gzPathCStr && *gzPathCStr != '\0')
{
gzPaths = common::Split(gzPathCStr, ':');
gzPaths = common::Split(gzPathCStr, common::SystemPaths::Delimiter());
}

gzPaths.erase(std::remove_if(gzPaths.begin(), gzPaths.end(),
Expand All @@ -428,7 +428,7 @@ void addResourcePaths(const std::vector<std::string> &_paths)
char *sdfPathCStr = std::getenv(kSdfPathEnv.c_str());
if (sdfPathCStr && *sdfPathCStr != '\0')
{
sdfPaths = common::Split(sdfPathCStr, ':');
sdfPaths = common::Split(sdfPathCStr, common::SystemPaths::Delimiter());
}

// Ignition file paths (for <uri>s)
Expand All @@ -437,15 +437,15 @@ void addResourcePaths(const std::vector<std::string> &_paths)
char *ignPathCStr = std::getenv(systemPaths->FilePathEnv().c_str());
if (ignPathCStr && *ignPathCStr != '\0')
{
ignPaths = common::Split(ignPathCStr, ':');
ignPaths = common::Split(ignPathCStr, common::SystemPaths::Delimiter());
}

// Gazebo resource paths
std::vector<std::string> gzPaths;
char *gzPathCStr = std::getenv(kResourcePathEnv.c_str());
if (gzPathCStr && *gzPathCStr != '\0')
{
gzPaths = common::Split(gzPathCStr, ':');
gzPaths = common::Split(gzPathCStr, common::SystemPaths::Delimiter());
}

// Add new paths to gzPaths
Expand Down Expand Up @@ -474,20 +474,20 @@ void addResourcePaths(const std::vector<std::string> &_paths)
// Update the vars
std::string sdfPathsStr;
for (const auto &path : sdfPaths)
sdfPathsStr += ':' + path;
sdfPathsStr += common::SystemPaths::Delimiter() + path;

ignition::common::setenv(kSdfPathEnv.c_str(), sdfPathsStr.c_str());

std::string ignPathsStr;
for (const auto &path : ignPaths)
ignPathsStr += ':' + path;
ignPathsStr += common::SystemPaths::Delimiter() + path;

ignition::common::setenv(
systemPaths->FilePathEnv().c_str(), ignPathsStr.c_str());

std::string gzPathsStr;
for (const auto &path : gzPaths)
gzPathsStr += ':' + path;
gzPathsStr += common::SystemPaths::Delimiter() + path;

ignition::common::setenv(kResourcePathEnv.c_str(), gzPathsStr.c_str());

Expand Down

0 comments on commit f39bc25

Please sign in to comment.