diff options
author | 2014-03-15 22:54:07 -0400 | |
---|---|---|
committer | 2014-03-21 15:36:44 +0000 | |
commit | 370cac9e401af4d9038e174f7002a93218525038 (patch) | |
tree | 99bb0e2e9a7e3956daef03ea75baa36045f4e53d | |
parent | 1050ee7d3bf8cd37663c8506f50e19e2786987ac (diff) | |
download | paludis-370cac9e401af4d9038e174f7002a93218525038.tar.gz paludis-370cac9e401af4d9038e174f7002a93218525038.tar.xz |
Tests for PromoteBinariesHelper
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | paludis/resolver/Makefile.am | 20 | ||||
-rw-r--r-- | paludis/resolver/resolver_TEST_promote_binaries.cc | 144 | ||||
-rwxr-xr-x | paludis/resolver/resolver_TEST_promote_binaries_cleanup.sh | 9 | ||||
-rwxr-xr-x | paludis/resolver/resolver_TEST_promote_binaries_setup.sh | 41 |
5 files changed, 213 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index 47964d200..8646fa501 100644 --- a/.gitignore +++ b/.gitignore @@ -368,6 +368,7 @@ tags /paludis/resolver/resolver_TEST_cycles /paludis/resolver/resolver_TEST_errors /paludis/resolver/resolver_TEST_fetches +/paludis/resolver/resolver_TEST_promote_binaries /paludis/resolver/resolver_TEST_purges /paludis/resolver/resolver_TEST_serialisation /paludis/resolver/resolver_TEST_simple diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index 60dc4eeb9..b3310ebdd 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -201,7 +201,8 @@ TESTS = \ resolver_TEST_uninstalls \ resolver_TEST_fetches \ resolver_TEST_purges \ - resolver_TEST_binaries + resolver_TEST_binaries \ + resolver_TEST_promote_binaries check_PROGRAMS = $(TESTS) @@ -217,7 +218,8 @@ check_SCRIPTS = \ resolver_TEST_uninstalls_setup.sh resolver_TEST_uninstalls_cleanup.sh \ resolver_TEST_fetches_setup.sh resolver_TEST_fetches_cleanup.sh \ resolver_TEST_purges_setup.sh resolver_TEST_purges_cleanup.sh \ - resolver_TEST_binaries_setup.sh resolver_TEST_binaries_cleanup.sh + resolver_TEST_binaries_setup.sh resolver_TEST_binaries_cleanup.sh \ + resolver_TEST_promote_binaries_setup.sh resolver_TEST_promote_binaries_cleanup.sh check_LIBRARIES = libpaludisresolvertest.a @@ -393,6 +395,20 @@ resolver_TEST_binaries_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@ resolver_TEST_binaries_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@ +resolver_TEST_promote_binaries_SOURCES = resolver_TEST_promote_binaries.cc + +resolver_TEST_promote_binaries_LDADD = \ + libpaludisresolvertest.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 \ + libpaludisresolver.a \ + $(DYNAMIC_LD_LIBS) + +resolver_TEST_promote_binaries_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@ @GTESTDEPS_CXXFLAGS@ + +resolver_TEST_promote_binaries_LDFLAGS = @GTESTDEPS_LDFLAGS@ @GTESTDEPS_LIBS@ + use_existing-se.hh : use_existing.se $(top_srcdir)/misc/make_se.bash if ! $(top_srcdir)/misc/make_se.bash --header $(srcdir)/use_existing.se > $@ ; then rm -f $@ ; exit 1 ; fi diff --git a/paludis/resolver/resolver_TEST_promote_binaries.cc b/paludis/resolver/resolver_TEST_promote_binaries.cc new file mode 100644 index 000000000..4c732d5b2 --- /dev/null +++ b/paludis/resolver/resolver_TEST_promote_binaries.cc @@ -0,0 +1,144 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2009, 2010, 2011 Ciaran McCreesh + * Copyright (c) 2014 Dimitry Ishenko + * + * 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/resolver/resolver.hh> +#include <paludis/resolver/decision.hh> +#include <paludis/resolver/decisions.hh> + +#include <paludis/environments/test/test_environment.hh> + +#include <paludis/util/make_named_values.hh> +#include <paludis/util/sequence.hh> +#include <paludis/util/make_shared_copy.hh> +#include <paludis/util/stringify.hh> +#include <paludis/util/visitor_cast.hh> + +#include <paludis/standard_output_manager.hh> +#include <paludis/action.hh> +#include <paludis/choice.hh> +#include <paludis/user_dep_spec.hh> +#include <paludis/generator.hh> +#include <paludis/filter.hh> +#include <paludis/filtered_generator.hh> +#include <paludis/selection.hh> + +#include <paludis/resolver/resolver_test.hh> + +#include <functional> + +using namespace paludis; +using namespace paludis::resolver; +using namespace paludis::resolver::resolver_test; + +namespace +{ + struct ResolverPromoteBinariesTestCase : ResolverTestCase + { + std::shared_ptr<ResolverWithBinaryTestData> data; + static bool bin_created; + + void SetUp(); + void TearDown(); + + std::shared_ptr<const PackageID> get_origin_id(std::shared_ptr<const Resolved> resolved) + { + return visitor_cast<const ChangesToMakeDecision>(*resolved->taken_change_or_remove_decisions()->begin()->first)->origin_id(); + } + }; +} + +bool ResolverPromoteBinariesTestCase::bin_created(false); + +void ResolverPromoteBinariesTestCase::SetUp() +{ + data = std::make_shared<ResolverWithBinaryTestData>("promote_binaries", "exheres-0", "exheres", true); + + if (!bin_created) + { + InstallAction install(make_named_values<InstallActionOptions>( + n::destination() = data->bin_repo, + n::make_output_manager() = [](const Action &) { return std::make_shared<StandardOutputManager>(); }, + n::perform_uninstall() = [](const std::shared_ptr<const PackageID> & id, const UninstallActionOptions &) + { if (id) throw InternalError(PALUDIS_HERE, "cannot uninstall"); }, + n::replacing() = std::make_shared<PackageIDSequence>(), + n::want_phase() = [](const std::string &) { return wp_yes; } + )); + + auto pkg1(*data->env[selection::RequireExactlyOne(generator::Matches( + parse_user_package_dep_spec("=cat/pkg1-1", &data->env, { }), nullptr, { }))]->last()); + + auto pkg2(*data->env[selection::RequireExactlyOne(generator::Matches( + parse_user_package_dep_spec("=cat/pkg2-1", &data->env, { }), nullptr, { }))]->last()); + + data->env.set_want_choice_enabled(ChoicePrefixName(""), UnprefixedChoiceName("opt"), true); + pkg1->perform_action(install); + + data->env.set_want_choice_enabled(ChoicePrefixName(""), UnprefixedChoiceName("opt"), false); + pkg2->perform_action(install); + + bin_created = true; + } +} + +void ResolverPromoteBinariesTestCase::TearDown() +{ + data.reset(); +} + +TEST_F(ResolverPromoteBinariesTestCase, Cat_Pkg1_Repo) +{ + data->promote_binaries_helper.set_promote_binaries(pb_never); + + auto resolved(data->get_resolved("cat/pkg1")); + ASSERT_FALSE(resolved->taken_change_or_remove_decisions()->empty()); + + ASSERT_EQ(get_origin_id(resolved)->repository_name(), RepositoryName("repo")); +} + +TEST_F(ResolverPromoteBinariesTestCase, Cat_Pkg1_Binrepo) +{ + data->promote_binaries_helper.set_promote_binaries(pb_if_same); + + auto resolved(data->get_resolved("cat/pkg1")); + ASSERT_FALSE(resolved->taken_change_or_remove_decisions()->empty()); + + ASSERT_NE(get_origin_id(resolved)->repository_name(), RepositoryName("binrepo")); +} + +TEST_F(ResolverPromoteBinariesTestCase, Cat_Pkg2_Repo) +{ + data->promote_binaries_helper.set_promote_binaries(pb_never); + + auto resolved(data->get_resolved("cat/pkg2")); + ASSERT_FALSE(resolved->taken_change_or_remove_decisions()->empty()); + + ASSERT_EQ(get_origin_id(resolved)->repository_name(), RepositoryName("repo")); +} + +TEST_F(ResolverPromoteBinariesTestCase, Cat_Pkg2_Binrepo) +{ + data->promote_binaries_helper.set_promote_binaries(pb_if_same); + + auto resolved(data->get_resolved("cat/pkg2")); + ASSERT_FALSE(resolved->taken_change_or_remove_decisions()->empty()); + + ASSERT_EQ(get_origin_id(resolved)->repository_name(), RepositoryName("binrepo")); +} + diff --git a/paludis/resolver/resolver_TEST_promote_binaries_cleanup.sh b/paludis/resolver/resolver_TEST_promote_binaries_cleanup.sh new file mode 100755 index 000000000..06ed75d29 --- /dev/null +++ b/paludis/resolver/resolver_TEST_promote_binaries_cleanup.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# vim: set ft=sh sw=4 sts=4 et : + +if [ -d resolver_TEST_promote_binaries_dir ] ; then + rm -fr resolver_TEST_promote_binaries_dir +else + true +fi + diff --git a/paludis/resolver/resolver_TEST_promote_binaries_setup.sh b/paludis/resolver/resolver_TEST_promote_binaries_setup.sh new file mode 100755 index 000000000..c3c2980dc --- /dev/null +++ b/paludis/resolver/resolver_TEST_promote_binaries_setup.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# vim: set ft=sh sw=4 sts=4 et : + +mkdir resolver_TEST_promote_binaries_dir || exit 1 +cd resolver_TEST_promote_binaries_dir || exit 1 + +mkdir -p build +mkdir -p distdir +mkdir -p installed + +mkdir -p binrepo/{profiles/profile,metadata,packages} + +cd binrepo +echo "binrepo" > profiles/repo_name +: > metadata/categories.conf +cd .. + +mkdir -p repo/{profiles/profile,metadata,packages} + +cd repo +echo "repo" > profiles/repo_name +echo "cat" > metadata/categories.conf + +mkdir -p packages/cat/pkg1 +cat <<END > packages/cat/pkg1/pkg1-1.exheres-0 +SUMMARY="pkg1" +PLATFORMS="test" +MYOPTIONS="opt" +SLOT="0" +END + +mkdir -p packages/cat/pkg2 +cat <<END > packages/cat/pkg2/pkg2-1.exheres-0 +SUMMARY="pkg1" +PLATFORMS="test" +MYOPTIONS="opt" +SLOT="0" +END + +cd .. + |