From 981b9b10d6f48fb2768110a9f81a5f4e880406b2 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 24 Oct 2023 15:25:27 +0200 Subject: FileRoot: Add new absent root underlying type variant Absent roots are characterised only by a Git tree hash, so a new variant of the underlying stored information was added in the form of a plain string. In order to avoid unwanted implicit conversions when instantiating via literal strings, we force callers of the constructors to explicitly differentiate between plain strings and filesystem paths. Existing tests were updated to reflect this. Co-authored-by: Alberto Sartori --- test/buildtool/build_engine/target_map/target_map.test.cpp | 14 ++++++++++---- test/buildtool/common/repository_config.test.cpp | 4 ++-- .../execution_engine/executor/executor_api.test.hpp | 4 ++-- test/buildtool/file_system/file_root.test.cpp | 8 +++++--- 4 files changed, 19 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index bd868b48..6397ba1d 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "catch2/catch_test_macros.hpp" #include "src/buildtool/build_engine/base_maps/directory_map.hpp" #include "src/buildtool/build_engine/base_maps/entity_name.hpp" @@ -47,10 +49,14 @@ void SetupConfig() { [[maybe_unused]] static auto done = CreateSymlinks(); // create the file roots auto info = RepositoryConfig::RepositoryInfo{ - FileRoot{"test/buildtool/build_engine/target_map/data_src"}, - FileRoot{"test/buildtool/build_engine/target_map/data_targets"}, - FileRoot{"test/buildtool/build_engine/target_map/data_rules"}, - FileRoot{"test/buildtool/build_engine/target_map/data_expr"}}; + FileRoot{std::filesystem::path{"test/buildtool/build_engine/target_map/" + "data_src"}}, + FileRoot{std::filesystem::path{"test/buildtool/build_engine/target_map/" + "data_targets"}}, + FileRoot{std::filesystem::path{"test/buildtool/build_engine/target_map/" + "data_rules"}}, + FileRoot{std::filesystem::path{"test/buildtool/build_engine/target_map/" + "data_expr"}}}; RepositoryConfig::Instance().Reset(); RepositoryConfig::Instance().SetInfo("", std::move(info)); } diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp index 29c89d50..cfde95ed 100644 --- a/test/buildtool/common/repository_config.test.cpp +++ b/test/buildtool/common/repository_config.test.cpp @@ -43,7 +43,7 @@ namespace { return std::move(*root); } } - return FileRoot{"missing"}; + return FileRoot{std::filesystem::path{"missing"}}; } [[nodiscard]] auto CreateFixedRepoInfo( @@ -61,7 +61,7 @@ namespace { std::string const& tfn = "TARGETS", std::string const& rfn = "RULES", std::string const& efn = "EXPRESSIONS") { - static auto const kFileRoot = FileRoot{"file path"}; + static auto const kFileRoot = FileRoot{std::filesystem::path{"file path"}}; return RepositoryConfig::RepositoryInfo{ kFileRoot, kFileRoot, kFileRoot, kFileRoot, bindings, tfn, rfn, efn}; } diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp index ffee5184..bd02e0fb 100755 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -31,8 +31,8 @@ using ApiFactory = std::function; static inline void SetupConfig() { - auto info = RepositoryConfig::RepositoryInfo{ - FileRoot{"test/buildtool/execution_engine/executor"}}; + auto info = RepositoryConfig::RepositoryInfo{FileRoot{ + std::filesystem::path{"test/buildtool/execution_engine/executor"}}}; RepositoryConfig::Instance().SetInfo("", std::move(info)); } diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index eab17ff6..8828fb7b 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -165,7 +165,8 @@ TEST_CASE("Creating file root", "[file_root]") { REQUIRE(root_path); CHECK(FileRoot{*root_path}.Exists(".")); - CHECK_FALSE(FileRoot{"does_not_exist"}.Exists(".")); + CHECK_FALSE( + FileRoot{std::filesystem::path{"does_not_exist"}}.Exists(".")); } SECTION("git root") { @@ -184,8 +185,9 @@ TEST_CASE("Creating file root", "[file_root]") { REQUIRE(root_path); CHECK(FileRoot{*root_path, /*ignore_special=*/true}.Exists(".")); - CHECK_FALSE( - FileRoot{"does_not_exist", /*ignore_special=*/true}.Exists(".")); + CHECK_FALSE(FileRoot{std::filesystem::path{"does_not_exist"}, + /*ignore_special=*/true} + .Exists(".")); } SECTION("git root ignore-special") { -- cgit v1.2.3