aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-08-07 12:15:46 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-08-07 12:15:46 +0000
commit79b75492801ea767af2c509dbcc626014932ad29 (patch)
tree7b2e8f81d6b7e218e61a951cd3d27e3410513d3b
parent85747c54f286921fd79db61c114ed0891fdc8210 (diff)
downloadpaludis-79b75492801ea767af2c509dbcc626014932ad29.tar.gz
paludis-79b75492801ea767af2c509dbcc626014932ad29.tar.xz
Fix virtuals, and add tests.
-rw-r--r--paludis/repositories/e/e_repository_TEST.cc58
-rwxr-xr-xpaludis/repositories/e/e_repository_TEST_setup.sh24
-rw-r--r--paludis/repositories/e/e_repository_profile_file.cc42
3 files changed, 115 insertions, 9 deletions
diff --git a/paludis/repositories/e/e_repository_TEST.cc b/paludis/repositories/e/e_repository_TEST.cc
index 06d1953..a54e689 100644
--- a/paludis/repositories/e/e_repository_TEST.cc
+++ b/paludis/repositories/e/e_repository_TEST.cc
@@ -757,6 +757,64 @@ namespace test_cases
} test_e_repository_invalidate_masks;
/**
+ * \test Test ERepository virtuals.
+ *
+ */
+ struct ERepositoryVirtualsTest : TestCase
+ {
+ ERepositoryVirtualsTest() : TestCase("virtuals") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<Map<std::string, std::string> > keys(
+ new Map<std::string, std::string>);
+ keys->insert("format", "ebuild");
+ keys->insert("names_cache", "/var/empty");
+ keys->insert("location", "e_repository_TEST_dir/repo15");
+ keys->insert("profiles", "e_repository_TEST_dir/repo15/profiles/profile");
+ tr1::shared_ptr<ERepository> repo(make_ebuild_repository(&env, keys));
+ env.package_database()->add_repository(1, repo);
+
+ tr1::shared_ptr<const RepositoryVirtualsInterface::VirtualsSequence> seq(repo->virtual_packages());
+ RepositoryVirtualsInterface::VirtualsSequence::Iterator it(seq->begin());
+
+ TEST_CHECK(seq->end() != it);
+ TEST_CHECK_STRINGIFY_EQUAL(it->virtual_name, "virtual/one");
+ TEST_CHECK_STRINGIFY_EQUAL(*it->provided_by_spec, "cat-one/pkg-one");
+ ++it;
+
+ TEST_CHECK(seq->end() != it);
+ TEST_CHECK_STRINGIFY_EQUAL(it->virtual_name, "virtual/two");
+ TEST_CHECK_STRINGIFY_EQUAL(*it->provided_by_spec, "cat-two/pkg-two");
+ ++it;
+
+ TEST_CHECK(seq->end() == it);
+
+ repo->set_profile(repo->find_profile(repo->params().location / "profiles/profile/subprofile"));
+ seq = repo->virtual_packages();
+ it = seq->begin();
+
+ TEST_CHECK(seq->end() != it);
+ TEST_CHECK_STRINGIFY_EQUAL(it->virtual_name, "virtual/one");
+ TEST_CHECK_STRINGIFY_EQUAL(*it->provided_by_spec, "cat-two/pkg-two");
+ ++it;
+
+ TEST_CHECK(seq->end() != it);
+ TEST_CHECK_STRINGIFY_EQUAL(it->virtual_name, "virtual/three");
+ TEST_CHECK_STRINGIFY_EQUAL(*it->provided_by_spec, "cat-three/pkg-three");
+ ++it;
+
+ TEST_CHECK(seq->end() != it);
+ TEST_CHECK_STRINGIFY_EQUAL(it->virtual_name, "virtual/two");
+ TEST_CHECK_STRINGIFY_EQUAL(*it->provided_by_spec, "cat-one/pkg-one");
+ ++it;
+
+ TEST_CHECK(seq->end() == it);
+ }
+ } test_e_repository_virtuals;
+
+ /**
* \test Test ERepository Manifest2 generation.
*
*/
diff --git a/paludis/repositories/e/e_repository_TEST_setup.sh b/paludis/repositories/e/e_repository_TEST_setup.sh
index cd589d0..423cea2 100755
--- a/paludis/repositories/e/e_repository_TEST_setup.sh
+++ b/paludis/repositories/e/e_repository_TEST_setup.sh
@@ -635,5 +635,29 @@ src_compile() {
END
cd ..
+mkdir -p repo15/{eclass,distfiles,profiles/profile/subprofile} || exit 1
+cd repo15 || exit 1
+echo "test-repo-15" >> profiles/repo_name || exit 1
+cat <<END >profiles/profiles.desc || exit 1
+test profile stable
+test profile/subprofile stable
+END
+cat <<END > profiles/profile/make.defaults || exit 1
+ARCH=test
+END
+cat <<END > profiles/profile/virtuals || exit 1
+virtual/one cat-one/pkg-one
+virtual/two cat-two/pkg-two
+END
+cat <<END >profiles/profile/subprofile/parent || exit 1
+..
+END
+cat <<END > profiles/profile/subprofile/virtuals || exit 1
+virtual/one cat-two/pkg-two
+virtual/two cat-one/pkg-one
+virtual/three cat-three/pkg-three
+END
+cd ..
+
cd ..
diff --git a/paludis/repositories/e/e_repository_profile_file.cc b/paludis/repositories/e/e_repository_profile_file.cc
index 093d806..4c11f29 100644
--- a/paludis/repositories/e/e_repository_profile_file.cc
+++ b/paludis/repositories/e/e_repository_profile_file.cc
@@ -28,8 +28,7 @@
#include <paludis/mask.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <libwrapiter/libwrapiter_output_iterator.hh>
-#include <map>
-#include <set>
+#include <list>
#include <algorithm>
using namespace paludis;
@@ -40,8 +39,7 @@ namespace
template <typename T_>
struct FileEntryTraits
{
- typedef std::multiset<typename tr1::remove_const<T_>::type> Storage;
- static T_ & extract_key(const T_ & k)
+ static const T_ & extract_key(const T_ & k)
{
return k;
}
@@ -50,12 +48,28 @@ namespace
template <typename F_, typename S_>
struct FileEntryTraits<const std::pair<F_, S_> >
{
- typedef std::multimap<F_, S_> Storage;
static const F_ & extract_key(const std::pair<F_, S_> & p)
{
return p.first;
}
};
+
+ template <typename T_>
+ struct MatchesKey
+ {
+ const T_ & _x;
+
+ explicit MatchesKey(const T_ & x) :
+ _x(x)
+ {
+ }
+
+ template <typename U_>
+ bool operator() (const U_ & y)
+ {
+ return FileEntryTraits<const U_>::extract_key(y) == _x;
+ }
+ };
}
namespace paludis
@@ -63,7 +77,8 @@ namespace paludis
template <typename F_>
struct Implementation<ProfileFile<F_> >
{
- typename FileEntryTraits<typename F_::Iterator::value_type>::Storage lines;
+ typedef std::list<typename tr1::remove_const<typename F_::Iterator::value_type>::type> Lines;
+ Lines lines;
};
}
@@ -82,12 +97,21 @@ ProfileFile<F_>::add_file(const FSEntry & f)
const std::string & key(FileEntryTraits<typename F_::Iterator::value_type>::extract_key(*line));
if (0 == key.compare(0, 1, "-", 0, 1))
{
- int erased(this->_imp->lines.erase(key.substr(1)));
- if (0 == erased)
+ typename Implementation<ProfileFile>::Lines::iterator i(
+ std::find_if(this->_imp->lines.begin(), this->_imp->lines.end(),
+ MatchesKey<std::string>(key.substr(1))));
+ if (this->_imp->lines.end() == i)
Log::get_instance()->message(ll_qa, lc_context, "No match for '" + key + "'");
+ else
+ while (this->_imp->lines.end() != i)
+ {
+ this->_imp->lines.erase(i++);
+ i = std::find_if(i, this->_imp->lines.end(),
+ MatchesKey<std::string>(key.substr(1)));
+ }
}
else
- this->_imp->lines.insert(*line);
+ this->_imp->lines.push_back(*line);
}
}