aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-26 22:36:51 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-26 22:36:51 +0000
commiteab34f8ecf7f840036c40ef342b3fd40a62e6f5b (patch)
tree957c5a8a199d069f9374938794c2159b7216511a
parentde1793c55828e04e8e4f93f51bf15518e193e141 (diff)
downloadpaludis-eab34f8ecf7f840036c40ef342b3fd40a62e6f5b.tar.gz
paludis-eab34f8ecf7f840036c40ef342b3fd40a62e6f5b.tar.xz
gtest more
-rw-r--r--paludis/repositories/e/Makefile.am4
-rw-r--r--paludis/repositories/e/e_repository_TEST_exlibs.cc230
2 files changed, 117 insertions, 117 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am
index 28d698e..0e0aea0 100644
--- a/paludis/repositories/e/Makefile.am
+++ b/paludis/repositories/e/Makefile.am
@@ -292,13 +292,15 @@ e_repository_TEST_phases_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
e_repository_TEST_exlibs_SOURCES = e_repository_TEST_exlibs.cc
e_repository_TEST_exlibs_LDADD = \
+ $(top_builddir)/paludis/util/gtest_runner.o \
$(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
$(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
- $(top_builddir)/test/libtest.a \
$(DYNAMIC_LD_LIBS)
e_repository_TEST_exlibs_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+e_repository_TEST_exlibs_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@
+
e_repository_TEST_replacing_SOURCES = e_repository_TEST_replacing.cc
e_repository_TEST_replacing_LDADD = \
diff --git a/paludis/repositories/e/e_repository_TEST_exlibs.cc b/paludis/repositories/e/e_repository_TEST_exlibs.cc
index 3d5af11..ac9cd40 100644
--- a/paludis/repositories/e/e_repository_TEST_exlibs.cc
+++ b/paludis/repositories/e/e_repository_TEST_exlibs.cc
@@ -23,15 +23,20 @@
#include <paludis/repositories/e/e_repository_id.hh>
#include <paludis/repositories/e/vdb_repository.hh>
#include <paludis/repositories/e/eapi.hh>
+
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/util/system.hh>
#include <paludis/util/visitor_cast.hh>
#include <paludis/util/map.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/set.hh>
#include <paludis/util/make_null_shared_ptr.hh>
+#include <paludis/util/stringify.hh>
+
#include <paludis/package_id.hh>
#include <paludis/metadata_key.hh>
#include <paludis/action.hh>
@@ -43,15 +48,15 @@
#include <paludis/repository_factory.hh>
#include <paludis/choice.hh>
#include <paludis/standard_output_manager.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+
#include <functional>
#include <set>
#include <string>
#include "config.h"
-using namespace test;
+#include <gtest/gtest.h>
+
using namespace paludis;
namespace
@@ -93,127 +98,120 @@ namespace
throws_InstallActionError
};
- struct ExlibsTest : TestCase
+ struct TestInfo
{
- const std::string test;
- int expected_result;
-
- ExlibsTest(const std::string & s, const ExpectedResult e) :
- TestCase(s),
- test(s),
- expected_result(e)
- {
- }
-
- unsigned max_run_time() const
- {
- return 3000;
- }
+ std::string test;
+ ExpectedResult expected_result;
+ };
- bool repeatable() const
- {
- return false;
- }
+ struct ExlibsTest :
+ testing::TestWithParam<TestInfo>
+ {
+ TestInfo info;
- void run()
+ void SetUp()
{
- TestEnvironment env;
- std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>());
- keys->insert("format", "e");
- keys->insert("names_cache", "/var/empty");
- keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "repo1"));
- keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "repo1/profiles/profile"));
- keys->insert("layout", "exheres");
- keys->insert("eapi_when_unknown", "exheres-0");
- keys->insert("eapi_when_unspecified", "exheres-0");
- keys->insert("profile_eapi", "exheres-0");
- keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "distdir"));
- keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "build"));
- std::shared_ptr<Repository> repo(ERepository::repository_factory_create(&env,
- std::bind(from_keys, keys, std::placeholders::_1)));
- env.add_repository(1, repo);
-
- std::shared_ptr<FakeInstalledRepository> installed_repo(std::make_shared<FakeInstalledRepository>(
- make_named_values<FakeInstalledRepositoryParams>(
- n::environment() = &env,
- n::name() = RepositoryName("installed"),
- n::suitable_destination() = true,
- n::supports_uninstall() = true
- )));
- env.add_repository(2, installed_repo);
-
- InstallAction action(make_named_values<InstallActionOptions>(
- n::destination() = installed_repo,
- n::make_output_manager() = &make_standard_output_manager,
- n::perform_uninstall() = &cannot_uninstall,
- n::replacing() = std::make_shared<PackageIDSequence>(),
- n::want_phase() = &want_all_phases
- ));
-
- const std::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec("cat/" + test,
- &env, { })), make_null_shared_ptr(), { }))]->last());
- TEST_CHECK(bool(id));
- switch (expected_result)
- {
- case success:
- TEST_CHECK(id->supports_action(SupportsActionTest<InstallAction>()));
- id->perform_action(action);
- break;
- case throws_InstallActionError:
- TEST_CHECK(id->supports_action(SupportsActionTest<InstallAction>()));
- TEST_CHECK_THROWS(id->perform_action(action), ActionFailedError);
- break;
- case unsupported:
- TEST_CHECK(! id->supports_action(SupportsActionTest<InstallAction>()));
- break;
- }
+ info = GetParam();
}
};
}
-namespace test_cases
+TEST_P(ExlibsTest, Works)
{
- ExlibsTest test_require_success("require-success", success);
- ExlibsTest test_require_fail("require-fail", unsupported);
- ExlibsTest test_require_param("require-param", success);
- ExlibsTest test_require_param_empty("require-param-empty", success);
- ExlibsTest test_require_param_missing("require-param-missing", unsupported);
- ExlibsTest test_require_param_undeclared("require-param-undeclared", unsupported);
- ExlibsTest test_require_params("require-params", success);
- ExlibsTest test_require_params_unaligned("require-params-unaligned", unsupported);
- ExlibsTest test_require_multiple_params("require-multiple-params", success);
- ExlibsTest test_require_multiple_params_spaces("require-multiple-params-spaces", success);
- ExlibsTest test_require_param_default("require-param-default", success);
- ExlibsTest test_require_param_default_spaces("require-multiple-params-default-spaces", success);
- ExlibsTest test_exparam_banned("exparam-banned", unsupported);
- ExlibsTest test_exparam_undeclared("exparam-undeclared", throws_InstallActionError);
- ExlibsTest test_exparam_subshell("exparam-subshell", throws_InstallActionError); // cookies to he who finds a way to make this test succeed :(
- ExlibsTest test_exarray("exarray", success);
- ExlibsTest test_exarray_spaces("exarray-spaces", success);
- ExlibsTest test_exarray_default("exarray-default", success);
- ExlibsTest test_exarray_default_spaces("exarray-default-spaces", success);
- ExlibsTest test_exarray_empty("exarray-empty", success);
- ExlibsTest test_noarray("noarray", success);
- ExlibsTest test_noarray_bad("noarray-bad", unsupported);
- ExlibsTest test_scalar_required("scalar-required", unsupported);
- ExlibsTest test_array_required("array-required", unsupported);
- ExlibsTest test_exlib_dot_with_exparam("exlib-dot-with-exparam", success);
- ExlibsTest test_exlib_plus_with_exparam("exlib-plus-with-exparam", success);
- ExlibsTest test_illegal_in_global_scope("illegal-in-global-scope", unsupported);
- ExlibsTest test_illegal_in_global_scope_in_func("illegal-in-global-scope-in-func", success);
- ExlibsTest test_called_cross_phase("called-cross-phase", throws_InstallActionError);
- ExlibsTest test_called_cross_phase_default("called-cross-phase-default", throws_InstallActionError);
- ExlibsTest test_called_cross_phase_user_overridden("called-cross-phase-user-overridden", throws_InstallActionError);
- ExlibsTest test_called_cross_phase_exlib("called-cross-phase-exlib", throws_InstallActionError);
- ExlibsTest test_called_cross_phase_exlib_exported("called-cross-phase-exlib-exported", throws_InstallActionError);
- ExlibsTest test_boolean("boolean", success);
- ExlibsTest test_boolean_badvalue("boolean-badvalue", unsupported);
- ExlibsTest test_boolean_blankvalue("boolean-blankvalue", unsupported);
- ExlibsTest test_boolean_badvaluewithdefault("boolean-badvaluewithdefault", unsupported);
- ExlibsTest test_boolean_baddefault("boolean-baddefault", unsupported);
- ExlibsTest test_boolean_blankdefault("boolean-blankdefault", unsupported);
- ExlibsTest test_boolean_nodefault("boolean-nodefault", unsupported);
- ExlibsTest test_boolean_notreally("boolean-notreally", unsupported);
+ TestEnvironment env;
+ std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>());
+ keys->insert("format", "e");
+ keys->insert("names_cache", "/var/empty");
+ keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "repo1"));
+ keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "repo1/profiles/profile"));
+ keys->insert("layout", "exheres");
+ keys->insert("eapi_when_unknown", "exheres-0");
+ keys->insert("eapi_when_unspecified", "exheres-0");
+ keys->insert("profile_eapi", "exheres-0");
+ keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "distdir"));
+ keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_exlibs_dir" / "build"));
+ std::shared_ptr<Repository> repo(ERepository::repository_factory_create(&env,
+ std::bind(from_keys, keys, std::placeholders::_1)));
+ env.add_repository(1, repo);
+
+ std::shared_ptr<FakeInstalledRepository> installed_repo(std::make_shared<FakeInstalledRepository>(
+ make_named_values<FakeInstalledRepositoryParams>(
+ n::environment() = &env,
+ n::name() = RepositoryName("installed"),
+ n::suitable_destination() = true,
+ n::supports_uninstall() = true
+ )));
+ env.add_repository(2, installed_repo);
+
+ InstallAction action(make_named_values<InstallActionOptions>(
+ n::destination() = installed_repo,
+ n::make_output_manager() = &make_standard_output_manager,
+ n::perform_uninstall() = &cannot_uninstall,
+ n::replacing() = std::make_shared<PackageIDSequence>(),
+ n::want_phase() = &want_all_phases
+ ));
+
+ const std::shared_ptr<const PackageID> id(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("cat/" + info.test,
+ &env, { })), make_null_shared_ptr(), { }))]->last());
+ ASSERT_TRUE(bool(id));
+ switch (info.expected_result)
+ {
+ case success:
+ ASSERT_TRUE(id->supports_action(SupportsActionTest<InstallAction>()));
+ id->perform_action(action);
+ break;
+ case throws_InstallActionError:
+ ASSERT_TRUE(id->supports_action(SupportsActionTest<InstallAction>()));
+ EXPECT_THROW(id->perform_action(action), ActionFailedError);
+ break;
+ case unsupported:
+ ASSERT_TRUE(! id->supports_action(SupportsActionTest<InstallAction>()));
+ break;
+ }
}
+INSTANTIATE_TEST_CASE_P(Works, ExlibsTest, testing::Values(
+ TestInfo{"require-success", success},
+ TestInfo{"require-fail", unsupported},
+ TestInfo{"require-param", success},
+ TestInfo{"require-param-empty", success},
+ TestInfo{"require-param-missing", unsupported},
+ TestInfo{"require-param-undeclared", unsupported},
+ TestInfo{"require-params", success},
+ TestInfo{"require-params-unaligned", unsupported},
+ TestInfo{"require-multiple-params", success},
+ TestInfo{"require-multiple-params-spaces", success},
+ TestInfo{"require-param-default", success},
+ TestInfo{"require-multiple-params-default-spaces", success},
+ TestInfo{"exparam-banned", unsupported},
+ TestInfo{"exparam-undeclared", throws_InstallActionError},
+ TestInfo{"exparam-subshell", throws_InstallActionError}, // cookies to he who finds a way to make this test succeed :(
+ TestInfo{"exarray", success},
+ TestInfo{"exarray-spaces", success},
+ TestInfo{"exarray-default", success},
+ TestInfo{"exarray-default-spaces", success},
+ TestInfo{"exarray-empty", success},
+ TestInfo{"noarray", success},
+ TestInfo{"noarray-bad", unsupported},
+ TestInfo{"scalar-required", unsupported},
+ TestInfo{"array-required", unsupported},
+ TestInfo{"exlib-dot-with-exparam", success},
+ TestInfo{"exlib-plus-with-exparam", success},
+ TestInfo{"illegal-in-global-scope", unsupported},
+ TestInfo{"illegal-in-global-scope-in-func", success},
+ TestInfo{"called-cross-phase", throws_InstallActionError},
+ TestInfo{"called-cross-phase-default", throws_InstallActionError},
+ TestInfo{"called-cross-phase-user-overridden", throws_InstallActionError},
+ TestInfo{"called-cross-phase-exlib", throws_InstallActionError},
+ TestInfo{"called-cross-phase-exlib-exported", throws_InstallActionError},
+ TestInfo{"boolean", success},
+ TestInfo{"boolean-badvalue", unsupported},
+ TestInfo{"boolean-blankvalue", unsupported},
+ TestInfo{"boolean-badvaluewithdefault", unsupported},
+ TestInfo{"boolean-baddefault", unsupported},
+ TestInfo{"boolean-blankdefault", unsupported},
+ TestInfo{"boolean-nodefault", unsupported},
+ TestInfo{"boolean-notreally", unsupported}
+ ));
+