aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-07 00:41:29 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-07 00:41:29 +0000
commitff8a2c2894bc88278fea2e114ead3143be8696ff (patch)
tree8afdbd70600fa4cc8fe2a505da39947580630335
parentbfbc950a043521060ac42b4745f9feafcae75cd9 (diff)
downloadpaludis-ff8a2c2894bc88278fea2e114ead3143be8696ff.tar.gz
paludis-ff8a2c2894bc88278fea2e114ead3143be8696ff.tar.xz
Fix homepage_key check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am13
-rw-r--r--paludis/repositories/e/qa/homepage_key.cc16
-rw-r--r--paludis/repositories/e/qa/homepage_key.hh4
-rw-r--r--paludis/repositories/e/qa/homepage_key_TEST.cc117
-rw-r--r--paludis/repositories/fake/fake_package_id.cc9
-rw-r--r--paludis/repositories/fake/fake_package_id.hh1
6 files changed, 151 insertions, 9 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index f4025d3..1095e6b 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -99,6 +99,7 @@ if ENABLE_QA
TESTS = \
extractors_TEST \
+ homepage_key_TEST \
spec_keys_TEST \
stray_files_TEST \
kv_variables_TEST \
@@ -142,6 +143,18 @@ extractors_TEST_LDADD = \
$(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
$(top_builddir)/test/libtest.a
+homepage_key_TEST_SOURCES = homepage_key_TEST.cc
+homepage_key_TEST_LDADD = \
+ libpaludiserepositoryqa.la \
+ test_extras.o \
+ $(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
+
visibility_TEST_SOURCES = visibility_TEST.cc
visibility_TEST_LDADD = \
libpaludiserepositoryqa.la \
diff --git a/paludis/repositories/e/qa/homepage_key.cc b/paludis/repositories/e/qa/homepage_key.cc
index 574443b..f16507c 100644
--- a/paludis/repositories/e/qa/homepage_key.cc
+++ b/paludis/repositories/e/qa/homepage_key.cc
@@ -44,7 +44,7 @@ namespace
const tr1::shared_ptr<const MetadataKey> & key;
const FSEntry entry;
QAReporter & reporter;
- const tr1::shared_ptr<const ERepositoryID> id;
+ const tr1::shared_ptr<const PackageID> id;
const std::string name;
bool found_one;
@@ -52,7 +52,7 @@ namespace
const tr1::shared_ptr<const MetadataKey> & k,
const FSEntry & f,
QAReporter & r,
- const tr1::shared_ptr<const ERepositoryID> & i,
+ const tr1::shared_ptr<const PackageID> & i,
const std::string & n) :
key(k),
entry(f),
@@ -66,16 +66,18 @@ namespace
~HomepageChecker()
{
if (! found_one)
- reporter.message(QAMessage(entry, qaml_normal, name, "Homepage specifies no URIs"));
+ reporter.message(QAMessage(entry, qaml_normal, name, "Homepage specifies no URIs")
+ .with_associated_id(id)
+ .with_associated_key(key));
}
void visit_leaf(const SimpleURIDepSpec & u)
{
found_one = true;
- if (0 == u.text().compare(0, 7, "http://") &&
- 0 == u.text().compare(0, 8, "https://") &&
- 0 == u.text().compare(0, 6, "ftp://"))
+ if (0 != u.text().compare(0, 7, "http://") &&
+ 0 != u.text().compare(0, 8, "https://") &&
+ 0 != u.text().compare(0, 6, "ftp://"))
reporter.message(QAMessage(entry, qaml_normal, name,
"Homepage uses no or unknown protocol in part '" + u.text() + "'")
.with_associated_id(id)
@@ -88,7 +90,7 @@ bool
paludis::erepository::homepage_key_check(
const FSEntry & entry,
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 homepage_key_check on ID '" + stringify(*id) + "':");
diff --git a/paludis/repositories/e/qa/homepage_key.hh b/paludis/repositories/e/qa/homepage_key.hh
index 7ba8190..7804e96 100644
--- a/paludis/repositories/e/qa/homepage_key.hh
+++ b/paludis/repositories/e/qa/homepage_key.hh
@@ -31,8 +31,8 @@ namespace paludis
bool homepage_key_check(
const FSEntry &,
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/homepage_key_TEST.cc b/paludis/repositories/e/qa/homepage_key_TEST.cc
new file mode 100644
index 0000000..55b22a4
--- /dev/null
+++ b/paludis/repositories/e/qa/homepage_key_TEST.cc
@@ -0,0 +1,117 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2008 David Leverton
+ *
+ * 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 "homepage_key.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;
+ std::string last_message;
+
+ TestReporter() :
+ count(0)
+ {
+ }
+
+ void message(const QAMessage & m)
+ {
+ ++count;
+ last_message = m.message;
+ }
+
+ void status(const std::string &)
+ {
+ }
+ };
+}
+
+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->homepage_key()->set_from_string("http://paludis.pioto.org/");
+
+ TestReporter r;
+ TEST_CHECK(homepage_key_check(FSEntry("/var/empty"), r, id, "homepage_key"));
+ TEST_CHECK_EQUAL(r.count, 0u);
+ }
+ } test_good;
+
+ struct BadTest : TestCase
+ {
+ BadTest() : TestCase("bad") { }
+
+ 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->homepage_key()->set_from_string("ptth://paludis.pioto.org/");
+
+ TestReporter r;
+ TEST_CHECK(homepage_key_check(FSEntry("/var/empty"), r, id, "homepage_key"));
+ TEST_CHECK_EQUAL(r.count, 1u);
+ TEST_CHECK_EQUAL(r.last_message, "Homepage uses no or unknown protocol in part 'ptth://paludis.pioto.org/'");
+ }
+ } test_bad;
+
+ struct EmptyTest : TestCase
+ {
+ EmptyTest() : TestCase("empty") { }
+
+ 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->homepage_key()->set_from_string("( )");
+
+ TestReporter r;
+ TEST_CHECK(homepage_key_check(FSEntry("/var/empty"), r, id, "homepage_key"));
+ TEST_CHECK_EQUAL(r.count, 1u);
+ TEST_CHECK_EQUAL(r.last_message, "Homepage specifies no URIs");
+ }
+ } test_empty;
+}
+
diff --git a/paludis/repositories/fake/fake_package_id.cc b/paludis/repositories/fake/fake_package_id.cc
index 83d7ade..91eb2db 100644
--- a/paludis/repositories/fake/fake_package_id.cc
+++ b/paludis/repositories/fake/fake_package_id.cc
@@ -412,6 +412,9 @@ namespace paludis
src_uri(new FakeMetadataSpecTreeKey<FetchableURISpecTree>("SRC_URI", "Source URIs",
"", tr1::bind(&erepository::parse_fetchable_uri, _1,
*erepository::EAPIData::get_instance()->eapi_from_string(eapi)), mkt_dependencies)),
+ homepage(new FakeMetadataSpecTreeKey<SimpleURISpecTree>("HOMEPAGE", "Homepage",
+ "", tr1::bind(&erepository::parse_simple_uri, _1,
+ *erepository::EAPIData::get_instance()->eapi_from_string(eapi)), mkt_dependencies)),
has_masks(false)
{
build_dependencies_labels->push_back(make_shared_ptr(new DependencyBuildLabel("DEPEND")));
@@ -605,6 +608,12 @@ FakePackageID::homepage_key() const
return _imp->homepage;
}
+const tr1::shared_ptr<FakeMetadataSpecTreeKey<SimpleURISpecTree> >
+FakePackageID::homepage_key()
+{
+ return _imp->homepage;
+}
+
const tr1::shared_ptr<const MetadataStringKey>
FakePackageID::short_description_key() const
{
diff --git a/paludis/repositories/fake/fake_package_id.hh b/paludis/repositories/fake/fake_package_id.hh
index 125674d..8e5b7ab 100644
--- a/paludis/repositories/fake/fake_package_id.hh
+++ b/paludis/repositories/fake/fake_package_id.hh
@@ -234,6 +234,7 @@ namespace paludis
const tr1::shared_ptr<FakeMetadataSpecTreeKey<DependencySpecTree> > post_dependencies_key();
const tr1::shared_ptr<FakeMetadataSpecTreeKey<DependencySpecTree> > suggested_dependencies_key();
const tr1::shared_ptr<FakeMetadataSpecTreeKey<FetchableURISpecTree> > fetches_key();
+ const tr1::shared_ptr<FakeMetadataSpecTreeKey<SimpleURISpecTree> > homepage_key();
void set_slot(const SlotName &);