From 370cac9e401af4d9038e174f7002a93218525038 Mon Sep 17 00:00:00 2001 From: Dimitry Ishenko Date: Sat, 15 Mar 2014 22:54:07 -0400 Subject: Tests for PromoteBinariesHelper --- .gitignore | 1 + paludis/resolver/Makefile.am | 20 ++- paludis/resolver/resolver_TEST_promote_binaries.cc | 144 +++++++++++++++++++++ .../resolver_TEST_promote_binaries_cleanup.sh | 9 ++ .../resolver_TEST_promote_binaries_setup.sh | 41 ++++++ 5 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 paludis/resolver/resolver_TEST_promote_binaries.cc create mode 100755 paludis/resolver/resolver_TEST_promote_binaries_cleanup.sh create mode 100755 paludis/resolver/resolver_TEST_promote_binaries_setup.sh 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 +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace paludis; +using namespace paludis::resolver; +using namespace paludis::resolver::resolver_test; + +namespace +{ + struct ResolverPromoteBinariesTestCase : ResolverTestCase + { + std::shared_ptr data; + static bool bin_created; + + void SetUp(); + void TearDown(); + + std::shared_ptr get_origin_id(std::shared_ptr resolved) + { + return visitor_cast(*resolved->taken_change_or_remove_decisions()->begin()->first)->origin_id(); + } + }; +} + +bool ResolverPromoteBinariesTestCase::bin_created(false); + +void ResolverPromoteBinariesTestCase::SetUp() +{ + data = std::make_shared("promote_binaries", "exheres-0", "exheres", true); + + if (!bin_created) + { + InstallAction install(make_named_values( + n::destination() = data->bin_repo, + n::make_output_manager() = [](const Action &) { return std::make_shared(); }, + n::perform_uninstall() = [](const std::shared_ptr & id, const UninstallActionOptions &) + { if (id) throw InternalError(PALUDIS_HERE, "cannot uninstall"); }, + n::replacing() = std::make_shared(), + 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 < packages/cat/pkg1/pkg1-1.exheres-0 +SUMMARY="pkg1" +PLATFORMS="test" +MYOPTIONS="opt" +SLOT="0" +END + +mkdir -p packages/cat/pkg2 +cat < packages/cat/pkg2/pkg2-1.exheres-0 +SUMMARY="pkg1" +PLATFORMS="test" +MYOPTIONS="opt" +SLOT="0" +END + +cd .. + -- cgit v1.2.3