aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 15:56:54 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 15:56:54 +0100
commite9bcce8dd7c018614479bab0d6e11ad53272b036 (patch)
treedc1bea01bb2fca5cc28e5b534dc746e80c67fe94
parentd6ace1a2445b8a1f530a35a925b389965f425989 (diff)
downloadpaludis-e9bcce8dd7c018614479bab0d6e11ad53272b036.tar.gz
paludis-e9bcce8dd7c018614479bab0d6e11ad53272b036.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/fs_merger_TEST.cc671
2 files changed, 291 insertions, 382 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index a61560b..c7e4c4d 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -50,7 +50,7 @@ add(`filtered_generator', `hh', `cc', `fwd', `gtest')
add(`format_messages_output_manager', `hh', `fwd', `cc')
add(`formatted_pretty_printer', `hh', `fwd', `cc')
add(`forward_at_finish_output_manager', `hh', `fwd', `cc')
-add(`fs_merger', `hh', `cc', `fwd', `se', `test', `testscript')
+add(`fs_merger', `hh', `cc', `fwd', `se', `gtest', `testscript')
add(`fuzzy_finder', `hh', `cc', `gtest')
add(`generator', `hh', `cc', `fwd', `gtest')
add(`generator_handler', `hh', `cc', `fwd')
diff --git a/paludis/fs_merger_TEST.cc b/paludis/fs_merger_TEST.cc
index 633afad..0e5c0bb 100644
--- a/paludis/fs_merger_TEST.cc
+++ b/paludis/fs_merger_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -18,8 +18,11 @@
*/
#include <paludis/fs_merger.hh>
-#include <paludis/environments/test/test_environment.hh>
#include <paludis/hooker.hh>
+#include <paludis/hook.hh>
+
+#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/safe_ifstream.hh>
@@ -30,14 +33,14 @@
#include <paludis/util/fs_iterator.hh>
#include <paludis/util/fs_path.hh>
#include <paludis/util/fs_error.hh>
-#include <paludis/hook.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+#include <paludis/util/stringify.hh>
+
#include <iterator>
#include <list>
+#include <gtest/gtest.h>
+
using namespace paludis;
-using namespace test;
namespace
{
@@ -55,10 +58,7 @@ namespace
i_set.nanoseconds() % 1000 == 0 &&
i_set.nanoseconds() / 1000 == reference.nanoseconds() / 1000);
}
-}
-namespace paludis
-{
class HookTestEnvironment :
public TestEnvironment
{
@@ -97,11 +97,7 @@ namespace paludis
}
return hooker->perform_hook(hook, optional_output_manager);
}
-}
-
-namespace
-{
struct TestMerger :
FSMerger
{
@@ -153,446 +149,359 @@ namespace
}
};
- class MergerTest :
- public TestCase
+ struct MergerAndFriends
{
- public:
- FSPath image_dir;
- FSPath root_dir;
- HookTestEnvironment env;
- TestMerger merger;
-
- bool repeatable() const
- {
- return false;
- }
-
- protected:
- MergerTest(EntryType src_type, EntryType dst_type, int n = 0) :
- TestCase("merge " + stringify(src_type) + " over " + stringify(dst_type) + (0 == n ? "" : " "
- + stringify(n))),
- image_dir("fs_merger_TEST_dir/" + stringify(src_type) + "_over_" + stringify(dst_type)
- + (0 == n ? "" : "_" + stringify(n)) + "_dir/image"),
- root_dir("fs_merger_TEST_dir/" + stringify(src_type) + "_over_" + stringify(dst_type)
- + (0 == n ? "" : "_" + stringify(n)) + "_dir/root"),
- env(FSPath("fs_merger_TEST_dir/hooks")),
- merger(make_named_values<FSMergerParams>(
- n::environment() = &env,
- n::fix_mtimes_before() = Timestamp(0, 0),
- n::get_new_ids_or_minus_one() = &get_new_ids_or_minus_one,
- n::image() = image_dir,
- n::install_under() = FSPath("/"),
- n::maybe_output_manager() = make_null_shared_ptr(),
- n::merged_entries() = std::make_shared<FSPathSet>(),
- n::no_chown() = true,
- n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
- n::root() = root_dir
- ))
- {
- }
-
- MergerTest(const std::string & custom_test,
- const MergerOptions & o = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
- const bool fix = false) :
- TestCase("merge " + custom_test + " test"),
- image_dir("fs_merger_TEST_dir/" + custom_test + "/image"),
- root_dir("fs_merger_TEST_dir/" + custom_test + "/root"),
- env(FSPath("fs_merger_TEST_dir/hooks")),
- merger(make_named_values<FSMergerParams>(
+ FSPath image_dir;
+ FSPath root_dir;
+ HookTestEnvironment env;
+ TestMerger merger;
+
+ MergerAndFriends(EntryType src_type, EntryType dst_type, int n = 0) :
+ image_dir("fs_merger_TEST_dir/" + stringify(src_type) + "_over_" + stringify(dst_type)
+ + (0 == n ? "" : "_" + stringify(n)) + "_dir/image"),
+ root_dir("fs_merger_TEST_dir/" + stringify(src_type) + "_over_" + stringify(dst_type)
+ + (0 == n ? "" : "_" + stringify(n)) + "_dir/root"),
+ env(FSPath("fs_merger_TEST_dir/hooks")),
+ merger(make_named_values<FSMergerParams>(
n::environment() = &env,
- n::fix_mtimes_before() = fix ? FSPath("fs_merger_TEST_dir/reference").stat().mtim() : Timestamp(0, 0),
+ n::fix_mtimes_before() = Timestamp(0, 0),
n::get_new_ids_or_minus_one() = &get_new_ids_or_minus_one,
n::image() = image_dir,
n::install_under() = FSPath("/"),
n::maybe_output_manager() = make_null_shared_ptr(),
n::merged_entries() = std::make_shared<FSPathSet>(),
n::no_chown() = true,
- n::options() = o,
+ n::options() = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
n::root() = root_dir
))
- {
- }
- };
-}
-
-namespace test_cases
-{
- struct MergerTestSymNothing : MergerTest
- {
- MergerTestSymNothing() : MergerTest(et_sym, et_nothing) { }
-
- void run()
- {
- TEST_CHECK(! (root_dir / "sym").stat().exists());
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "sym").stat().is_symlink());
- TEST_CHECK((root_dir / "rewrite_me").stat().is_symlink());
- TEST_CHECK_EQUAL((root_dir / "sym").readlink(), "image_dst");
- TEST_CHECK_EQUAL((root_dir / "rewrite_me").readlink(), "/rewrite_target");
- }
- } test_merger_sym_nothing;
-
- struct MergerTestSymSym : MergerTest
- {
- MergerTestSymSym() : MergerTest(et_sym, et_sym) { }
-
- void run()
- {
- TEST_CHECK((root_dir / "sym").stat().is_symlink());
- TEST_CHECK_EQUAL((root_dir / "sym").readlink(), "root_dst");
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "sym").stat().is_symlink());
- TEST_CHECK((root_dir / "rewrite_me").stat().is_symlink());
- TEST_CHECK_EQUAL((root_dir / "sym").readlink(), "image_dst");
- TEST_CHECK_EQUAL((root_dir / "rewrite_me").readlink(), "/rewrite_target");
- }
- } test_merger_sym_sym;
-
- struct MergerTestSymFile : MergerTest
- {
- MergerTestSymFile() : MergerTest(et_sym, et_file) { }
-
- void run()
{
- TEST_CHECK((root_dir / "sym").stat().is_regular_file());
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "sym").stat().is_symlink());
- TEST_CHECK((root_dir / "rewrite_me").stat().is_symlink());
- TEST_CHECK_EQUAL((root_dir / "sym").readlink(), "image_dst");
- TEST_CHECK_EQUAL((root_dir / "rewrite_me").readlink(), "/rewrite_target");
}
- } test_merger_sym_file;
-
- struct MergerTestSymDir : MergerTest
- {
- MergerTestSymDir() : MergerTest(et_sym, et_dir) { }
- void run()
+ MergerAndFriends(const std::string & custom_test,
+ const MergerOptions & o = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
+ const bool fix = false) :
+ image_dir("fs_merger_TEST_dir/" + custom_test + "/image"),
+ root_dir("fs_merger_TEST_dir/" + custom_test + "/root"),
+ env(FSPath("fs_merger_TEST_dir/hooks")),
+ merger(make_named_values<FSMergerParams>(
+ n::environment() = &env,
+ n::fix_mtimes_before() = fix ? FSPath("fs_merger_TEST_dir/reference").stat().mtim() : Timestamp(0, 0),
+ n::get_new_ids_or_minus_one() = &get_new_ids_or_minus_one,
+ n::image() = image_dir,
+ n::install_under() = FSPath("/"),
+ n::maybe_output_manager() = make_null_shared_ptr(),
+ n::merged_entries() = std::make_shared<FSPathSet>(),
+ n::no_chown() = true,
+ n::options() = o,
+ n::root() = root_dir
+ ))
{
- TEST_CHECK((root_dir / "sym").stat().is_directory());
-
- TEST_CHECK(! merger.check());
- TEST_CHECK_THROWS(merger.merge(), FSMergerError);
-
- TEST_CHECK((root_dir / "sym").stat().is_directory());
}
- } test_merger_sym_dir;
+ };
- struct MergerTestDirNothing : MergerTest
+ std::shared_ptr<MergerAndFriends> make_merger(EntryType src_type, EntryType dst_type, int n = 0)
{
- MergerTestDirNothing() : MergerTest(et_dir, et_nothing) { }
-
- void run()
- {
- TEST_CHECK(! (root_dir / "dir").stat().exists());
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "dir").stat().is_directory());
- }
- } test_merger_dir_nothing;
+ return std::make_shared<MergerAndFriends>(src_type, dst_type, n);
+ }
- struct MergerTestDirDir : MergerTest
+ std::shared_ptr<MergerAndFriends> make_merger(const std::string & custom_test,
+ const MergerOptions & o = MergerOptions() + mo_rewrite_symlinks + mo_allow_empty_dirs,
+ const bool fix = false)
{
- MergerTestDirDir() : MergerTest(et_dir, et_dir) { }
-
- void run()
- {
- TEST_CHECK((root_dir / "dir").stat().is_directory());
+ return std::make_shared<MergerAndFriends>(custom_test, o, fix);
+ }
+}
- TEST_CHECK(merger.check());
- merger.merge();
+TEST(Merger, SymNothing)
+{
+ auto data(make_merger(et_sym, et_nothing, 0));
+ ASSERT_TRUE(! (data->root_dir / "sym").stat().exists());
- TEST_CHECK((root_dir / "dir").stat().is_directory());
- }
- } test_merger_dir_dir;
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- struct MergerTestDirFile : MergerTest
- {
- MergerTestDirFile() : MergerTest(et_dir, et_file) { }
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "rewrite_me").stat().is_symlink());
+ EXPECT_EQ("image_dst", (data->root_dir / "sym").readlink());
+ EXPECT_EQ("/rewrite_target", (data->root_dir / "rewrite_me").readlink());
+}
- void run()
- {
- TEST_CHECK((root_dir / "dir").stat().is_regular_file());
+TEST(Merger, SymSym)
+{
+ auto data(make_merger(et_sym, et_sym, 0));
- TEST_CHECK(! merger.check());
- TEST_CHECK_THROWS(merger.merge(), FSMergerError);
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_symlink());
+ EXPECT_EQ("root_dst", (data->root_dir / "sym").readlink());
- TEST_CHECK((root_dir / "dir").stat().is_regular_file());
- }
- } test_merger_dir_file;
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- struct MergerTestDirSym1 : MergerTest
- {
- MergerTestDirSym1() : MergerTest(et_dir, et_sym, 1) { }
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "rewrite_me").stat().is_symlink());
+ EXPECT_EQ("image_dst", (data->root_dir / "sym").readlink());
+ EXPECT_EQ("/rewrite_target", (data->root_dir / "rewrite_me").readlink());
+}
- void run()
- {
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK((root_dir / "dir").realpath().stat().is_directory());
- TEST_CHECK(! (root_dir / "dir" / "file").stat().exists());
+TEST(Merger, SymFile)
+{
+ auto data(make_merger(et_sym, et_file, 0));
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_regular_file());
- TEST_CHECK(merger.check());
- merger.merge();
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK((root_dir / "dir").realpath().stat().is_directory());
- TEST_CHECK((root_dir / "dir" / "file").stat().is_regular_file());
- }
- } test_merger_dir_sym_1;
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "rewrite_me").stat().is_symlink());
+ EXPECT_EQ("image_dst", (data->root_dir / "sym").readlink());
+ EXPECT_EQ("/rewrite_target", (data->root_dir / "rewrite_me").readlink());
+}
- struct MergerTestDirSym2 : MergerTest
- {
- MergerTestDirSym2() : MergerTest(et_dir, et_sym, 2) { }
+TEST(Merger, SymDir)
+{
+ auto data(make_merger(et_sym, et_dir, 0));
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_directory());
- void run()
- {
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK((root_dir / "dir").realpath().stat().is_regular_file());
+ ASSERT_TRUE(! data->merger.check());
+ EXPECT_THROW(data->merger.merge(), FSMergerError);
- TEST_CHECK(! merger.check());
- TEST_CHECK_THROWS(merger.merge(), FSMergerError);
+ ASSERT_TRUE((data->root_dir / "sym").stat().is_directory());
+}
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK((root_dir / "dir").realpath().stat().is_regular_file());
- }
- } test_merger_dir_sym_2;
+TEST(Merger, DirNothing)
+{
+ auto data(make_merger(et_dir, et_nothing, 0));
+ ASSERT_TRUE(! (data->root_dir / "dir").stat().exists());
- struct MergerTestDirSym3 : MergerTest
- {
- MergerTestDirSym3() : MergerTest(et_dir, et_sym, 3) { }
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- void run()
- {
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK_THROWS((root_dir / "dir").realpath(), FSError);
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_directory());
+}
- TEST_CHECK(! merger.check());
- TEST_CHECK_THROWS(merger.merge(), FSMergerError);
+TEST(Merger, DirDir)
+{
+ auto data(make_merger(et_dir, et_dir, 0));
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_directory());
- TEST_CHECK((root_dir / "dir").stat().is_symlink());
- TEST_CHECK_THROWS((root_dir / "dir").realpath(), FSError);
- }
- } test_merger_dir_sym_3;
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- struct MergerTestFileNothing : MergerTest
- {
- MergerTestFileNothing() : MergerTest(et_file, et_nothing) { }
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_directory());
+}
- void run()
- {
- TEST_CHECK(! (root_dir / "file").stat().exists());
+TEST(Merger, DirFile)
+{
+ auto data(make_merger(et_dir, et_file, 0));
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_regular_file());
- TEST_CHECK(merger.check());
- merger.merge();
+ ASSERT_TRUE(! data->merger.check());
+ EXPECT_THROW(data->merger.merge(), FSMergerError);
- TEST_CHECK((root_dir / "file").stat().is_regular_file());
- SafeIFStream f(root_dir / "file");
- TEST_CHECK(f);
- std::string fs(std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()));
- TEST_CHECK_EQUAL(fs, "image contents\n");
- }
- } test_merger_file_nothing;
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_regular_file());
+}
- struct MergerTestFileFile : MergerTest
- {
- MergerTestFileFile() : MergerTest(et_file, et_file) { }
+TEST(Merger, DirSym1)
+{
+ auto data(make_merger(et_dir, et_sym, 1));
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "dir").realpath().stat().is_directory());
+ ASSERT_TRUE(! (data->root_dir / "dir" / "file").stat().exists());
- void run()
- {
- TEST_CHECK((root_dir / "file").stat().is_regular_file());
- SafeIFStream b(root_dir / "file");
- TEST_CHECK(b);
- std::string bs((std::istreambuf_iterator<char>(b)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(bs, "root contents\n");
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "file").stat().is_regular_file());
- SafeIFStream f(root_dir / "file");
- TEST_CHECK(f);
- std::string fs((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(fs, "image contents\n");
- }
- } test_merger_file_file;
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- struct MergerTestFileSym : MergerTest
- {
- MergerTestFileSym() : MergerTest(et_file, et_sym) { }
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "dir").realpath().stat().is_directory());
+ ASSERT_TRUE((data->root_dir / "dir" / "file").stat().is_regular_file());
+}
- void run()
- {
- TEST_CHECK((root_dir / "file1").stat().is_symlink());
- TEST_CHECK((root_dir / "file2").stat().is_symlink());
- TEST_CHECK((root_dir / "file3").stat().is_symlink());
-
- TEST_CHECK(merger.check());
- merger.merge();
-
- TEST_CHECK((root_dir / "file1").stat().is_regular_file());
- SafeIFStream f(root_dir / "file1");
- TEST_CHECK(f);
- std::string fs((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(fs, "image 1 contents\n");
-
- TEST_CHECK((root_dir / "file2").stat().is_regular_file());
- SafeIFStream f2(root_dir / "file2");
- TEST_CHECK(f2);
- std::string fs2((std::istreambuf_iterator<char>(f2)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(fs2, "image 2 contents\n");
-
- TEST_CHECK((root_dir / "file3").stat().is_regular_file());
- SafeIFStream f3(root_dir / "file3");
- TEST_CHECK(f3);
- std::string fs3((std::istreambuf_iterator<char>(f3)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(fs3, "image 3 contents\n");
- }
- } test_merger_file_sym;
+TEST(Merger, DirSym2)
+{
+ auto data(make_merger(et_dir, et_sym, 2));
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "dir").realpath().stat().is_regular_file());
- struct MergerTestFileDir : MergerTest
- {
- MergerTestFileDir() : MergerTest(et_file, et_dir) { }
+ ASSERT_TRUE(! data->merger.check());
+ EXPECT_THROW(data->merger.merge(), FSMergerError);
- void run()
- {
- TEST_CHECK((root_dir / "file").stat().is_directory());
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "dir").realpath().stat().is_regular_file());
+}
- TEST_CHECK(! merger.check());
- TEST_CHECK_THROWS(merger.merge(), FSMergerError);
+TEST(Merger, DirSym3)
+{
+ auto data(make_merger(et_dir, et_sym, 3));
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ EXPECT_THROW((data->root_dir / "dir").realpath(), FSError);
- TEST_CHECK((root_dir / "file").stat().is_directory());
- }
- } test_merger_file_dir;
+ ASSERT_TRUE(! data->merger.check());
+ EXPECT_THROW(data->merger.merge(), FSMergerError);
- struct MergerOverrideTest : MergerTest
- {
- MergerOverrideTest() : MergerTest("override") { }
+ ASSERT_TRUE((data->root_dir / "dir").stat().is_symlink());
+ EXPECT_THROW((data->root_dir / "dir").realpath(), FSError);
+}
- void run()
- {
- TEST_CHECK((image_dir / "dir_skip_me").stat().is_directory());
- TEST_CHECK((image_dir / "dir_install_me").stat().is_directory());
- TEST_CHECK((image_dir / "file_skip_me").stat().is_regular_file());
- TEST_CHECK((image_dir / "file_install_me").stat().is_regular_file());
- TEST_CHECK((image_dir / "sym_skip_me").stat().is_symlink());
- TEST_CHECK((image_dir / "sym_install_me").stat().is_symlink());
-
- TEST_CHECK(merger.check());
- merger.merge();
-
-
- TEST_CHECK(! (root_dir / "dir_skip_me").stat().exists());
- TEST_CHECK((root_dir / "dir_install_me").stat().is_directory());
- TEST_CHECK(! (root_dir / "file_skip_me").stat().exists());
- TEST_CHECK((root_dir / "file_install_me").stat().is_regular_file());
- TEST_CHECK(! (root_dir / "sym_skip_me").stat().exists());
- TEST_CHECK((root_dir / "sym_install_me").stat().is_symlink());
- }
- } test_merger_override;
+TEST(Merger, FileNothing)
+{
+ auto data(make_merger(et_file, et_nothing, 0));
+ ASSERT_TRUE(! (data->root_dir / "file").stat().exists());
- struct MergerEmptyDirAllowedTest : MergerTest
- {
- MergerEmptyDirAllowedTest() : MergerTest("empty_dir_allowed", { mo_allow_empty_dirs }) { }
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- void run()
- {
- TEST_CHECK((image_dir / "empty").stat().is_directory());
- TEST_CHECK(FSIterator(image_dir / "empty", { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+ ASSERT_TRUE((data->root_dir / "file").stat().is_regular_file());
+ SafeIFStream f(data->root_dir / "file");
+ ASSERT_TRUE(f);
+ std::string fs(std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()));
+ EXPECT_EQ("image contents\n", fs);
+}
- TEST_CHECK(merger.check());
- }
- } test_merger_empty_dir_allowed;
+TEST(Merger, FileFile)
+{
+ auto data(make_merger(et_file, et_file, 0));
+ ASSERT_TRUE((data->root_dir / "file").stat().is_regular_file());
+ SafeIFStream b(data->root_dir / "file");
+ ASSERT_TRUE(b);
+ std::string bs((std::istreambuf_iterator<char>(b)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("root contents\n", bs);
+
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
+
+ ASSERT_TRUE((data->root_dir / "file").stat().is_regular_file());
+ SafeIFStream f(data->root_dir / "file");
+ ASSERT_TRUE(f);
+ std::string fs((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("image contents\n", fs);
+}
- struct MergerEmptyDirDisallowedTest : MergerTest
- {
- MergerEmptyDirDisallowedTest() : MergerTest("empty_dir_disallowed", { }) { }
+TEST(Merger, FileSym)
+{
+ auto data(make_merger(et_file, et_sym, 0));
+ ASSERT_TRUE((data->root_dir / "file1").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "file2").stat().is_symlink());
+ ASSERT_TRUE((data->root_dir / "file3").stat().is_symlink());
+
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
+
+ ASSERT_TRUE((data->root_dir / "file1").stat().is_regular_file());
+ SafeIFStream f(data->root_dir / "file1");
+ ASSERT_TRUE(f);
+ std::string fs((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("image 1 contents\n", fs);
+
+ ASSERT_TRUE((data->root_dir / "file2").stat().is_regular_file());
+ SafeIFStream f2(data->root_dir / "file2");
+ ASSERT_TRUE(f2);
+ std::string fs2((std::istreambuf_iterator<char>(f2)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("image 2 contents\n", fs2);
+
+ ASSERT_TRUE((data->root_dir / "file3").stat().is_regular_file());
+ SafeIFStream f3(data->root_dir / "file3");
+ ASSERT_TRUE(f3);
+ std::string fs3((std::istreambuf_iterator<char>(f3)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("image 3 contents\n", fs3);
+}
- void run()
- {
- TEST_CHECK((image_dir / "empty").stat().is_directory());
- TEST_CHECK(FSIterator(image_dir / "empty", { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+TEST(Merger, FileDir)
+{
+ auto data(make_merger(et_file, et_dir, 0));
+ ASSERT_TRUE((data->root_dir / "file").stat().is_directory());
- TEST_CHECK(! merger.check());
- }
- } test_merger_empty_dir_disallowed;
+ ASSERT_TRUE(! data->merger.check());
+ EXPECT_THROW(data->merger.merge(), FSMergerError);
- struct MergerEmptyRootAllowedTest : MergerTest
- {
- MergerEmptyRootAllowedTest() : MergerTest("empty_root_allowed", { mo_allow_empty_dirs }) { }
+ ASSERT_TRUE((data->root_dir / "file").stat().is_directory());
+}
- void run()
- {
- TEST_CHECK(FSIterator(image_dir, { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+TEST(Merger, Override)
+{
+ auto data(make_merger("override"));
+
+ ASSERT_TRUE((data->image_dir / "dir_skip_me").stat().is_directory());
+ ASSERT_TRUE((data->image_dir / "dir_install_me").stat().is_directory());
+ ASSERT_TRUE((data->image_dir / "file_skip_me").stat().is_regular_file());
+ ASSERT_TRUE((data->image_dir / "file_install_me").stat().is_regular_file());
+ ASSERT_TRUE((data->image_dir / "sym_skip_me").stat().is_symlink());
+ ASSERT_TRUE((data->image_dir / "sym_install_me").stat().is_symlink());
+
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
+
+ ASSERT_TRUE(! (data->root_dir / "dir_skip_me").stat().exists());
+ ASSERT_TRUE((data->root_dir / "dir_install_me").stat().is_directory());
+ ASSERT_TRUE(! (data->root_dir / "file_skip_me").stat().exists());
+ ASSERT_TRUE((data->root_dir / "file_install_me").stat().is_regular_file());
+ ASSERT_TRUE(! (data->root_dir / "sym_skip_me").stat().exists());
+ ASSERT_TRUE((data->root_dir / "sym_install_me").stat().is_symlink());
+}
- TEST_CHECK(merger.check());
- }
- } test_merger_empty_root_allowed;
+TEST(Merger, EmptyDirAllowed)
+{
+ auto data(make_merger("empty_dir_allowed", { mo_allow_empty_dirs }));
+ ASSERT_TRUE((data->image_dir / "empty").stat().is_directory());
+ ASSERT_TRUE(FSIterator(data->image_dir / "empty", { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
- struct MergerEmptyRootDisallowedTest : MergerTest
- {
- MergerEmptyRootDisallowedTest() : MergerTest("empty_root_disallowed", { }) { }
+ ASSERT_TRUE(data->merger.check());
+}
- void run()
- {
- TEST_CHECK(FSIterator(image_dir, { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+TEST(Merger, EmptyDirDisallowed)
+{
+ auto data(make_merger("empty_dir_disallowed", { }));
+ ASSERT_TRUE((data->image_dir / "empty").stat().is_directory());
+ ASSERT_TRUE(FSIterator(data->image_dir / "empty", { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
- TEST_CHECK(! merger.check());
- }
- } test_merger_empty_root_disallowed;
+ ASSERT_TRUE(! data->merger.check());
+}
- struct MergerMtimesTest : MergerTest
- {
- MergerMtimesTest() : MergerTest("mtimes", { mo_preserve_mtimes }) { }
+TEST(Merger, EmptyRootAllowed)
+{
+ auto data(make_merger("empty_root_allowed", { mo_allow_empty_dirs }));
+ ASSERT_TRUE(FSIterator(data->image_dir, { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+ ASSERT_TRUE(data->merger.check());
+}
- void run()
- {
- Timestamp m_new((image_dir / "new_file").stat().mtim());
- Timestamp m_existing((image_dir / "existing_file").stat().mtim());
- Timestamp m_dir_new((image_dir / "dir" / "new_file").stat().mtim());
+TEST(Merger, EmptyRootDisallowed)
+{
+ auto data(make_merger("empty_root_disallowed", { }));
+ ASSERT_TRUE(FSIterator(data->image_dir, { fsio_include_dotfiles, fsio_first_only }) == FSIterator());
+ ASSERT_TRUE(! data->merger.check());
+}
- TEST_CHECK(merger.check());
- merger.merge();
+TEST(Merger, Mtimes)
+{
+ auto data(make_merger("mtimes", { mo_preserve_mtimes }));
+ Timestamp m_new((data->image_dir / "new_file").stat().mtim());
+ Timestamp m_existing((data->image_dir / "existing_file").stat().mtim());
+ Timestamp m_dir_new((data->image_dir / "dir" / "new_file").stat().mtim());
- TEST_CHECK(timestamps_nearly_equal((root_dir / "new_file").stat().mtim(), m_new));
- TEST_CHECK(timestamps_nearly_equal((root_dir / "existing_file").stat().mtim(), m_existing));
- TEST_CHECK(Timestamp::now().seconds() - (root_dir / "dodgy_file").stat().mtim().seconds() >= (60 * 60 * 24 * 365 * 3) - 1);
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- TEST_CHECK(timestamps_nearly_equal((root_dir / "dir" / "new_file").stat().mtim(), m_dir_new));
- TEST_CHECK(Timestamp::now().seconds() - (root_dir / "dir" / "dodgy_file").stat().mtim().seconds() >= (60 * 60 * 24 * 365 * 3) - 1);
- }
- } test_merger_mtimes;
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "new_file").stat().mtim(), m_new));
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "existing_file").stat().mtim(), m_existing));
+ ASSERT_TRUE(Timestamp::now().seconds() - (data->root_dir / "dodgy_file").stat().mtim().seconds() >= (60 * 60 * 24 * 365 * 3) - 1);
- struct MergerMtimesFixTest : MergerTest
- {
- MergerMtimesFixTest() : MergerTest("mtimes_fix", { mo_preserve_mtimes }, true) { }
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "dir" / "new_file").stat().mtim(), m_dir_new));
+ ASSERT_TRUE(Timestamp::now().seconds() - (data->root_dir / "dir" / "dodgy_file").stat().mtim().seconds() >= (60 * 60 * 24 * 365 * 3) - 1);
+}
- void run()
- {
- Timestamp m_new((image_dir / "new_file").stat().mtim());
- Timestamp m_existing((image_dir / "existing_file").stat().mtim());
- Timestamp m_dir_new((image_dir / "dir" / "new_file").stat().mtim());
+TEST(Merger, MtimesFixes)
+{
+ auto data(make_merger("mtimes_fix", { mo_preserve_mtimes }, true));
+ Timestamp m_new((data->image_dir / "new_file").stat().mtim());
+ Timestamp m_existing((data->image_dir / "existing_file").stat().mtim());
+ Timestamp m_dir_new((data->image_dir / "dir" / "new_file").stat().mtim());
- TEST_CHECK(merger.check());
- merger.merge();
+ ASSERT_TRUE(data->merger.check());
+ data->merger.merge();
- TEST_CHECK(timestamps_nearly_equal((root_dir / "new_file").stat().mtim(), m_new));
- TEST_CHECK(timestamps_nearly_equal((root_dir / "existing_file").stat().mtim(), m_existing));
- TEST_CHECK(timestamps_nearly_equal((root_dir / "dodgy_file").stat().mtim(), FSPath("fs_merger_TEST_dir/reference").stat().mtim()));
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "new_file").stat().mtim(), m_new));
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "existing_file").stat().mtim(), m_existing));
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "dodgy_file").stat().mtim(), FSPath("fs_merger_TEST_dir/reference").stat().mtim()));
- TEST_CHECK(timestamps_nearly_equal((root_dir / "dir" / "new_file").stat().mtim(), m_dir_new));
- TEST_CHECK(timestamps_nearly_equal((root_dir / "dir" / "dodgy_file").stat().mtim(), FSPath("fs_merger_TEST_dir/reference").stat().mtim()));
- }
- } test_merger_mtimes_fix;
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "dir" / "new_file").stat().mtim(), m_dir_new));
+ ASSERT_TRUE(timestamps_nearly_equal((data->root_dir / "dir" / "dodgy_file").stat().mtim(), FSPath("fs_merger_TEST_dir/reference").stat().mtim()));
}