diff --git a/nav2_map_server/include/nav2_map_server/map_io.hpp b/nav2_map_server/include/nav2_map_server/map_io.hpp index b789c4b250e..97dc81821c9 100644 --- a/nav2_map_server/include/nav2_map_server/map_io.hpp +++ b/nav2_map_server/include/nav2_map_server/map_io.hpp @@ -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( diff --git a/nav2_map_server/src/map_io.cpp b/nav2_map_server/src/map_io.cpp index abda9dd7c3a..e07d85b4227 100644 --- a/nav2_map_server/src/map_io.cpp +++ b/nav2_map_server/src/map_io.cpp @@ -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); } @@ -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) { diff --git a/nav2_map_server/test/unit/test_map_io.cpp b/nav2_map_server/test/unit/test_map_io.cpp index a067a8843e0..7f6d930d0fc 100644 --- a/nav2_map_server/test/unit/test_map_io.cpp +++ b/nav2_map_server/test/unit/test_map_io.cpp @@ -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)