From 37411da421974c32062a3aae4939e2e740f65081 Mon Sep 17 00:00:00 2001 From: "Klaus T. Aehlig" Date: Tue, 6 Feb 2024 20:20:41 +0100 Subject: executor tests: only use hard-coded paths if no PATH is provided --- .../executor/executor_api.test.hpp | 43 +++++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) mode change 100755 => 100644 test/buildtool/execution_engine/executor/executor_api.test.hpp (limited to 'test') diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp old mode 100755 new mode 100644 index ad7a5216..5f951e8d --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -91,12 +91,20 @@ static inline void RunHelloWorldCompilation(RepositoryConfig* repo_config, ArtifactDescription{path{"data/hello_world/main.cpp"}, ""}; auto const& main_cpp_id = main_cpp_desc.Id(); std::string const make_hello_id = "make_hello"; + auto* env_path = std::getenv("PATH"); + std::map env{}; + if (env_path != nullptr) { + env.emplace("PATH", env_path); + } + else { + env.emplace("PATH", "/bin:/usr/bin"); + } auto const make_hello_desc = ActionDescription{ {"out/hello_world"}, {}, Action{make_hello_id, {"c++", "src/main.cpp", "-o", "out/hello_world"}, - {{"PATH", "/bin:/usr/bin"}}}, + env}, {{"src/main.cpp", main_cpp_desc}}}; auto const exec_desc = ArtifactDescription{make_hello_id, "out/hello_world"}; @@ -155,6 +163,14 @@ static inline void RunGreeterCompilation(RepositoryConfig* repo_config, auto const& greet_cpp_id = greet_cpp_desc.Id(); std::string const compile_greet_id = "compile_greet"; + auto* env_path = std::getenv("PATH"); + std::map env{}; + if (env_path != nullptr) { + env.emplace("PATH", env_path); + } + else { + env.emplace("PATH", "/bin:/usr/bin"); + } auto const compile_greet_desc = ActionDescription{{"out/greet.o"}, {}, @@ -166,7 +182,7 @@ static inline void RunGreeterCompilation(RepositoryConfig* repo_config, "include", "-o", "out/greet.o"}, - {{"PATH", "/bin:/usr/bin"}}}, + env}, {{"include/greet.hpp", greet_hpp_desc}, {"src/greet.cpp", greet_cpp_desc}}}; @@ -178,7 +194,7 @@ static inline void RunGreeterCompilation(RepositoryConfig* repo_config, auto const make_lib_desc = ActionDescription{ {"out/libgreet.a"}, {}, - Action{make_lib_id, {"ar", "rcs", "out/libgreet.a", "greet.o"}, {}}, + Action{make_lib_id, {"ar", "rcs", "out/libgreet.a", "greet.o"}, env}, {{"greet.o", greet_o_desc}}}; auto const main_cpp_desc = @@ -203,7 +219,7 @@ static inline void RunGreeterCompilation(RepositoryConfig* repo_config, "-lgreet", "-o", "out/greeter"}, - {{"PATH", "/bin:/usr/bin"}}}, + env}, {{"src/main.cpp", main_cpp_desc}, {"include/greet.hpp", greet_hpp_desc}, {"lib/libgreet.a", libgreet_desc}}}; @@ -463,12 +479,19 @@ static inline void TestRetrieveOutputDirectories(RepositoryConfig* repo_config, auto create_action = [&make_tree_id, make_tree_cmd]( std::vector&& out_files, std::vector&& out_dirs) { - return ActionDescription{std::move(out_files), - std::move(out_dirs), - Action{make_tree_id, - {"sh", "-c", make_tree_cmd}, - {{"PATH", "/bin:/usr/bin"}}}, - {}}; + auto* env_path = std::getenv("PATH"); + std::map env{}; + if (env_path != nullptr) { + env.emplace("PATH", env_path); + } + else { + env.emplace("PATH", "/bin:/usr/bin"); + } + return ActionDescription{ + std::move(out_files), + std::move(out_dirs), + Action{make_tree_id, {"sh", "-c", make_tree_cmd}, env}, + {}}; }; SECTION("entire action output as directory") { -- cgit v1.2.3