From 65fc11ff28e6dd29a95391b6700a02d277b539c6 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 8 Apr 2024 12:28:31 +0200 Subject: Test ["utils/archive", "archive_usage"]: fix assumptions on path This test, among others, verifies the archive functionality by creating an archive with our library, extractting it with the system command-line tools, and comparing the result. In order to not depend on the host system having installed tools for all possible compression algorithms, it tacitly drops the extraction test if the respective tool could not be found under /usr/bin. This, however, assumes that /usr/bin is in path; ensure this, by extending PATH accordingly. --- test/utils/archive/archive_usage.test.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'test/utils/archive/archive_usage.test.cpp') diff --git a/test/utils/archive/archive_usage.test.cpp b/test/utils/archive/archive_usage.test.cpp index 6a8eb751..1be69139 100644 --- a/test/utils/archive/archive_usage.test.cpp +++ b/test/utils/archive/archive_usage.test.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include @@ -358,10 +359,14 @@ TEST_CASE("Read-write archives", "[archive_read_write]") { } if (tools_exist) { + std::string path{"/usr/bin"}; + if (auto* env_path = std::getenv("PATH")) { + path = std::string{env_path} + ":" + path; + } SECTION("Extract via system tools") { - REQUIRE( - system((scenario.cmd + " " + scenario.filename).c_str()) == - 0); + REQUIRE(system(("export PATH=" + path + " && " + scenario.cmd + + " " + scenario.filename) + .c_str()) == 0); compare_extracted(); } } @@ -408,15 +413,18 @@ TEST_CASE("ArchiveOps", "[archive_ops]") { std::string("/usr/bin/") + tool); } if (tools_exist) { + std::string path{"/usr/bin"}; + if (auto* env_path = std::getenv("PATH")) { + path = std::string{env_path} + ":" + path; + } SECTION("Extract via system tools") { REQUIRE( FileSystemManager::RemoveDirectory(scenario.test_dir, /*recursively=*/true)); REQUIRE(FileSystemManager::CreateDirectory(scenario.test_dir)); - - REQUIRE( - system((scenario.cmd + " " + scenario.filename).c_str()) == - 0); + REQUIRE(system(("export PATH=" + path + " && " + scenario.cmd + + " " + scenario.filename) + .c_str()) == 0); compare_extracted(scenario.test_dir); } } -- cgit v1.2.3