aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-21 15:26:36 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-21 15:26:36 +0000
commit381ea2a561a596b91d695af5f18bf9623d7a4b71 (patch)
treef153465626f5ed353631b73cc043da4af1167094
parentadda98379ffcb62edf1a7424fe10735869ecaa11 (diff)
downloadpaludis-381ea2a561a596b91d695af5f18bf9623d7a4b71.tar.gz
paludis-381ea2a561a596b91d695af5f18bf9623d7a4b71.tar.xz
gtest more
-rw-r--r--paludis/environments/paludis/Makefile.am8
-rw-r--r--paludis/environments/paludis/paludis_environment_TEST.cc283
-rw-r--r--paludis/environments/paludis/world_TEST.cc53
3 files changed, 158 insertions, 186 deletions
diff --git a/paludis/environments/paludis/Makefile.am b/paludis/environments/paludis/Makefile.am
index 8a82fbf..400a1f3 100644
--- a/paludis/environments/paludis/Makefile.am
+++ b/paludis/environments/paludis/Makefile.am
@@ -68,23 +68,27 @@ check_SCRIPTS = \
paludis_environment_TEST_SOURCES = paludis_environment_TEST.cc
paludis_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)
paludis_environment_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+paludis_environment_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
world_TEST_SOURCES = world_TEST.cc
world_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)
world_TEST_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+world_TEST_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
logdir = @HACKED_LOG_DIR@
log_DATA = .keep
diff --git a/paludis/environments/paludis/paludis_environment_TEST.cc b/paludis/environments/paludis/paludis_environment_TEST.cc
index ee5d69d..87b136b 100644
--- a/paludis/environments/paludis/paludis_environment_TEST.cc
+++ b/paludis/environments/paludis/paludis_environment_TEST.cc
@@ -17,13 +17,15 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "paludis_environment.hh"
-#include "paludis_config.hh"
+#include <paludis/environments/paludis/paludis_environment.hh>
+#include <paludis/environments/paludis/paludis_config.hh>
+
#include <paludis/util/sequence.hh>
#include <paludis/util/set.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/options.hh>
#include <paludis/util/make_null_shared_ptr.hh>
+
#include <paludis/package_id.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/generator.hh>
@@ -32,12 +34,11 @@
#include <paludis/selection.hh>
#include <paludis/metadata_key.hh>
#include <paludis/choice.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+
#include <cstdlib>
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
namespace
{
@@ -50,156 +51,128 @@ namespace
}
}
-namespace test_cases
+TEST(PaludisEnvironment, Use)
{
- struct TestPaludisEnvironmentUse : TestCase
- {
- TestPaludisEnvironmentUse() : TestCase("use") { }
-
- void run()
- {
- setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home1").c_str(), 1);
- unsetenv("PALUDIS_SKIP_CONFIG");
-
- std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
- const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
- const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(get_use("foo", one));
- TEST_CHECK(! get_use("foofoo", one));
- TEST_CHECK(get_use("moo", one));
- TEST_CHECK(get_use("quoted-name", one));
-
- TEST_CHECK(get_use("more_exp_one", one));
- TEST_CHECK(get_use("exp_two", one));
- TEST_CHECK(get_use("exp_one", one));
- TEST_CHECK(get_use("third_exp_one", one));
- TEST_CHECK(! get_use("third_exp_two", one));
-
- TEST_CHECK(get_use("third_exp_one", three));
- TEST_CHECK(get_use("third_exp_two", three));
- }
- } paludis_environment_use_test;
-
- struct TestPaludisEnvironmentKnownUse : TestCase
- {
- TestPaludisEnvironmentKnownUse() : TestCase("known use") { }
-
- void run()
- {
- setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home5").c_str(), 1);
- unsetenv("PALUDIS_SKIP_CONFIG");
-
- std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
-
- const std::shared_ptr<const PackageID> id1(*(*env)[selection::RequireExactlyOne(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- env.get(), { })), 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 two");
- }
- } paludis_environment_use_test_known;
-
- struct TestPaludisEnvironmentUseMinusStar : TestCase
- {
- TestPaludisEnvironmentUseMinusStar() : TestCase("use -*") { }
-
- void run()
- {
- setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home2").c_str(), 1);
- unsetenv("PALUDIS_SKIP_CONFIG");
-
- std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
-
- const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
- const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(get_use("foo", one));
- TEST_CHECK(! get_use("foofoo", one));
- TEST_CHECK(! get_use("moo", one));
-
- TEST_CHECK(get_use("more_exp_one", one));
- TEST_CHECK(get_use("exp_two", one));
- TEST_CHECK(! get_use("exp_one", one));
- TEST_CHECK(get_use("third_exp_one", one));
- TEST_CHECK(! get_use("third_exp_two", one));
-
- TEST_CHECK(! get_use("third_exp_one", three));
- TEST_CHECK(get_use("third_exp_two", three));
- }
- } paludis_environment_use_test_minus_star;
-
- struct TestPaludisEnvironmentUseMinusPartialStar : TestCase
- {
- TestPaludisEnvironmentUseMinusPartialStar() : TestCase("use -* partial") { }
-
- void run()
- {
- setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home3").c_str(), 1);
- unsetenv("PALUDIS_SKIP_CONFIG");
-
- std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
-
- const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
- const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
- generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
- env.get(), { })), make_null_shared_ptr(), { }))]->begin());
-
- TEST_CHECK(get_use("foo", one));
- TEST_CHECK(! get_use("foofoo", one));
- TEST_CHECK(get_use("moo", one));
-
- TEST_CHECK(get_use("more_exp_one", one));
- TEST_CHECK(get_use("exp_two", one));
- TEST_CHECK(! get_use("exp_one", one));
- TEST_CHECK(get_use("third_exp_one", one));
- TEST_CHECK(! get_use("third_exp_two", one));
-
- TEST_CHECK(! get_use("third_exp_one", three));
- TEST_CHECK(get_use("third_exp_two", three));
- }
- } paludis_environment_use_test_minus_star_partial;
-
- struct TestPaludisEnvironmentRepositories : TestCase
- {
- TestPaludisEnvironmentRepositories() : TestCase("repositories") { }
-
- void run()
- {
- setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home4").c_str(), 1);
- unsetenv("PALUDIS_SKIP_CONFIG");
-
- std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
-
- TEST_CHECK(bool(env->package_database()->fetch_repository(RepositoryName("first"))));
- TEST_CHECK(bool(env->package_database()->fetch_repository(RepositoryName("second"))));
- TEST_CHECK(bool(env->package_database()->fetch_repository(RepositoryName("third"))));
- TEST_CHECK(bool(env->package_database()->fetch_repository(RepositoryName("fourth"))));
- TEST_CHECK(bool(env->package_database()->fetch_repository(RepositoryName("fifth"))));
-
- TEST_CHECK(env->package_database()->more_important_than(RepositoryName("first"), RepositoryName("second")));
- TEST_CHECK(env->package_database()->more_important_than(RepositoryName("second"), RepositoryName("third")));
- TEST_CHECK(env->package_database()->more_important_than(RepositoryName("fourth"), RepositoryName("third")));
- TEST_CHECK(env->package_database()->more_important_than(RepositoryName("fourth"), RepositoryName("fifth")));
- TEST_CHECK(env->package_database()->more_important_than(RepositoryName("second"), RepositoryName("fifth")));
- }
- } paludis_environment_repositories;
+ setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home1").c_str(), 1);
+ unsetenv("PALUDIS_SKIP_CONFIG");
+
+ std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
+ const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+ const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(get_use("foo", one));
+ EXPECT_TRUE(! get_use("foofoo", one));
+ EXPECT_TRUE(get_use("moo", one));
+ EXPECT_TRUE(get_use("quoted-name", one));
+
+ EXPECT_TRUE(get_use("more_exp_one", one));
+ EXPECT_TRUE(get_use("exp_two", one));
+ EXPECT_TRUE(get_use("exp_one", one));
+ EXPECT_TRUE(get_use("third_exp_one", one));
+ EXPECT_TRUE(! get_use("third_exp_two", one));
+
+ EXPECT_TRUE(get_use("third_exp_one", three));
+ EXPECT_TRUE(get_use("third_exp_two", three));
+}
+
+TEST(PaludisEnvironment, KnownUse)
+{
+ setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home5").c_str(), 1);
+ unsetenv("PALUDIS_SKIP_CONFIG");
+
+ std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
+
+ const std::shared_ptr<const PackageID> id1(*(*env)[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ env.get(), { })), 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 two", join(k1->begin(), k1->end(), " "));
+}
+
+TEST(PaludisEnvironment, UseMinusStar)
+{
+ setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home2").c_str(), 1);
+ unsetenv("PALUDIS_SKIP_CONFIG");
+
+ std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
+
+ const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+ const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(get_use("foo", one));
+ EXPECT_TRUE(! get_use("foofoo", one));
+ EXPECT_TRUE(! get_use("moo", one));
+
+ EXPECT_TRUE(get_use("more_exp_one", one));
+ EXPECT_TRUE(get_use("exp_two", one));
+ EXPECT_TRUE(! get_use("exp_one", one));
+ EXPECT_TRUE(get_use("third_exp_one", one));
+ EXPECT_TRUE(! get_use("third_exp_two", one));
+
+ EXPECT_TRUE(! get_use("third_exp_one", three));
+ EXPECT_TRUE(get_use("third_exp_two", three));
+}
+
+TEST(PaludisEnvironment, UseMinusPartialStar)
+{
+ setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home3").c_str(), 1);
+ unsetenv("PALUDIS_SKIP_CONFIG");
+
+ std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
+
+ const std::shared_ptr<const PackageID> one(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-one-1",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+ const std::shared_ptr<const PackageID> three(*(*env)[selection::RequireExactlyOne(
+ generator::Matches(PackageDepSpec(parse_user_package_dep_spec("=cat-one/pkg-two-3",
+ env.get(), { })), make_null_shared_ptr(), { }))]->begin());
+
+ EXPECT_TRUE(get_use("foo", one));
+ EXPECT_TRUE(! get_use("foofoo", one));
+ EXPECT_TRUE(get_use("moo", one));
+
+ EXPECT_TRUE(get_use("more_exp_one", one));
+ EXPECT_TRUE(get_use("exp_two", one));
+ EXPECT_TRUE(! get_use("exp_one", one));
+ EXPECT_TRUE(get_use("third_exp_one", one));
+ EXPECT_TRUE(! get_use("third_exp_two", one));
+
+ EXPECT_TRUE(! get_use("third_exp_one", three));
+ EXPECT_TRUE(get_use("third_exp_two", three));
+}
+
+TEST(PaludisEnvironment, Repositories)
+{
+ setenv("PALUDIS_HOME", stringify(FSPath::cwd() / "paludis_environment_TEST_dir" / "home4").c_str(), 1);
+ unsetenv("PALUDIS_SKIP_CONFIG");
+
+ std::shared_ptr<Environment> env(std::make_shared<PaludisEnvironment>(""));
+
+ EXPECT_TRUE(bool(env->package_database()->fetch_repository(RepositoryName("first"))));
+ EXPECT_TRUE(bool(env->package_database()->fetch_repository(RepositoryName("second"))));
+ EXPECT_TRUE(bool(env->package_database()->fetch_repository(RepositoryName("third"))));
+ EXPECT_TRUE(bool(env->package_database()->fetch_repository(RepositoryName("fourth"))));
+ EXPECT_TRUE(bool(env->package_database()->fetch_repository(RepositoryName("fifth"))));
+
+ EXPECT_TRUE(env->package_database()->more_important_than(RepositoryName("first"), RepositoryName("second")));
+ EXPECT_TRUE(env->package_database()->more_important_than(RepositoryName("second"), RepositoryName("third")));
+ EXPECT_TRUE(env->package_database()->more_important_than(RepositoryName("fourth"), RepositoryName("third")));
+ EXPECT_TRUE(env->package_database()->more_important_than(RepositoryName("fourth"), RepositoryName("fifth")));
+ EXPECT_TRUE(env->package_database()->more_important_than(RepositoryName("second"), RepositoryName("fifth")));
}
diff --git a/paludis/environments/paludis/world_TEST.cc b/paludis/environments/paludis/world_TEST.cc
index 56bef9d..cbb2f7f 100644
--- a/paludis/environments/paludis/world_TEST.cc
+++ b/paludis/environments/paludis/world_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2010 Ciaran McCreesh
+ * Copyright (c) 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
@@ -19,43 +19,38 @@
#include <paludis/environments/paludis/world.hh>
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/options.hh>
+
#include <paludis/partially_made_package_dep_spec.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+
#include <iterator>
#include <cstdlib>
+#include <gtest/gtest.h>
+
using namespace paludis;
-using namespace test;
-namespace test_cases
+TEST(World, Updates)
{
- struct TestWorldUpdates : TestCase
+ std::shared_ptr<FSPath> w(std::make_shared<FSPath>(FSPath::cwd() / "world_TEST_dir" / "world"));
+
{
- TestWorldUpdates() : TestCase("world updates") { }
-
- void run()
- {
- std::shared_ptr<FSPath> w(std::make_shared<FSPath>(FSPath::cwd() / "world_TEST_dir" / "world"));
-
- {
- TestEnvironment env;
- paludis_environment::World world(&env, w);
- world.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;
+ TestEnvironment env;
+ paludis_environment::World world(&env, w);
+ world.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
+ );
}