diff options
Diffstat (limited to 'paludis/set_file_TEST.cc')
-rw-r--r-- | paludis/set_file_TEST.cc | 315 |
1 files changed, 144 insertions, 171 deletions
diff --git a/paludis/set_file_TEST.cc b/paludis/set_file_TEST.cc index 83b485669..0b016f3b6 100644 --- a/paludis/set_file_TEST.cc +++ b/paludis/set_file_TEST.cc @@ -18,20 +18,21 @@ */ #include <paludis/set_file.hh> +#include <paludis/dep_spec.hh> +#include <paludis/user_dep_spec.hh> + #include <paludis/environments/test/test_environment.hh> + #include <paludis/util/make_named_values.hh> #include <paludis/util/safe_ifstream.hh> #include <paludis/util/indirect_iterator-impl.hh> #include <paludis/util/accept_visitor.hh> -#include <paludis/dep_spec.hh> -#include <paludis/user_dep_spec.hh> - -#include <test/test_runner.hh> -#include <test/test_framework.hh> +#include <paludis/util/stringify.hh> #include <algorithm> -using namespace test; +#include <gtest/gtest.h> + using namespace paludis; namespace @@ -59,182 +60,154 @@ namespace }; } -namespace test_cases +TEST(SetFile, Simple) { - struct SimpleTest : TestCase + using namespace std::placeholders; + + TestEnvironment env; + + SetFile f(make_named_values<SetFileParams>( + n::environment() = static_cast<Environment *>(0), + n::file_name() = FSPath("set_file_TEST_dir/simple1"), + n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), + n::set_operator_mode() = sfsmo_natural, + n::type() = sft_simple + )); + { - SimpleTest() : TestCase("simple set file") { } + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( foo/bar >=bar/baz-1.23 ) ", stringify(p.s.str())); + } - void run() - { - using namespace std::placeholders; - - TestEnvironment env; - - SetFile f(make_named_values<SetFileParams>( - n::environment() = static_cast<Environment *>(0), - n::file_name() = FSPath("set_file_TEST_dir/simple1"), - n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), - n::set_operator_mode() = sfsmo_natural, - n::type() = sft_simple - )); - - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( foo/bar >=bar/baz-1.23 ) "); - } - - f.add("foo/bar"); - f.add("moo/oink"); - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( foo/bar >=bar/baz-1.23 moo/oink ) "); - } - - f.rewrite(); - - { - SafeIFStream ff(FSPath("set_file_TEST_dir/simple1")); - TEST_CHECK(ff); - std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); - TEST_CHECK_EQUAL(g, "# this is a comment\n\nfoo/bar\n>=bar/baz-1.23\n\n# the end\nmoo/oink\n"); - } - - TEST_CHECK(f.remove(">=bar/baz-1.23")); - TEST_CHECK(! f.remove("bar/cow")); - - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( foo/bar moo/oink ) "); - } - - f.rewrite(); - - { - SafeIFStream ff(FSPath("set_file_TEST_dir/simple1")); - TEST_CHECK(ff); - std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); - TEST_CHECK_EQUAL(g, "# this is a comment\n\nfoo/bar\n\n# the end\nmoo/oink\n"); - } - } + f.add("foo/bar"); + f.add("moo/oink"); + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( foo/bar >=bar/baz-1.23 moo/oink ) ", stringify(p.s.str())); + } - bool repeatable() const - { - return false; - } - } test_simple; + f.rewrite(); - struct PaludisConfTest : TestCase { - PaludisConfTest() : TestCase("paludis .conf set file") { } + SafeIFStream ff(FSPath("set_file_TEST_dir/simple1")); + ASSERT_TRUE(ff); + std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); + EXPECT_EQ("# this is a comment\n\nfoo/bar\n>=bar/baz-1.23\n\n# the end\nmoo/oink\n", g); + } - void run() - { - using namespace std::placeholders; - - TestEnvironment env; - - SetFile f(make_named_values<SetFileParams>( - n::environment() = static_cast<Environment *>(0), - n::file_name() = FSPath("set_file_TEST_dir/paludisconf1"), - n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), - n::set_operator_mode() = sfsmo_natural, - n::type() = sft_paludis_conf - )); - - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( >=bar/baz-1.23 set ) "); - } - - f.add("foo/bar"); - f.add("moo/oink"); - f.add("settee"); - f.add("couch"); - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( >=bar/baz-1.23 set moo/oink couch ) "); - } - - f.rewrite(); - - { - SafeIFStream ff(FSPath("set_file_TEST_dir/paludisconf1")); - TEST_CHECK(ff); - std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); - TEST_CHECK_EQUAL(g, "# this is a comment\n\n? foo/bar\n* >=bar/baz-1.23\n\n* set\n? settee\n\n# the end\n* moo/oink\n* couch\n"); - } - - TEST_CHECK(f.remove(">=bar/baz-1.23")); - TEST_CHECK(! f.remove("bar/cow")); - TEST_CHECK(f.remove("set")); - - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( moo/oink couch ) "); - } - - f.rewrite(); - - { - SafeIFStream ff(FSPath("set_file_TEST_dir/paludisconf1")); - TEST_CHECK(ff); - std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); - TEST_CHECK_EQUAL(g, "# this is a comment\n\n? foo/bar\n\n? settee\n\n# the end\n* moo/oink\n* couch\n"); - } - } + EXPECT_TRUE(f.remove(">=bar/baz-1.23")); + EXPECT_TRUE(! f.remove("bar/cow")); - bool repeatable() const - { - return false; - } - } test_paludis_conf; + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( foo/bar moo/oink ) ", stringify(p.s.str())); + } + + f.rewrite(); - struct OverrideTest : TestCase { - OverrideTest() : TestCase("operator overrides") { } + SafeIFStream ff(FSPath("set_file_TEST_dir/simple1")); + ASSERT_TRUE(ff); + std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); + EXPECT_EQ("# this is a comment\n\nfoo/bar\n\n# the end\nmoo/oink\n", g); + } +} - void run() - { - using namespace std::placeholders; - - TestEnvironment env; - - SetFile f(make_named_values<SetFileParams>( - n::environment() = static_cast<Environment *>(0), - n::file_name() = FSPath("set_file_TEST_dir/override"), - n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), - n::set_operator_mode() = sfsmo_natural, - n::type() = sft_paludis_conf - )); - - { - SetSpecStringifier p; - f.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( >=bar/bar-1.23 set set2* ) "); - } - - SetFile fstar(make_named_values<SetFileParams>( - n::environment() = static_cast<Environment *>(0), - n::file_name() = FSPath("set_file_TEST_dir/override"), - n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), - n::set_operator_mode() = sfsmo_star, - n::type() = sft_paludis_conf - )); - - { - SetSpecStringifier p; - fstar.contents()->top()->accept(p); - TEST_CHECK_STRINGIFY_EQUAL(p.s.str(), "( foo/foo >=bar/bar-1.23 >=baz/baz-1.23 set* set2* ) "); - } +TEST(SetFile, PaludisConf) +{ + using namespace std::placeholders; + + TestEnvironment env; + + SetFile f(make_named_values<SetFileParams>( + n::environment() = static_cast<Environment *>(0), + n::file_name() = FSPath("set_file_TEST_dir/paludisconf1"), + n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), + n::set_operator_mode() = sfsmo_natural, + n::type() = sft_paludis_conf + )); + + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( >=bar/baz-1.23 set ) ", stringify(p.s.str())); + } + + f.add("foo/bar"); + f.add("moo/oink"); + f.add("settee"); + f.add("couch"); + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( >=bar/baz-1.23 set moo/oink couch ) ", stringify(p.s.str())); + } + + f.rewrite(); + + { + SafeIFStream ff(FSPath("set_file_TEST_dir/paludisconf1")); + ASSERT_TRUE(ff); + std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); + EXPECT_EQ("# this is a comment\n\n? foo/bar\n* >=bar/baz-1.23\n\n* set\n? settee\n\n# the end\n* moo/oink\n* couch\n", g); + } + + EXPECT_TRUE(f.remove(">=bar/baz-1.23")); + EXPECT_TRUE(! f.remove("bar/cow")); + EXPECT_TRUE(f.remove("set")); + + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( moo/oink couch ) ", stringify(p.s.str())); + } + + f.rewrite(); + + { + SafeIFStream ff(FSPath("set_file_TEST_dir/paludisconf1")); + ASSERT_TRUE(ff); + std::string g((std::istreambuf_iterator<char>(ff)), std::istreambuf_iterator<char>()); + EXPECT_EQ("# this is a comment\n\n? foo/bar\n\n? settee\n\n# the end\n* moo/oink\n* couch\n", g); + } +} + +TEST(SetFile, Overrides) +{ + using namespace std::placeholders; + + TestEnvironment env; + + SetFile f(make_named_values<SetFileParams>( + n::environment() = static_cast<Environment *>(0), + n::file_name() = FSPath("set_file_TEST_dir/override"), + n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), + n::set_operator_mode() = sfsmo_natural, + n::type() = sft_paludis_conf + )); + + { + SetSpecStringifier p; + f.contents()->top()->accept(p); + EXPECT_EQ("( >=bar/bar-1.23 set set2* ) ", stringify(p.s.str())); + } + + SetFile fstar(make_named_values<SetFileParams>( + n::environment() = static_cast<Environment *>(0), + n::file_name() = FSPath("set_file_TEST_dir/override"), + n::parser() = std::bind(&parse_user_package_dep_spec, _1, &env, UserPackageDepSpecOptions(), filter::All()), + n::set_operator_mode() = sfsmo_star, + n::type() = sft_paludis_conf + )); + + { + SetSpecStringifier p; + fstar.contents()->top()->accept(p); + EXPECT_EQ("( foo/foo >=bar/bar-1.23 >=baz/baz-1.23 set* set2* ) ", stringify(p.s.str())); + } - } - } test_overrides; } |