diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-05-08 17:29:56 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-05-09 01:11:53 +0200 |
commit | 7d94668a6a917da363acfc9294ab0f257b72fc8c (patch) | |
tree | 926731897bcdb094732d0dbb7da33b2ddc51723d /test | |
parent | fded05c6eb02faa398da8a6792baf1db73f560f2 (diff) | |
download | justbuild-7d94668a6a917da363acfc9294ab0f257b72fc8c.tar.gz |
test: Do not rely on shell built-in behavior
... in particular echo(1), which behaves different on dash
and sh.
Diffstat (limited to 'test')
-rw-r--r-- | test/buildtool/file_system/file_system_manager.test.cpp | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/test/buildtool/file_system/file_system_manager.test.cpp b/test/buildtool/file_system/file_system_manager.test.cpp index f627bf02..4b48308e 100644 --- a/test/buildtool/file_system/file_system_manager.test.cpp +++ b/test/buildtool/file_system/file_system_manager.test.cpp @@ -16,6 +16,7 @@ #include <chrono> #include <cstdlib> #include <filesystem> +#include <fstream> #include <iostream> #include "catch2/catch_test_macros.hpp" @@ -510,22 +511,10 @@ TEST_CASE("FileSystemManager", "[file_system]") { auto anchor = FileSystemManager::ChangeDirectory(test_file.parent_path()); - // assemble file creation command (escape null character) - std::string create_file_cmd{}; - create_file_cmd += "echo -n \""; - std::for_each( - test_content.begin(), test_content.end(), [&](auto const& c) { - if (c == '\0') { - create_file_cmd += std::string{"\\0"}; - } - else { - create_file_cmd += c; - } - }); - create_file_cmd += "\" > " + test_file.filename().string(); - - // run file creation command - std::system(create_file_cmd.c_str()); + std::ofstream file{test_file.filename()}; + REQUIRE(file); + file << test_content; + file.close(); // check if file exists REQUIRE(FileSystemManager::IsFile(test_file.filename())); |