From de9fc75a961eea20aba6eeb3fc56d2e9f8d8f494 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 7 Mar 2022 13:23:13 +0100 Subject: FileSystemManager: Implement fd-less file copy --- .../file_system/file_system_manager.test.cpp | 102 ++++++++++++--------- 1 file changed, 60 insertions(+), 42 deletions(-) (limited to 'test/buildtool/file_system/file_system_manager.test.cpp') diff --git a/test/buildtool/file_system/file_system_manager.test.cpp b/test/buildtool/file_system/file_system_manager.test.cpp index 84f9e8a3..2d0016cf 100644 --- a/test/buildtool/file_system/file_system_manager.test.cpp +++ b/test/buildtool/file_system/file_system_manager.test.cpp @@ -167,30 +167,13 @@ TEST_CASE("ReadFile", "[file_system]") { } TEST_CASE_METHOD(CopyFileFixture, "CopyFile", "[file_system]") { - // Copy file was successful - CHECK(FileSystemManager::CopyFile(from_, to_)); - - // file exists - CHECK(std::filesystem::exists(to_)); - CHECK(std::filesystem::is_regular_file(to_)); - - // Contents are equal - auto const content_from = FileSystemManager::ReadFile(from_); - CHECK(content_from.has_value()); - auto const content_to = FileSystemManager::ReadFile(to_); - CHECK(content_to.has_value()); - CHECK(content_from == content_to); -} - -TEST_CASE_METHOD(CopyFileFixture, "CopyFileAs", "[file_system]") { - SECTION("as file") { - // Copy as file was successful - CHECK(FileSystemManager::CopyFileAs(from_, to_, ObjectType::File)); + auto run_test = [&](bool fd_less) { + // Copy file was successful + CHECK(FileSystemManager::CopyFile(from_, to_, fd_less)); // file exists CHECK(std::filesystem::exists(to_)); CHECK(std::filesystem::is_regular_file(to_)); - CHECK(not FileSystemManager::IsExecutable(to_)); // Contents are equal auto const content_from = FileSystemManager::ReadFile(from_); @@ -198,29 +181,62 @@ TEST_CASE_METHOD(CopyFileFixture, "CopyFileAs", "[file_system]") { auto const content_to = FileSystemManager::ReadFile(to_); CHECK(content_to.has_value()); CHECK(content_from == content_to); + }; - // permissions should be 0444 - CHECK(HasFilePermissions(to_)); + SECTION("direct") { run_test(false); } + SECTION("fd_less") { run_test(true); } +} + +TEST_CASE_METHOD(CopyFileFixture, "CopyFileAs", "[file_system]") { + SECTION("as file") { + auto run_test = [&](bool fd_less) { + // Copy as file was successful + CHECK(FileSystemManager::CopyFileAs( + from_, to_, ObjectType::File, fd_less)); + + // file exists + CHECK(std::filesystem::exists(to_)); + CHECK(std::filesystem::is_regular_file(to_)); + CHECK(not FileSystemManager::IsExecutable(to_)); + + // Contents are equal + auto const content_from = FileSystemManager::ReadFile(from_); + CHECK(content_from.has_value()); + auto const content_to = FileSystemManager::ReadFile(to_); + CHECK(content_to.has_value()); + CHECK(content_from == content_to); + + // permissions should be 0444 + CHECK(HasFilePermissions(to_)); + }; + + SECTION("direct") { run_test(false); } + SECTION("fd_less") { run_test(true); } } SECTION("as executable") { - // Copy as file was successful - CHECK( - FileSystemManager::CopyFileAs(from_, to_, ObjectType::Executable)); - - // file exists - CHECK(std::filesystem::exists(to_)); - CHECK(std::filesystem::is_regular_file(to_)); - CHECK(FileSystemManager::IsExecutable(to_)); - - // Contents are equal - auto const content_from = FileSystemManager::ReadFile(from_); - CHECK(content_from.has_value()); - auto const content_to = FileSystemManager::ReadFile(to_); - CHECK(content_to.has_value()); - CHECK(content_from == content_to); - - // permissions should be 0555 - CHECK(HasExecutablePermissions(to_)); + auto run_test = [&](bool fd_less) { + // Copy as file was successful + CHECK(FileSystemManager::CopyFileAs( + from_, to_, ObjectType::Executable, fd_less)); + + // file exists + CHECK(std::filesystem::exists(to_)); + CHECK(std::filesystem::is_regular_file(to_)); + CHECK(FileSystemManager::IsExecutable(to_)); + + // Contents are equal + auto const content_from = FileSystemManager::ReadFile(from_); + CHECK(content_from.has_value()); + auto const content_to = FileSystemManager::ReadFile(to_); + CHECK(content_to.has_value()); + CHECK(content_from == content_to); + + // permissions should be 0555 + CHECK(HasExecutablePermissions(to_)); + }; + + SECTION("direct") { run_test(false); } + SECTION("fd_less") { run_test(true); } } } @@ -357,8 +373,10 @@ TEST_CASE("FileSystemManager", "[file_system]") { CHECK(file_content == test_content); // copy file without 'overwrite' - CHECK(FileSystemManager::CopyFile( - test_file, copy_file, std::filesystem::copy_options::none)); + CHECK(FileSystemManager::CopyFile(test_file, + copy_file, + /*fd_less=*/false, + std::filesystem::copy_options::none)); // copy file with 'overwrite' CHECK(FileSystemManager::CopyFile(copy_file, test_file)); -- cgit v1.2.3