aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-06 23:54:33 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-06 23:54:33 +0000
commitb1303fc4c597273b05a723f1eeb329b4d66b080e (patch)
tree667505d30b474ac1e17c9afb8d29d5dd72c8bb5b
parentfd692a5b206d849dbd4f1b717bb57d2b8f18ec65 (diff)
downloadpaludis-b1303fc4c597273b05a723f1eeb329b4d66b080e.tar.gz
paludis-b1303fc4c597273b05a723f1eeb329b4d66b080e.tar.xz
More QA fixing
-rw-r--r--paludis/repositories/e/qa/Makefile.am14
-rw-r--r--paludis/repositories/e/qa/dependency_keys.cc78
-rw-r--r--paludis/repositories/e/qa/dependency_keys.hh7
-rw-r--r--paludis/repositories/e/qa/dependency_keys_TEST.cc108
4 files changed, 201 insertions, 6 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index 5a74c33..2b8aaba 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -47,7 +47,7 @@ TESTS_ENVIRONMENT = env \
TEST_OUTPUT_WRAPPER="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/outputwrapper`" \
PALUDIS_OUTPUTWRAPPER_DIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/`" \
PALUDIS_EBUILD_DIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_srcdir)/paludis/repositories/e/ebuild/`" \
- PALUDIS_EAPIS_DIR="$(top_srcdir)/paludis/eapis/" \
+ PALUDIS_EAPIS_DIR="$(top_srcdir)/paludis/repositories/e/eapis/" \
PALUDIS_DISTRIBUTIONS_DIR="$(top_srcdir)/paludis/distributions/" \
PALUDIS_DISTRIBUTION="gentoo" \
PALUDIS_SKIP_CONFIG="yes" \
@@ -61,10 +61,22 @@ TESTS_ENVIRONMENT = env \
if ENABLE_QA
TESTS = \
+ dependency_keys_TEST \
stray_files_TEST
check_PROGRAMS = $(TESTS)
+dependency_keys_TEST_SOURCES = dependency_keys_TEST.cc
+dependency_keys_TEST_LDFLAGS = \
+ libpaludiserepositoryqa.la \
+ $(top_builddir)/paludis/repositories/e/libpaludiserepository.la \
+ $(top_builddir)/paludis/repositories/fake/libpaludisfakerepository.la \
+ $(top_builddir)/paludis/util/libpaludisutil.la \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/paludis/libpaludis.la \
+ $(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
+ $(top_builddir)/test/libtest.a
+
stray_files_TEST_SOURCES = stray_files_TEST.cc
stray_files_TEST_LDFLAGS = \
libpaludiserepositoryqa.la \
diff --git a/paludis/repositories/e/qa/dependency_keys.cc b/paludis/repositories/e/qa/dependency_keys.cc
index cf7b05f..6adf553 100644
--- a/paludis/repositories/e/qa/dependency_keys.cc
+++ b/paludis/repositories/e/qa/dependency_keys.cc
@@ -24,21 +24,95 @@
#include <paludis/repositories/e/eapi.hh>
#include <paludis/repositories/e/e_repository_id.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/visitor-impl.hh>
using namespace paludis;
using namespace paludis::erepository;
namespace
{
+ struct Checker :
+ ConstVisitor<DependencySpecTree>
+ {
+ QAReporter & reporter;
+ const tr1::shared_ptr<const PackageID> & id;
+ const MetadataSpecTreeKey<DependencySpecTree> & key;
+ const std::string name;
+ unsigned level;
+
+ Checker(QAReporter & r,
+ const tr1::shared_ptr<const PackageID> & i,
+ const MetadataSpecTreeKey<DependencySpecTree> & k,
+ const std::string & n) :
+ reporter(r),
+ id(i),
+ key(k),
+ name(n),
+ level(0)
+ {
+ }
+
+ void visit_leaf(const PackageDepSpec &)
+ {
+ }
+
+ void visit_leaf(const BlockDepSpec &)
+ {
+ }
+
+ void visit_sequence(const UseDepSpec &,
+ DependencySpecTree::ConstSequenceIterator cur,
+ DependencySpecTree::ConstSequenceIterator end)
+ {
+ Save<unsigned> save_level(&level, level + 1);
+ if (cur == end)
+ reporter.message(qaml_normal, name, "Empty 'use? ( )' block in dependency key '" + stringify(key.raw_name())
+ + "' for ID '" + stringify(*id) + "'");
+ else
+ std::for_each(cur, end, accept_visitor(*this));
+ }
+
+ void visit_sequence(const AllDepSpec &,
+ DependencySpecTree::ConstSequenceIterator cur,
+ DependencySpecTree::ConstSequenceIterator end)
+ {
+ Save<unsigned> save_level(&level, level + 1);
+ if (cur == end)
+ {
+ if (level > 1)
+ reporter.message(qaml_normal, name, "Empty '( )' block in dependency key '" + stringify(key.raw_name())
+ + "' for ID '" + stringify(*id) + "'");
+ }
+ else
+ std::for_each(cur, end, accept_visitor(*this));
+ }
+
+ void visit_sequence(const AnyDepSpec &,
+ DependencySpecTree::ConstSequenceIterator cur,
+ DependencySpecTree::ConstSequenceIterator end)
+ {
+ Save<unsigned> save_level(&level, level + 1);
+ if (cur == end)
+ reporter.message(qaml_normal, name, "Empty '|| ( )' block in dependency key '" + stringify(key.raw_name())
+ + "' for ID '" + stringify(*id) + "'");
+ else
+ std::for_each(cur, end, accept_visitor(*this));
+ }
+ };
+
bool dependency_key_check(
QAReporter & reporter,
- const tr1::shared_ptr<const ERepositoryID> & id,
+ const tr1::shared_ptr<const PackageID> & id,
const std::string & name,
const MetadataSpecTreeKey<DependencySpecTree> & key)
{
Context context("When checking dependency key '" + key.raw_name() + "' for check '" + name +
"' using dependency_keys_check on ID '" + stringify(*id) + "':");
+ Checker c(reporter, id, key, name);
+ key.value()->accept(c);
+
return true;
}
}
@@ -46,7 +120,7 @@ namespace
bool
paludis::erepository::dependency_keys_check(
QAReporter & reporter,
- const tr1::shared_ptr<const ERepositoryID> & id,
+ const tr1::shared_ptr<const PackageID> & id,
const std::string & name)
{
Context context("When performing check '" + name + "' using dependency_keys_check on ID '" + stringify(*id) + "':");
diff --git a/paludis/repositories/e/qa/dependency_keys.hh b/paludis/repositories/e/qa/dependency_keys.hh
index fb948e0..c156999 100644
--- a/paludis/repositories/e/qa/dependency_keys.hh
+++ b/paludis/repositories/e/qa/dependency_keys.hh
@@ -21,7 +21,8 @@
#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_DEPENDENCIES_HH 1
#include <paludis/qa-fwd.hh>
-#include <paludis/repositories/e/e_repository_id.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/util/attributes.hh>
namespace paludis
{
@@ -29,8 +30,8 @@ namespace paludis
{
bool dependency_keys_check(
QAReporter &,
- const tr1::shared_ptr<const ERepositoryID> &,
- const std::string &);
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &) PALUDIS_VISIBLE;
}
}
diff --git a/paludis/repositories/e/qa/dependency_keys_TEST.cc b/paludis/repositories/e/qa/dependency_keys_TEST.cc
new file mode 100644
index 0000000..dd6ce13
--- /dev/null
+++ b/paludis/repositories/e/qa/dependency_keys_TEST.cc
@@ -0,0 +1,108 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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 "dependency_keys.hh"
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/qa.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::erepository;
+using namespace test;
+
+namespace
+{
+ struct TestReporter :
+ QAReporter
+ {
+ unsigned count;
+
+ TestReporter() :
+ count(0)
+ {
+ }
+
+ void message(QAMessageLevel, const std::string &, const std::string &)
+ {
+ ++count;
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct GoodTest : TestCase
+ {
+ GoodTest() : TestCase("good") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+ tr1::shared_ptr<FakePackageID> id(repo->add_version("cat", "pkg", "1"));
+ id->build_dependencies_key()->set_from_string("cat/other");
+
+ TestReporter r;
+ TEST_CHECK(dependency_keys_check(r, id, "dependency keys"));
+ TEST_CHECK_EQUAL(r.count, 0u);
+ }
+ } test_good;
+
+ struct EmptyBlockTest : TestCase
+ {
+ EmptyBlockTest() : TestCase("empty block") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+
+ tr1::shared_ptr<FakePackageID> id1(repo->add_version("cat", "pkg", "1"));
+ id1->build_dependencies_key()->set_from_string("( ( ) )");
+ TestReporter r1;
+ TEST_CHECK(dependency_keys_check(r1, id1, "dependency keys"));
+ TEST_CHECK_EQUAL(r1.count, 1u);
+
+ tr1::shared_ptr<FakePackageID> id2(repo->add_version("cat", "pkg", "2"));
+ id2->build_dependencies_key()->set_from_string("|| ( )");
+ TestReporter r2;
+ TEST_CHECK(dependency_keys_check(r2, id2, "dependency keys"));
+ TEST_CHECK_EQUAL(r2.count, 1u);
+
+ tr1::shared_ptr<FakePackageID> id3(repo->add_version("cat", "pkg", "3"));
+ id3->build_dependencies_key()->set_from_string("x? ( )");
+ TestReporter r3;
+ TEST_CHECK(dependency_keys_check(r3, id3, "dependency keys"));
+ TEST_CHECK_EQUAL(r3.count, 1u);
+
+ tr1::shared_ptr<FakePackageID> id4(repo->add_version("cat", "pkg", "4"));
+ id4->build_dependencies_key()->set_from_string("x? ( ) ( y? ( || ( ) ) )");
+ TestReporter r4;
+ TEST_CHECK(dependency_keys_check(r4, id4, "dependency keys"));
+ TEST_CHECK_EQUAL(r4.count, 2u);
+ }
+ } test_empty_block;
+}
+