Skip to content

Commit

Permalink
chore: add another merge test
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Sep 12, 2024
1 parent 3e62fc7 commit 5bbdf0f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ecsact/cli/commands/build/build_recipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,9 @@ auto ecsact::build_recipe::merge( //
if(std::holds_alternative<source_path>(src)) {
source_path src_path = std::get<source_path>(src);
if(!src_path.path.is_absolute()) {
src_path.path = fs::relative(
target.base_directory() / src_path.path,
base.base_directory()
);
src_path.path =
fs::relative(target.base_directory(), base.base_directory()) /
fs::relative(src_path.path, target.base_directory());
}

merged_build_recipe._sources.emplace_back(std::move(src_path));
Expand Down
41 changes: 41 additions & 0 deletions ecsact/cli/commands/build/test/merge_recipe_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ imports: []
exports: [ecsact_clear_registry]
)yaml";

constexpr auto RECIPE_D = R"yaml(
name: D
sources:
- d.cc
imports: []
exports: [ecsact_clear_registry]
)yaml";

constexpr auto RECIPE_E = R"yaml(
name: E
sources:
- e.cc
imports: []
exports: [ecsact_destroy_registry]
)yaml";

auto contains_source_path(auto&& r, auto p) -> bool {
using std::ranges::find_if;

Expand Down Expand Up @@ -105,3 +123,26 @@ TEST(RecipeMerge, Correct) {
) << "Found:\n"
<< sources_path_str(abc_m.sources());
}

TEST(RecipeMerge, Correct2) {
auto d = std::get<build_recipe>(build_recipe::from_yaml_string( //
RECIPE_D,
"job/d.yml"
));
auto e = std::get<build_recipe>(build_recipe::from_yaml_string( //
RECIPE_E,
"job/e.yml"
));

auto de_m = std::get<build_recipe>(build_recipe::merge(d, e));

EXPECT_EQ(d.base_directory(), de_m.base_directory());

EXPECT_TRUE(contains_source_path(de_m.sources(), "d.cc"))
<< "Found:\n"
<< sources_path_str(de_m.sources());

EXPECT_TRUE(contains_source_path(de_m.sources(), "e.cc"))
<< "Found:\n"
<< sources_path_str(de_m.sources());
}

0 comments on commit 5bbdf0f

Please sign in to comment.