From de20a3101ef1ce2ec66b3c7de3991a0be1e48fa3 Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh Date: Thu, 24 Mar 2011 23:20:15 +0000 Subject: gtest more --- paludis/files.m4 | 2 +- paludis/set_file_TEST.cc | 315 ++++++++++++++++++++++------------------------- 2 files changed, 145 insertions(+), 172 deletions(-) diff --git a/paludis/files.m4 b/paludis/files.m4 index b811141b6..7579574be 100644 --- a/paludis/files.m4 +++ b/paludis/files.m4 @@ -92,7 +92,7 @@ add(`selection', `hh', `cc', `fwd', `test') add(`selection_cache', `hh', `cc', `fwd') add(`selection_handler', `hh', `cc', `fwd') add(`serialise', `hh', `cc', `fwd', `impl') -add(`set_file', `hh', `cc', `se', `test', `testscript') +add(`set_file', `hh', `cc', `se', `gtest', `testscript') add(`slot_requirement', `hh', `fwd', `cc') add(`spec_tree', `hh', `fwd', `cc') add(`standard_output_manager', `hh', `cc', `fwd') 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 +#include +#include + #include + #include #include #include #include -#include -#include - -#include -#include +#include #include -using namespace test; +#include + 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( + n::environment() = static_cast(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( - n::environment() = static_cast(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(ff)), std::istreambuf_iterator()); - 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(ff)), std::istreambuf_iterator()); - 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(ff)), std::istreambuf_iterator()); + 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( - n::environment() = static_cast(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(ff)), std::istreambuf_iterator()); - 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(ff)), std::istreambuf_iterator()); - 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(ff)), std::istreambuf_iterator()); + 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( - n::environment() = static_cast(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( - n::environment() = static_cast(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( + n::environment() = static_cast(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(ff)), std::istreambuf_iterator()); + 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(ff)), std::istreambuf_iterator()); + 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( + n::environment() = static_cast(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( + n::environment() = static_cast(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; } -- cgit v1.2.3