// or ".sh".
std::string add_exe_suffix(const std::string& program);
+// Return a new path with `extension` added to `path` (keeping any existing
+// extension).
+std::filesystem::path add_extension(const std::filesystem::path& path,
+ std::string_view extension);
+
// Return current working directory (CWD) by reading the environment variable
// PWD (thus keeping any symlink parts in the path and potentially ".." or "//"
// parts). If PWD does not resolve to the same inode as `actual_cwd` then
// --- Inline implementations ---
+inline std::filesystem::path
+add_extension(const std::filesystem::path& path, std::string_view extension)
+{
+ std::filesystem::path result(path);
+ result += std::filesystem::path(extension);
+ return result;
+}
+
inline bool
is_dev_null_path(const std::filesystem::path& path)
{
CHECK(util::add_exe_suffix("foo.sh") == "foo.sh");
}
+TEST_CASE("util::add_extension")
+{
+ CHECK(util::add_extension("foo.x", "") == "foo.x");
+ CHECK(util::add_extension("foo.x", ".y") == "foo.x.y");
+}
+
TEST_CASE("util::is_full_path")
{
CHECK(!util::is_full_path(""));