/* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* * Copyright (c) 2006, 2007, 2008, 2009, 2010 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 * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" using namespace test; using namespace paludis; namespace { void cannot_uninstall(const std::shared_ptr & id, const UninstallActionOptions &) { if (id) throw InternalError(PALUDIS_HERE, "cannot uninstall"); } std::shared_ptr make_standard_output_manager(const Action &) { return std::make_shared(); } std::string from_keys(const std::shared_ptr > & m, const std::string & k) { Map::ConstIterator mm(m->find(k)); if (m->end() == mm) return ""; else return mm->second; } WantPhase want_all_phases(const std::string &) { return wp_yes; } } namespace test_cases { struct ERepositoryInstallEAPI4Test : TestCase { ERepositoryInstallEAPI4Test() : TestCase("install_eapi_4") { } unsigned max_run_time() const { return 3000; } bool repeatable() const { return false; } void run() { TestEnvironment env; env.set_paludis_command("/bin/false"); std::shared_ptr > keys(std::make_shared>()); keys->insert("format", "e"); keys->insert("names_cache", "/var/empty"); keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo")); keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo/profiles/profile")); keys->insert("layout", "traditional"); keys->insert("eapi_when_unknown", "0"); keys->insert("eapi_when_unspecified", "0"); keys->insert("profile_eapi", "0"); keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "distdir")); keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "build")); std::shared_ptr repo(ERepository::repository_factory_create(&env, std::bind(from_keys, keys, std::placeholders::_1))); env.package_database()->add_repository(1, repo); std::shared_ptr installed_repo(std::make_shared( make_named_values( n::environment() = &env, n::name() = RepositoryName("installed"), n::suitable_destination() = true, n::supports_uninstall() = true ))); env.package_database()->add_repository(2, installed_repo); InstallAction action(make_named_values( n::destination() = installed_repo, n::make_output_manager() = &make_standard_output_manager, n::perform_uninstall() = &cannot_uninstall, n::replacing() = std::make_shared(), n::want_phase() = &want_all_phases )); PretendAction pretend_action(make_named_values( n::destination() = installed_repo, n::make_output_manager() = &make_standard_output_manager, n::replacing() = std::make_shared() )); { TestMessageSuffix suffix("pkg_pretend", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/pkg_pretend-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(pretend_action); TEST_CHECK(! pretend_action.failed()); } { TestMessageSuffix suffix("pkg_pretend-failure", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/pkg_pretend-failure-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(pretend_action); TEST_CHECK(pretend_action.failed()); } { TestMessageSuffix suffix("default_src_install 4", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/default_src_install-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { TestMessageSuffix suffix("docompress 4", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/docompress-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { TestMessageSuffix suffix("dodoc -r", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/dodoc-r-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { TestMessageSuffix suffix("doins symlink", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/doins-symlink-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { TestMessageSuffix suffix("banned functions 4", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/banned-functions-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); TEST_CHECK_THROWS(id->perform_action(action), ActionFailedError); } { TestMessageSuffix suffix("econf disable dependency tracking", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/econf-disable-dependency-tracking-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { TestMessageSuffix suffix("global scope use", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/global-scope-use-4", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } } } test_e_repository_install_eapi_4; struct ERepositoryEAPI4MergeTypeTest : TestCase { ERepositoryEAPI4MergeTypeTest() : TestCase("eapi 4 merge type") { } unsigned max_run_time() const { return 3000; } bool repeatable() const { return false; } void run() { FSPath root(FSPath::cwd() / "e_repository_TEST_4_dir" / "root"); TestEnvironment env; env.set_paludis_command("/bin/false"); std::shared_ptr > keys(std::make_shared>()); keys->insert("format", "e"); keys->insert("names_cache", "/var/empty"); keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo")); keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo/profiles/profile")); keys->insert("layout", "traditional"); keys->insert("eapi_when_unknown", "0"); keys->insert("eapi_when_unspecified", "0"); keys->insert("profile_eapi", "0"); keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "distdir")); keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "build")); std::shared_ptr repo(ERepository::repository_factory_create(&env, std::bind(from_keys, keys, std::placeholders::_1))); env.package_database()->add_repository(1, repo); std::shared_ptr > v_keys(std::make_shared>()); v_keys->insert("format", "vdb"); v_keys->insert("names_cache", "/var/empty"); v_keys->insert("provides_cache", "/var/empty"); v_keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "vdb")); v_keys->insert("root", stringify(root)); std::shared_ptr v_repo(VDBRepository::repository_factory_create(&env, std::bind(from_keys, keys, std::placeholders::_1))); env.package_database()->add_repository(1, v_repo); { InstallAction action(make_named_values( n::destination() = v_repo, n::make_output_manager() = &make_standard_output_manager, n::perform_uninstall() = &cannot_uninstall, n::replacing() = std::make_shared(), n::want_phase() = &want_all_phases )); ::setenv("EXPECTED_MERGE_TYPE", "source", 1); TestMessageSuffix suffix("merge type source", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/merge-type-4::test-repo", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } } } test_e_repository_eapi_4_merge_type; #ifdef ENABLE_PBINS struct ERepositoryEAPI4MergeTypeBinTest : TestCase { ERepositoryEAPI4MergeTypeBinTest() : TestCase("eapi 4 merge type bin") { } unsigned max_run_time() const { return 3000; } bool repeatable() const { return false; } void run() { FSPath root(FSPath::cwd() / "e_repository_TEST_4_dir" / "root"); TestEnvironment env; env.set_paludis_command("/bin/false"); std::shared_ptr > keys(std::make_shared>()); keys->insert("format", "e"); keys->insert("names_cache", "/var/empty"); keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo")); keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo/profiles/profile")); keys->insert("layout", "traditional"); keys->insert("eapi_when_unknown", "0"); keys->insert("eapi_when_unspecified", "0"); keys->insert("profile_eapi", "0"); keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "distdir")); keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "build")); std::shared_ptr repo(ERepository::repository_factory_create(&env, std::bind(from_keys, keys, std::placeholders::_1))); env.package_database()->add_repository(1, repo); std::shared_ptr > b_keys(std::make_shared>()); b_keys->insert("format", "e"); b_keys->insert("names_cache", "/var/empty"); b_keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / ("binrepo"))); b_keys->insert("profiles", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "repo/profiles/profile")); b_keys->insert("layout", "traditional"); b_keys->insert("eapi_when_unknown", "0"); b_keys->insert("eapi_when_unspecified", "0"); b_keys->insert("profile_eapi", "0"); b_keys->insert("distdir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "distdir")); b_keys->insert("binary_distdir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "distdir")); b_keys->insert("binary_keywords_filter", "test"); b_keys->insert("binary_destination", "true"); b_keys->insert("master_repository", "test-repo"); b_keys->insert("builddir", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "build")); b_keys->insert("root", stringify(root)); std::shared_ptr b_repo(ERepository::repository_factory_create(&env, std::bind(from_keys, b_keys, std::placeholders::_1))); env.package_database()->add_repository(2, b_repo); std::shared_ptr > v_keys(std::make_shared>()); v_keys->insert("format", "vdb"); v_keys->insert("names_cache", "/var/empty"); v_keys->insert("provides_cache", "/var/empty"); v_keys->insert("location", stringify(FSPath::cwd() / "e_repository_TEST_4_dir" / "vdb")); v_keys->insert("root", stringify(root)); std::shared_ptr v_repo(VDBRepository::repository_factory_create(&env, std::bind(from_keys, keys, std::placeholders::_1))); env.package_database()->add_repository(1, v_repo); { InstallAction action(make_named_values( n::destination() = b_repo, n::make_output_manager() = &make_standard_output_manager, n::perform_uninstall() = &cannot_uninstall, n::replacing() = std::make_shared(), n::want_phase() = &want_all_phases )); ::setenv("EXPECTED_MERGE_TYPE", "buildonly", 1); TestMessageSuffix suffix("merge type buildonly", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/merge-type-bin-4::test-repo", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "4"); id->perform_action(action); } { InstallAction action(make_named_values( n::destination() = v_repo, n::make_output_manager() = &make_standard_output_manager, n::perform_uninstall() = &cannot_uninstall, n::replacing() = std::make_shared(), n::want_phase() = &want_all_phases )); ::setenv("EXPECTED_MERGE_TYPE", "binary", 1); TestMessageSuffix suffix("merge type binary", true); const std::shared_ptr id(*env[selection::RequireExactlyOne(generator::Matches( PackageDepSpec(parse_user_package_dep_spec("=cat/merge-type-bin-4::binrepo", &env, { })), { }))]->last()); TEST_CHECK(bool(id)); TEST_CHECK_EQUAL(simple_visitor_cast >(**id->find_metadata("EAPI"))->value(), "pbin-1+4"); id->perform_action(action); } } } test_e_repository_eapi_4_merge_type_bin; #endif }