Make tests not sensitive to requirements orders
This commit is contained in:
parent
0a4117b76a
commit
9a153e42f9
@ -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
|
||||
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)
|
||||
{
|
||||
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.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>
|
||||
|
@ -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>;
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user