aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 15:13:40 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 15:13:40 +0100
commite94a84f56b4006399fd19c665e8537a75504d6f5 (patch)
treea8b3b73cc2226e1b6b5c6f8447b52f4537e2bb7f
parent05f626829d870d4aeb6f2197518eddb760acddb6 (diff)
downloadpaludis-e94a84f56b4006399fd19c665e8537a75504d6f5.tar.gz
paludis-e94a84f56b4006399fd19c665e8537a75504d6f5.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/generator_TEST.cc325
2 files changed, 96 insertions, 231 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 626ded5..9757870 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -52,7 +52,7 @@ 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(`fuzzy_finder', `hh', `cc', `gtest')
-add(`generator', `hh', `cc', `fwd', `test')
+add(`generator', `hh', `cc', `fwd', `gtest')
add(`generator_handler', `hh', `cc', `fwd')
add(`hook', `hh', `cc', `fwd', `se')
add(`hooker', `hh', `cc', `gtest', `testscript')
diff --git a/paludis/generator_TEST.cc b/paludis/generator_TEST.cc
index 092124f..033c1f7 100644
--- a/paludis/generator_TEST.cc
+++ b/paludis/generator_TEST.cc
@@ -22,306 +22,171 @@
#include <paludis/selection.hh>
#include <paludis/filtered_generator.hh>
#include <paludis/user_dep_spec.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
+
#include <paludis/util/sequence.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/util/join.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
-#include <test/test_concepts.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
-namespace test_cases
+namespace
{
- TESTCASE_SEMIREGULAR(Generator, generator::All());
- TESTCASE_STRINGIFYABLE(Generator, generator::All(), "all packages");
+ struct TestInfo
+ {
+ std::shared_ptr<Generator> generator;
+ std::string expected;
+ };
- struct GeneratorTestCaseBase : TestCase
+ struct GeneratorTestCaseBase :
+ testing::TestWithParam<TestInfo>
{
- Generator generator;
- TestEnvironment env;
- std::shared_ptr<FakeRepository> repo1;
- std::shared_ptr<FakeRepository> repo2;
- std::shared_ptr<FakeInstalledRepository> inst_repo1;
-
- GeneratorTestCaseBase(const std::string & s, const Generator & f) :
- TestCase("generator " + s + " with " + stringify(f)),
- generator(f),
- repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo1")))),
- repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("repo2")))),
- inst_repo1(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("inst_repo1"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )))
+ TestInfo info;
+
+ void SetUp()
{
- env.add_repository(1, repo1);
- env.add_repository(10, repo2);
- env.add_repository(0, inst_repo1);
+ info = GetParam();
+ }
- repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2", { }));
+ void TearDown()
+ {
+ }
+ };
+}
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2", { }))->keywords_key()->set_from_string("");
- repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3", { }));
+TEST_P(GeneratorTestCaseBase, Works)
+{
+ TestEnvironment env;
- inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
- }
+ auto repo1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo1"))));
- virtual std::string get_expected() const = 0;
+ auto repo2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("repo2"))));
- void run()
- {
- const std::string expected(get_expected());
- std::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(generator)]);
+ auto inst_repo1(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("inst_repo1"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
- TEST_CHECK(bool(got));
- TEST_CHECK_EQUAL(join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "), expected);
+ env.add_repository(1, repo1);
+ env.add_repository(10, repo2);
+ env.add_repository(0, inst_repo1);
- std::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(generator |
- filter::SupportsAction<InstallAction>() | filter::SupportsAction<UninstallAction>())]);
- TEST_CHECK(bool(got_none));
- TEST_CHECK_EQUAL(join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "), "");
- }
- };
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+ repo1->add_version(CategoryNamePart("cat") + PackageNamePart("b"), VersionSpec("2", { }));
- struct AllGeneratorTestCase : GeneratorTestCaseBase
- {
- AllGeneratorTestCase() :
- GeneratorTestCaseBase("all", generator::All())
- {
- }
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("2", { }))->keywords_key()->set_from_string("");
+ repo2->add_version(CategoryNamePart("cat") + PackageNamePart("c"), VersionSpec("3", { }));
- virtual std::string get_expected() const
- {
- return
+ inst_repo1->add_version(CategoryNamePart("cat") + PackageNamePart("a"), VersionSpec("1", { }));
+
+ std::shared_ptr<const PackageIDSequence> got(env[selection::AllVersionsSorted(*info.generator)]);
+
+ ASSERT_TRUE(bool(got));
+ EXPECT_EQ(info.expected, join(indirect_iterator(got->begin()), indirect_iterator(got->end()), ", "));
+
+ std::shared_ptr<const PackageIDSequence> got_none(env[selection::AllVersionsSorted(*info.generator |
+ filter::SupportsAction<InstallAction>() | filter::SupportsAction<UninstallAction>())]);
+ ASSERT_TRUE(bool(got_none));
+ EXPECT_EQ("", join(indirect_iterator(got_none->begin()), indirect_iterator(got_none->end()), ", "));
+}
+
+INSTANTIATE_TEST_CASE_P(GeneratorTest, GeneratorTestCaseBase, testing::Values(
+ TestInfo{ std::make_shared<generator::All>(), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } all_generator_test;
+ "cat/c-3:0::repo2" ) },
- struct MatchesGeneratorTestCase : GeneratorTestCaseBase
- {
- MatchesGeneratorTestCase() :
- GeneratorTestCaseBase("matches", generator::Matches(parse_user_package_dep_spec("cat/a",
- &env, { }), make_null_shared_ptr(), { }))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Matches>(
+ envless_parse_package_dep_spec_for_tests("cat/a"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } matches_generator_test;
-
- struct MatchesCatWildcardGeneratorTestCase : GeneratorTestCaseBase
- {
- MatchesCatWildcardGeneratorTestCase() :
- GeneratorTestCaseBase("matches cat wildcard", generator::Matches(parse_user_package_dep_spec("*/a",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/a-2:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Matches>(
+ envless_parse_package_dep_spec_for_tests("*/a"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } matches_cat_wildcard_generator_test;
-
- struct MatchesPkgWildcardGeneratorTestCase : GeneratorTestCaseBase
- {
- MatchesPkgWildcardGeneratorTestCase() :
- GeneratorTestCaseBase("matches pkg wildcard", generator::Matches(parse_user_package_dep_spec("cat/*",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/a-2:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Matches>(
+ envless_parse_package_dep_spec_for_tests("cat/*"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } matches_pkg_wildcard_generator_test;
-
- struct MatchesAllWildcardGeneratorTestCase : GeneratorTestCaseBase
- {
- MatchesAllWildcardGeneratorTestCase() :
- GeneratorTestCaseBase("matches all wildcard", generator::Matches(
- parse_user_package_dep_spec(">=*/*-2",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }))
- {
- }
+ "cat/c-3:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Matches>(
+ envless_parse_package_dep_spec_for_tests(">=*/*-2"), make_null_shared_ptr(), MatchPackageOptions()), std::string(
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } matches_all_wildcard_generator_test;
+ "cat/c-3:0::repo2") },
- struct PackageGeneratorTestCase : GeneratorTestCaseBase
- {
- PackageGeneratorTestCase() :
- GeneratorTestCaseBase("package", generator::Package(QualifiedPackageName("cat/a")))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Package>(QualifiedPackageName("cat/a")), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } package_generator_test;
+ "cat/a-2:0::repo2") },
- struct NoPackageGeneratorTestCase : GeneratorTestCaseBase
- {
- NoPackageGeneratorTestCase() :
- GeneratorTestCaseBase("package", generator::Package(QualifiedPackageName("cat/d")))
- {
- }
-
- virtual std::string get_expected() const
- {
- return "";
- }
- } no_package_generator_test;
+ TestInfo{ std::make_shared<generator::Package>(QualifiedPackageName("cat/d")), std::string(
+ "") },
- struct RepositoryGeneratorTestCase : GeneratorTestCaseBase
- {
- RepositoryGeneratorTestCase() :
- GeneratorTestCaseBase("repository", generator::InRepository(RepositoryName("repo1")))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::InRepository>(RepositoryName("repo1")), std::string(
"cat/a-1:0::repo1, "
- "cat/b-2:0::repo1";
- }
- } repository_generator_test;
-
- struct NoRepositoryGeneratorTestCase : GeneratorTestCaseBase
- {
- NoRepositoryGeneratorTestCase() :
- GeneratorTestCaseBase("no repository", generator::InRepository(RepositoryName("repo3")))
- {
- }
-
- virtual std::string get_expected() const
- {
- return "";
- }
- } no_repository_generator_test;
+ "cat/b-2:0::repo1") },
- struct CategoryGeneratorTestCase : GeneratorTestCaseBase
- {
- CategoryGeneratorTestCase() :
- GeneratorTestCaseBase("category", generator::Category(CategoryNamePart("cat")))
- {
- }
+ TestInfo{ std::make_shared<generator::InRepository>(RepositoryName("repo3")), std::string(
+ "") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Category>(CategoryNamePart("cat")), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } category_generator_test;
+ "cat/c-3:0::repo2") },
- struct NoCategoryGeneratorTestCase : GeneratorTestCaseBase
- {
- NoCategoryGeneratorTestCase() :
- GeneratorTestCaseBase("no category", generator::Category(CategoryNamePart("a")))
- {
- }
-
- virtual std::string get_expected() const
- {
- return "";
- }
- } no_category_generator_test;
+ TestInfo{ std::make_shared<generator::Category>(CategoryNamePart("a")), std::string(
+ "") },
- struct IntersectionGeneratorTestCase : GeneratorTestCaseBase
- {
- IntersectionGeneratorTestCase() :
- GeneratorTestCaseBase("intersection", generator::Intersection(
- generator::Matches(parse_user_package_dep_spec("*/a",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { }),
- generator::Matches(parse_user_package_dep_spec("cat/*",
- &env, { updso_allow_wildcards }), make_null_shared_ptr(), { })
- ))
- {
- }
-
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::Intersection>(
+ generator::Matches(envless_parse_package_dep_spec_for_tests("*/a"), make_null_shared_ptr(), MatchPackageOptions()),
+ generator::Matches(envless_parse_package_dep_spec_for_tests("cat/*"), make_null_shared_ptr(), MatchPackageOptions())
+ ), std::string(
"cat/a-1:0::inst_repo1, "
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
- "cat/a-2:0::repo2";
- }
- } intersection_generator_test;
-
- struct SomeIDsMightSupportInstallActionGeneratorTestCase : GeneratorTestCaseBase
- {
- SomeIDsMightSupportInstallActionGeneratorTestCase() :
- GeneratorTestCaseBase("some IDs might support install",
- generator::SomeIDsMightSupportAction<InstallAction>())
- {
- }
+ "cat/a-2:0::repo2") },
- virtual std::string get_expected() const
- {
- return
+ TestInfo{ std::make_shared<generator::SomeIDsMightSupportAction<InstallAction> >(), std::string(
"cat/a-1:0::repo1, "
"cat/a-1:0::repo2, "
"cat/a-2:0::repo2, "
"cat/b-2:0::repo1, "
- "cat/c-3:0::repo2";
- }
- } some_ids_might_support_install_action_generator_test;
-}
+ "cat/c-3:0::repo2") }
+ ));