From c4019cde1141bda0f522a41134234426e3f4e186 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 25 Jan 2022 14:18:32 +0100 Subject: [PATCH] Test: Add test case for selectively commenting --- test/testdotfile.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/test/testdotfile.cpp b/test/testdotfile.cpp index 50e53f8..764f8ee 100644 --- a/test/testdotfile.cpp +++ b/test/testdotfile.cpp @@ -223,6 +223,101 @@ TEST_CASE(PushDotfilesWithExcludePath) removeTestDotfiles(fileNames); } +TEST_CASE(PushDotfilesSelectivelyComment) +{ + std::vector fileNames = { + "__test-file-1", + "__test-file-2", + "__test-file-3", + "__test-file-4", + "__test-file-5", + "__test-file-6", + "__test-file-7", + }; + + auto distro = Machine::the().distroId(); + auto hostname = Machine::the().hostname(); + auto username = Machine::the().username(); + std::string placeholder = "@@@@"; + + std::vector fileContents = { + "# >>> distro=" + distro + " hostname=" + hostname + " user=" + username + R"( +# this should be uncommented +# <<< +)", + "# >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + R"( +# this should remain commented +# <<< +)", + "# >>> distro=" + distro + " hostname=" + placeholder + " user=" + username + R"( +# this should remain commented +# <<< +)", + "# >>> distro=" + distro + " hostname=" + hostname + " user=" + placeholder + R"( +this should be commented +# <<< +)", + " # >>> distro=" + distro + R"( + # this should be uncommented + # <<< +)", + " # >>> user=" + username + R"( + # this should be uncommented + # <<< +)", + " # >>> hostname=" + hostname + R"( + this should remain uncommented + # <<< +)", + }; + + std::vector pushedFileContents = { + "# >>> distro=" + distro + " hostname=" + hostname + " user=" + username + R"( +this should be uncommented +# <<< +)", + "# >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + R"( +# this should remain commented +# <<< +)", + "# >>> distro=" + distro + " hostname=" + placeholder + " user=" + username + R"( +# this should remain commented +# <<< +)", + "# >>> distro=" + distro + " hostname=" + hostname + " user=" + placeholder + R"( +# this should be commented +# <<< +)", + " # >>> distro=" + distro + R"( + this should be uncommented + # <<< +)", + " # >>> user=" + username + R"( + this should be uncommented + # <<< +)", + " # >>> hostname=" + hostname + R"( + this should remain uncommented + # <<< +)", + }; + + createTestDotfiles(fileNames, fileContents); + + Dotfile::the().push(fileNames); + + for (size_t i = 0; i < fileNames.size(); ++i) { + const auto& file = fileNames.at(i); + VERIFY(std::filesystem::exists(file), continue); + VERIFY(std::filesystem::exists(homeDirectory / file), continue); + + Util::File lhs(homeDirectory / file); + EXPECT_EQ(lhs.data(), pushedFileContents.at(i)); + } + + removeTestDotfiles(fileNames); +} + TEST_CASE(AddSystemDotfiles) { VERIFY(geteuid() == 0, return);