Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor-99 committed Apr 11, 2024
1 parent 901e0c8 commit 3d1dac9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nav2_map_server/include/nav2_map_server/map_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool saveMapToFile(
* @brief Expand ~/ to home user dir.
* @param yaml_filename Name of input YAML file.
* @param home_dir Expanded `~/`home dir or empty string if HOME not set
*
*
* @return Expanded string or input string if `~/` not expanded
*/
std::string expand_user_home_dir_if_needed(
Expand Down
13 changes: 5 additions & 8 deletions nav2_map_server/src/map_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,18 @@ std::string get_home_dir()
return std::string{};
}

std::string expand_user_home_dir_if_needed(std::string yaml_filename, std::string home_variable_value)
std::string expand_user_home_dir_if_needed(
std::string yaml_filename,
std::string home_variable_value)
{
if (yaml_filename.size() < 2 or not (yaml_filename[0] == '~' and yaml_filename[1] == '/'))
{
if (yaml_filename.size() < 2 || !(yaml_filename[0] == '~' && yaml_filename[1] == '/')) {
return yaml_filename;
}

if (home_variable_value.empty())
{
if (home_variable_value.empty()) {
std::cout << "[INFO] [map_io]: Map yaml file name starts with '~/' but no HOME variable set. \n"
<< "[INFO] [map_io] User home dir will be not expanded \n";
return yaml_filename;
}

const std::string prefix{home_variable_value};
return yaml_filename.replace(0, 1, prefix);
}
Expand Down Expand Up @@ -323,7 +321,6 @@ LOAD_MAP_STATUS loadMapFromYaml(
" for reason: " << e.what() << std::endl;
return INVALID_MAP_METADATA;
}

try {
loadMapFromFile(load_parameters, map);
} catch (std::exception & e) {
Expand Down
5 changes: 2 additions & 3 deletions nav2_map_server/test/unit/test_map_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,13 @@ TEST(HomeUserExpanderTestSuite, homeUserExpanderShouldNotChangeInputStringWhenSh
{
const std::string emptyFileName{};
ASSERT_EQ(emptyFileName, expand_user_home_dir_if_needed(emptyFileName, "/home/user"));

}

TEST(HomeUserExpanderTestSuite, homeUserExpanderShouldNotChangeInputStringWhenInputStringDoesNotStartWithHomeSequence)
TEST(HomeUserExpanderTestSuite,
homeUserExpanderShouldNotChangeInputStringWhenInputStringDoesNotStartWithHomeSequence)
{
const std::string fileName{"valid_file.yaml"};
ASSERT_EQ(fileName, expand_user_home_dir_if_needed(fileName, "/home/user"));

}

TEST(HomeUserExpanderTestSuite, homeUserExpanderShouldNotChangeInputStringWhenHomeVariableNotFound)
Expand Down

0 comments on commit 3d1dac9

Please sign in to comment.