aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-09-04 18:43:55 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-09-04 18:43:55 +0100
commit9a153e42f9703672b5a9de6d24d6a35697b05531 (patch)
tree7048d3eca8dd03046d53797ed75f36ff95edf76e
parent0a4117b76a6c9954a4d893789308034f29f1db47 (diff)
downloadpaludis-9a153e42f9703672b5a9de6d24d6a35697b05531.tar.gz
paludis-9a153e42f9703672b5a9de6d24d6a35697b05531.tar.xz
Make tests not sensitive to requirements orders
-rw-r--r--paludis/resolver/job_requirements.cc35
-rw-r--r--paludis/resolver/job_requirements.hh7
-rw-r--r--paludis/resolver/resolver_TEST_continue_on_failure.cc34
-rw-r--r--paludis/resolver/resolver_TEST_fetches.cc19
4 files changed, 52 insertions, 43 deletions
diff --git a/paludis/resolver/job_requirements.cc b/paludis/resolver/job_requirements.cc
index 766e0e1..950245e 100644
--- a/paludis/resolver/job_requirements.cc
+++ b/paludis/resolver/job_requirements.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2010 Ciaran McCreesh
+ * Copyright (c) 2010, 2011 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
@@ -53,28 +53,23 @@ JobRequirement::serialise(Serialiser & s) const
;
}
-namespace
+bool
+JobRequirementComparator::operator() (const JobRequirement & a, const JobRequirement & b)
{
- struct JobRequirementComparator
- {
- bool operator() (const JobRequirement & a, const JobRequirement & b)
- {
- if (a.job_number() < b.job_number())
- return true;
- if (a.job_number() > b.job_number())
- return false;
-
- for (EnumIterator<JobRequirementIf> t, t_end(last_jri) ; t != t_end ; ++t)
- {
- if (a.required_if()[*t] < b.required_if()[*t])
- return true;
- if (a.required_if()[*t] > b.required_if()[*t])
- return false;
- }
+ if (a.job_number() < b.job_number())
+ return true;
+ if (a.job_number() > b.job_number())
+ return false;
+ for (EnumIterator<JobRequirementIf> t, t_end(last_jri) ; t != t_end ; ++t)
+ {
+ if (a.required_if()[*t] < b.required_if()[*t])
+ return true;
+ if (a.required_if()[*t] > b.required_if()[*t])
return false;
- }
- };
+ }
+
+ return false;
}
const std::shared_ptr<JobRequirements>
diff --git a/paludis/resolver/job_requirements.hh b/paludis/resolver/job_requirements.hh
index 9e47b6a..354c601 100644
--- a/paludis/resolver/job_requirements.hh
+++ b/paludis/resolver/job_requirements.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2010 Ciaran McCreesh
+ * Copyright (c) 2010, 2011 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
@@ -46,6 +46,11 @@ namespace paludis
static const JobRequirement deserialise(Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result));
void serialise(Serialiser &) const;
};
+
+ struct JobRequirementComparator
+ {
+ bool operator() (const JobRequirement & a, const JobRequirement & b);
+ };
}
extern template class Sequence<resolver::JobRequirement>;
diff --git a/paludis/resolver/resolver_TEST_continue_on_failure.cc b/paludis/resolver/resolver_TEST_continue_on_failure.cc
index b99860a..4e2ac57 100644
--- a/paludis/resolver/resolver_TEST_continue_on_failure.cc
+++ b/paludis/resolver/resolver_TEST_continue_on_failure.cc
@@ -89,6 +89,14 @@ namespace
result << " always";
return result.str();
}
+
+ std::string
+ sort_stringify_job_requirements(const ExecuteJob * const j)
+ {
+ std::set<JobRequirement, JobRequirementComparator> r;
+ std::copy(j->requirements()->begin(), j->requirements()->end(), std::inserter(r, r.begin()));
+ return join(r.begin(), r.end(), ", ", stringify_req);
+ }
}
namespace
@@ -130,22 +138,18 @@ namespace
const InstallJob * const direct_dep_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(1)));
ASSERT_TRUE(direct_dep_job);
- EXPECT_EQ("0 satisfied independent always",
- join(direct_dep_job->requirements()->begin(), direct_dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("0 satisfied independent always", sort_stringify_job_requirements(direct_dep_job));
const InstallJob * const indirect_dep_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(3)));
ASSERT_TRUE(indirect_dep_job);
- EXPECT_EQ("2 satisfied independent always",
- join(indirect_dep_job->requirements()->begin(), indirect_dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("2 satisfied independent always", sort_stringify_job_requirements(indirect_dep_job));
const InstallJob * const target_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(5)));
ASSERT_TRUE(target_job);
if (direct_dep_installed_)
- EXPECT_EQ("4 satisfied independent always, 3 independent, 1 independent",
- join(target_job->requirements()->begin(), target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 independent, 3 independent, 4 satisfied independent always", sort_stringify_job_requirements(target_job));
else
- EXPECT_EQ("4 satisfied independent always, 1 satisfied independent, 3 independent, 1 independent",
- join(target_job->requirements()->begin(), target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 independent, 1 satisfied independent, 3 independent, 4 satisfied independent always", sort_stringify_job_requirements(target_job));
}
};
}
@@ -197,19 +201,19 @@ TEST_F(ResolverContinueOnFailureTestCase, Uninstall)
const UninstallJob * const needs_target_job(visitor_cast<const UninstallJob>(**resolved->job_lists()->execute_job_list()->fetch(0)));
ASSERT_TRUE(needs_target_job);
- EXPECT_EQ("", join(needs_target_job->requirements()->begin(), needs_target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("", sort_stringify_job_requirements(needs_target_job));
const UninstallJob * const target_job(visitor_cast<const UninstallJob>(**resolved->job_lists()->execute_job_list()->fetch(1)));
ASSERT_TRUE(target_job);
- EXPECT_EQ("0 satisfied independent", join(target_job->requirements()->begin(), target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("0 satisfied independent", sort_stringify_job_requirements(target_job));
const UninstallJob * const dep_job(visitor_cast<const UninstallJob>(**resolved->job_lists()->execute_job_list()->fetch(2)));
ASSERT_TRUE(dep_job);
- EXPECT_EQ("1 satisfied independent", join(dep_job->requirements()->begin(), dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 satisfied independent", sort_stringify_job_requirements(dep_job));
const UninstallJob * const dep_of_dep_job(visitor_cast<const UninstallJob>(**resolved->job_lists()->execute_job_list()->fetch(3)));
ASSERT_TRUE(dep_of_dep_job);
- EXPECT_EQ("2 satisfied independent", join(dep_of_dep_job->requirements()->begin(), dep_of_dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("2 satisfied independent", sort_stringify_job_requirements(dep_of_dep_job));
}
TEST_F(ResolverContinueOnFailureTestCase, Purge)
@@ -243,14 +247,14 @@ TEST_F(ResolverContinueOnFailureTestCase, Purge)
const FetchJob * const fetch_target_job(visitor_cast<const FetchJob>(**resolved->job_lists()->execute_job_list()->fetch(0)));
ASSERT_TRUE(fetch_target_job);
- EXPECT_EQ("", join(fetch_target_job->requirements()->begin(), fetch_target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("", sort_stringify_job_requirements(fetch_target_job));
const InstallJob * const target_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(1)));
ASSERT_TRUE(target_job);
- EXPECT_EQ("0 satisfied independent always", join(target_job->requirements()->begin(), target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("0 satisfied independent always", sort_stringify_job_requirements(target_job));
const UninstallJob * const going_job(visitor_cast<const UninstallJob>(**resolved->job_lists()->execute_job_list()->fetch(2)));
ASSERT_TRUE(going_job);
- EXPECT_EQ("1 satisfied independent", join(going_job->requirements()->begin(), going_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 satisfied independent", sort_stringify_job_requirements(going_job));
}
diff --git a/paludis/resolver/resolver_TEST_fetches.cc b/paludis/resolver/resolver_TEST_fetches.cc
index 4528f8a..80d41b2 100644
--- a/paludis/resolver/resolver_TEST_fetches.cc
+++ b/paludis/resolver/resolver_TEST_fetches.cc
@@ -87,6 +87,14 @@ namespace
result << " always";
return result.str();
}
+
+ std::string
+ sort_stringify_job_requirements(const ExecuteJob * const j)
+ {
+ std::set<JobRequirement, JobRequirementComparator> r;
+ std::copy(j->requirements()->begin(), j->requirements()->end(), std::inserter(r, r.begin()));
+ return join(r.begin(), r.end(), ", ", stringify_req);
+ }
}
TEST_F(ResolverFetchTestCase, Fetch)
@@ -114,21 +122,18 @@ TEST_F(ResolverFetchTestCase, Fetch)
const FetchJob * const fetch_fetch_dep_job(visitor_cast<const FetchJob>(**resolved->job_lists()->execute_job_list()->fetch(0)));
ASSERT_TRUE(fetch_fetch_dep_job);
- EXPECT_EQ("", join(fetch_fetch_dep_job->requirements()->begin(), fetch_fetch_dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("", sort_stringify_job_requirements(fetch_fetch_dep_job));
const InstallJob * const fetch_dep_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(1)));
ASSERT_TRUE(fetch_dep_job);
- EXPECT_EQ("0 satisfied independent always",
- join(fetch_dep_job->requirements()->begin(), fetch_dep_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("0 satisfied independent always", sort_stringify_job_requirements(fetch_dep_job));
const FetchJob * const fetch_target_job(visitor_cast<const FetchJob>(**resolved->job_lists()->execute_job_list()->fetch(2)));
ASSERT_TRUE(fetch_target_job);
- EXPECT_EQ("1 satisfied independent, 1 independent",
- join(fetch_target_job->requirements()->begin(), fetch_target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 independent, 1 satisfied independent", sort_stringify_job_requirements(fetch_target_job));
const InstallJob * const target_job(visitor_cast<const InstallJob>(**resolved->job_lists()->execute_job_list()->fetch(3)));
ASSERT_TRUE(target_job);
- EXPECT_EQ("2 satisfied independent always, 1 independent",
- join(target_job->requirements()->begin(), target_job->requirements()->end(), ", ", stringify_req));
+ EXPECT_EQ("1 independent, 2 satisfied independent always", sort_stringify_job_requirements(target_job));
}