From a649c46a47b076f5988430af4ec1d4579485dc05 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 11 Nov 2023 20:17:09 +1300 Subject: [PATCH] tests: add a test for a failure applying patch adding file It seems that for this case we are assuming that everything is fine, and will apply the patch even though: 1. The file already exists! (GNU patch seems to warn for this case) 2. Even after confirming that we do not mind that the file already exists, we do not detect that there the content in that file _should_ cause that patch to fail. --- tests/test_applier.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_applier.cpp b/tests/test_applier.cpp index 3945ef2..414221e 100644 --- a/tests/test_applier.cpp +++ b/tests/test_applier.cpp @@ -1138,3 +1138,44 @@ PATCH_TEST(applier_multi_line_addition_from_empty_file) } )"); } + +PATCH_TEST(PATCH_XFAIL_applier_add_file_but_file_already_exits_with_conflicts) +{ + { + Patch::File file("diff.patch", std::ios_base::out); + file << R"( +--- /dev/null 2023-10-31 17:55:44.017202200 +1300 ++++ a 2023-11-11 20:05:33.898828568 +1300 +@@ -0,0 +1,4 @@ ++1 ++2 ++3 ++4 +)"; + } + + const std::string file_contents = R"(a +b +c +d +)"; + + { + Patch::File file("a", std::ios_base::out); + file << file_contents; + } + + Process process(patch_path, { patch_path, "-f", "-i", "diff.patch", nullptr }); + + EXPECT_EQ(process.stdout_data(), R"(The next patch would create the file a, +which already exists! Applying it anyway. +patching file a +Hunk #1 FAILED at 1. +1 out of 1 hunk FAILED -- saving rejects to file a.rej +)"); + + EXPECT_EQ(process.stderr_data(), ""); + EXPECT_EQ(process.return_code(), 1); + + EXPECT_FILE_EQ("a", file_contents); +}