From db961e1e9fba6e0c439f69ac8342ef887d9d19a6 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 20 Jun 2023 17:54:07 +0200 Subject: Add non-upwards symlinks in the rule language... via a 'SYMLINK' constructor function. This works similarly to the 'FILE' construct, but the name given must point to a non-upwards symlink and a symlink artifact is being generated from it. Also updates the relevant tests. --- .../build_engine/base_maps/source_map.test.cpp | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/buildtool/build_engine/base_maps/source_map.test.cpp') diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp index 3b787ffe..05157870 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -28,6 +28,14 @@ namespace { using namespace BuildMaps::Base; // NOLINT void SetupConfig(bool use_git) { + // manually create locally a test symlink in data_src; should match the + // git test_repo structure + if (not use_git) { + auto link_path = kBasePath / "data_src/foo/link"; + if (not FileSystemManager::Exists(link_path)) { + REQUIRE(FileSystemManager::CreateSymlink("dummy", link_path)); + } + } auto root = FileRoot{kBasePath / "data_src"}; if (use_git) { auto repo_path = CreateTestRepo(); @@ -156,3 +164,24 @@ TEST_CASE("subdir file") { CHECK(artifacts["bar/file"]["data"]["size"] == 0); } } + +TEST_CASE("subdir symlink") { + nlohmann::json artifacts; + auto name = EntityName{"", "foo", "link"}; + auto consumer = [&artifacts](auto values) { + artifacts = (*values[0])->Artifacts()->ToJson(); + }; + + SECTION("via file") { + CHECK(ReadSourceTarget(name, consumer, /*use_git=*/false)); + CHECK(artifacts["link"]["type"] == "LOCAL"); + CHECK(artifacts["link"]["data"]["path"] == "foo/link"); + } + + SECTION("via git tree") { + CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(artifacts["link"]["type"] == "KNOWN"); + CHECK(artifacts["link"]["data"]["id"] == kSrcLinkId); + CHECK(artifacts["link"]["data"]["size"] == 5); // content: dummy + } +} -- cgit v1.2.3