aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-25 10:53:37 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-25 16:55:33 +0000
commit5284f6e650a4f5361b6738af44e82be8b77a603f (patch)
tree75dbfb5be493126e6de64d4296694649c6ce36f8
parente0a55b2eff2694b60de55a409f0357a5aad49a8e (diff)
downloadpaludis-5284f6e650a4f5361b6738af44e82be8b77a603f.tar.gz
paludis-5284f6e650a4f5361b6738af44e82be8b77a603f.tar.xz
gtest more
-rw-r--r--paludis/environments/portage/Makefile.am5
-rw-r--r--paludis/environments/portage/portage_environment_TEST.cc255
2 files changed, 120 insertions, 140 deletions
diff --git a/paludis/environments/portage/Makefile.am b/paludis/environments/portage/Makefile.am
index b8143ed..a71258b 100644
--- a/paludis/environments/portage/Makefile.am
+++ b/paludis/environments/portage/Makefile.am
@@ -29,12 +29,15 @@ EXTRA_DIST = \
TESTS = portage_environment_TEST
portage_environment_TEST_SOURCES = portage_environment_TEST.cc
+
portage_environment_TEST_LDADD = \
- $(top_builddir)/test/libtest.a \
+ $(top_builddir)/paludis/util/gtest_runner.o \
$(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
$(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
$(DYNAMIC_LD_LIBS)
+portage_environment_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
portage_environment_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
check_PROGRAMS = $(TESTS)
diff --git a/paludis/environments/portage/portage_environment_TEST.cc b/paludis/environments/portage/portage_environment_TEST.cc
index 3e86d66..97bd214 100644
--- a/paludis/environments/portage/portage_environment_TEST.cc
+++ b/paludis/environments/portage/portage_environment_TEST.cc
@@ -18,6 +18,7 @@
*/
#include <paludis/environments/portage/portage_environment.hh>
+
#include <paludis/util/join.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
@@ -25,6 +26,7 @@
#include <paludis/util/options.hh>
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/make_null_shared_ptr.hh>
+
#include <paludis/package_id.hh>
#include <paludis/package_database.hh>
#include <paludis/dep_spec.hh>
@@ -37,11 +39,10 @@
#include <paludis/metadata_key.hh>
#include <paludis/choice.hh>
#include <paludis/partially_made_package_dep_spec.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
namespace
{
@@ -74,142 +75,118 @@ namespace
}
}
-namespace test_cases
+TEST(PortageEnvironment, QueryUse)
{
- struct QueryUseTest : TestCase
- {
- QueryUseTest() : TestCase("query_use") { }
-
- void run()
- {
- PortageEnvironment env(stringify(FSPath("portage_environment_TEST_dir/query_use").realpath()));
-
- const std::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(get_use("one", env, idx));
- TEST_CHECK(get_use("two", env, idx));
- TEST_CHECK(! get_use("three", env, idx));
- TEST_CHECK(! get_use("four", env, idx));
- TEST_CHECK(! get_use("five", env, idx));
- TEST_CHECK(! get_use("six", env, idx));
-
- TEST_CHECK(! get_use("one", env, id1));
- TEST_CHECK(get_use("two", env, id1));
- TEST_CHECK(! get_use("three", env, id1));
- TEST_CHECK(get_use("four", env, id1));
- TEST_CHECK(! get_use("five", env, id1));
- TEST_CHECK(! get_use("six", env, id1));
-
- TEST_CHECK(get_use("bar_cards_bar", env, id1));
- TEST_CHECK(! get_use("bar_cards_monkey", env, id1));
- }
- } test_query_use;
-
- struct KnownUseNamesTest : TestCase
- {
- KnownUseNamesTest() : TestCase("known_use_expand_names") { }
-
- void run()
- {
- PortageEnvironment env(stringify(FSPath("portage_environment_TEST_dir/known_use_expand_names").realpath()));
-
- const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
- std::shared_ptr<const Choice> foo_cards;
- for (Choices::ConstIterator c(id1->choices_key()->value()->begin()), c_end(id1->choices_key()->value()->end()) ;
- c != c_end ; ++c)
- if ((*c)->raw_name() == "FOO_CARDS")
- foo_cards = *c;
- if (! foo_cards)
- throw InternalError(PALUDIS_HERE, "oops");
- std::shared_ptr<const Set<UnprefixedChoiceName> > k1(env.known_choice_value_names(id1, foo_cards));
- TEST_CHECK_EQUAL(join(k1->begin(), k1->end(), " "), "one three");
- }
- } test_known_use_expand;
-
- struct AcceptKeywordsTest : TestCase
- {
- AcceptKeywordsTest() : TestCase("accept_keywords") { }
-
- void run()
- {
- TestPortageEnvironment env("portage_environment_TEST_dir/accept_keywords");
-
- const std::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(accept_keyword(env, KeywordName("arch"), idx));
- TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), idx));
- TEST_CHECK(! accept_keyword(env, KeywordName("~arch"), idx));
-
- const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(accept_keyword(env, KeywordName("arch"), id1));
- TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), id1));
- TEST_CHECK(accept_keyword(env, KeywordName("~arch"), id1));
-
- const std::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(accept_keyword(env, KeywordName("other_arch"), id2));
- TEST_CHECK(accept_keyword(env, KeywordName("arch"), id2));
- TEST_CHECK(accept_keyword(env, KeywordName("~arch"), id2));
-
- const std::shared_ptr<const PackageID> id3(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-three-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(! accept_keyword(env, KeywordName("other_arch"), id3));
- TEST_CHECK(! accept_keyword(env, KeywordName("arch"), id3));
- TEST_CHECK(! accept_keyword(env, KeywordName("~arch"), id3));
-
- const std::shared_ptr<const PackageID> id4(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-four-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
- TEST_CHECK(accept_keyword(env, KeywordName("fred"), id4));
- std::shared_ptr<const KeywordNameSet> empty(std::make_shared<KeywordNameSet>());
- TEST_CHECK(env.accept_keywords(empty, id4));
-
- const std::shared_ptr<const PackageID> id5(*env[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-five-1",
- &env, { })), make_null_shared_ptr(), { }))]->begin());
- TEST_CHECK(accept_keyword(env, KeywordName("~foo"), id5));
- TEST_CHECK(! accept_keyword(env, KeywordName("foo"), id5));
- }
- } test_accept_keywords;
-
- struct TestWorldUpdates : TestCase
- {
- TestWorldUpdates() : TestCase("world updates") { }
-
- void run()
- {
- TestPortageEnvironment env("portage_environment_TEST_dir/world");
- FSPath w(FSPath::cwd() / "portage_environment_TEST_dir" / "world" / "var" / "lib" / "portage" / "world");
-
- env.update_config_files_for_package_move(make_package_dep_spec({ })
- .package(QualifiedPackageName("cat/before")),
- QualifiedPackageName("cat/after"));
-
- SafeIFStream f(w);
- std::string ff((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
- TEST_CHECK_EQUAL(ff,
- "cat/unchanged\n"
- "cat/alsounchanged\n"
- "cat/after\n"
- );
- }
- } world_updates_test;
+ PortageEnvironment env(stringify(FSPath("portage_environment_TEST_dir/query_use").realpath()));
+
+ const std::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(get_use("one", env, idx));
+ EXPECT_TRUE(get_use("two", env, idx));
+ EXPECT_TRUE(! get_use("three", env, idx));
+ EXPECT_TRUE(! get_use("four", env, idx));
+ EXPECT_TRUE(! get_use("five", env, idx));
+ EXPECT_TRUE(! get_use("six", env, idx));
+
+ EXPECT_TRUE(! get_use("one", env, id1));
+ EXPECT_TRUE(get_use("two", env, id1));
+ EXPECT_TRUE(! get_use("three", env, id1));
+ EXPECT_TRUE(get_use("four", env, id1));
+ EXPECT_TRUE(! get_use("five", env, id1));
+ EXPECT_TRUE(! get_use("six", env, id1));
+
+ EXPECT_TRUE(get_use("bar_cards_bar", env, id1));
+ EXPECT_TRUE(! get_use("bar_cards_monkey", env, id1));
+}
+
+TEST(PortageEnvironment, KnownUseFlagNames)
+{
+ PortageEnvironment env(stringify(FSPath("portage_environment_TEST_dir/known_use_expand_names").realpath()));
+
+ const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+ std::shared_ptr<const Choice> foo_cards;
+ for (Choices::ConstIterator c(id1->choices_key()->value()->begin()), c_end(id1->choices_key()->value()->end()) ;
+ c != c_end ; ++c)
+ if ((*c)->raw_name() == "FOO_CARDS")
+ foo_cards = *c;
+ if (! foo_cards)
+ throw InternalError(PALUDIS_HERE, "oops");
+ std::shared_ptr<const Set<UnprefixedChoiceName> > k1(env.known_choice_value_names(id1, foo_cards));
+ EXPECT_EQ("one three", join(k1->begin(), k1->end(), " "));
+}
+
+TEST(PortageEnvironment, AcceptKeywords)
+{
+ TestPortageEnvironment env("portage_environment_TEST_dir/accept_keywords");
+
+ const std::shared_ptr<const PackageID> idx(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-x-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(accept_keyword(env, KeywordName("arch"), idx));
+ EXPECT_TRUE(accept_keyword(env, KeywordName("other_arch"), idx));
+ EXPECT_TRUE(! accept_keyword(env, KeywordName("~arch"), idx));
+
+ const std::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(accept_keyword(env, KeywordName("arch"), id1));
+ EXPECT_TRUE(accept_keyword(env, KeywordName("other_arch"), id1));
+ EXPECT_TRUE(accept_keyword(env, KeywordName("~arch"), id1));
+
+ const std::shared_ptr<const PackageID> id2(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(accept_keyword(env, KeywordName("other_arch"), id2));
+ EXPECT_TRUE(accept_keyword(env, KeywordName("arch"), id2));
+ EXPECT_TRUE(accept_keyword(env, KeywordName("~arch"), id2));
+
+ const std::shared_ptr<const PackageID> id3(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-three-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(! accept_keyword(env, KeywordName("other_arch"), id3));
+ EXPECT_TRUE(! accept_keyword(env, KeywordName("arch"), id3));
+ EXPECT_TRUE(! accept_keyword(env, KeywordName("~arch"), id3));
+
+ const std::shared_ptr<const PackageID> id4(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-four-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+ EXPECT_TRUE(accept_keyword(env, KeywordName("fred"), id4));
+ std::shared_ptr<const KeywordNameSet> empty(std::make_shared<KeywordNameSet>());
+ EXPECT_TRUE(env.accept_keywords(empty, id4));
+
+ const std::shared_ptr<const PackageID> id5(*env[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-five-1",
+ &env, { })), make_null_shared_ptr(), { }))]->begin());
+ EXPECT_TRUE(accept_keyword(env, KeywordName("~foo"), id5));
+ EXPECT_TRUE(! accept_keyword(env, KeywordName("foo"), id5));
+}
+
+TEST(PortageEnvironment, World)
+{
+ TestPortageEnvironment env("portage_environment_TEST_dir/world");
+ FSPath w(FSPath::cwd() / "portage_environment_TEST_dir" / "world" / "var" / "lib" / "portage" / "world");
+
+ env.update_config_files_for_package_move(make_package_dep_spec({ })
+ .package(QualifiedPackageName("cat/before")),
+ QualifiedPackageName("cat/after"));
+
+ SafeIFStream f(w);
+ std::string ff((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
+ EXPECT_EQ("cat/unchanged\n"
+ "cat/alsounchanged\n"
+ "cat/after\n",
+ ff);
}