aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-26 17:13:26 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-26 17:13:26 +0000
commita9b4ed0d06e8238a80dc6b9ec4142fc924339433 (patch)
tree068b4e603f92e3039814e485b2f6b3288eff88ff
parent20b841f4170fe5eafab9a65e877e9d17b9db13db (diff)
downloadpaludis-a9b4ed0d06e8238a80dc6b9ec4142fc924339433.tar.gz
paludis-a9b4ed0d06e8238a80dc6b9ec4142fc924339433.tar.xz
Add function_keyword check.
-rw-r--r--paludis/repositories/e/qa/Makefile.am17
-rw-r--r--paludis/repositories/e/qa/function_keyword.cc75
-rw-r--r--paludis/repositories/e/qa/function_keyword.hh44
-rw-r--r--paludis/repositories/e/qa/function_keyword_TEST.cc89
-rw-r--r--paludis/repositories/e/qa/qa_checks.cc7
5 files changed, 231 insertions, 1 deletions
diff --git a/paludis/repositories/e/qa/Makefile.am b/paludis/repositories/e/qa/Makefile.am
index e3744f6..c922cb6 100644
--- a/paludis/repositories/e/qa/Makefile.am
+++ b/paludis/repositories/e/qa/Makefile.am
@@ -49,6 +49,7 @@ paludis_repositories_e_include_HEADERS = \
restrict_key.hh \
inherited_key.hh \
visibility.hh \
+ function_keyword.hh \
whitespace.hh \
header.hh \
variable_assigns.hh \
@@ -84,6 +85,7 @@ libpaludiserepositoryqa_la_SOURCES = \
restrict_key.cc \
inherited_key.cc \
visibility.cc \
+ function_keyword.cc \
whitespace.cc \
header.cc \
variable_assigns.cc \
@@ -148,7 +150,8 @@ TESTS = \
visibility_TEST \
misc_files_TEST \
gpg_TEST \
- subshell_die_TEST
+ subshell_die_TEST \
+ function_keyword_TEST
check_PROGRAMS = $(TESTS)
@@ -272,6 +275,18 @@ subshell_die_TEST_LDADD = \
$(top_builddir)/paludis/environments/test/libpaludistestenvironment.la \
$(top_builddir)/test/libtest.a
+function_keyword_TEST_SOURCES = function_keyword_TEST.cc
+function_keyword_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
+
endif
built-sources : $(BUILT_SOURCES)
diff --git a/paludis/repositories/e/qa/function_keyword.cc b/paludis/repositories/e/qa/function_keyword.cc
new file mode 100644
index 0000000..e0e55dd
--- /dev/null
+++ b/paludis/repositories/e/qa/function_keyword.cc
@@ -0,0 +1,75 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda
+ *
+ * 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 "function_keyword.hh"
+#include <paludis/qa.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <pcre++.h>
+#include <list>
+
+using namespace paludis;
+
+namespace
+{
+ QAMessage
+ with_id(QAMessage m, const tr1::shared_ptr<const PackageID> & id)
+ {
+ return id ? m.with_associated_id(id) : m;
+ }
+}
+
+bool
+paludis::erepository::function_keyword_check(
+ const FSEntry & entry,
+ QAReporter & reporter,
+ const tr1::shared_ptr<const PackageID> & id,
+ const std::string & content,
+ const std::string & name)
+{
+ Context context("When performing check '" + name + "' using function_keyword_check on '" + (id ? stringify(*id) : stringify(entry)) + "':");
+
+ pcrepp::Pcre::Pcre r_function("^function +[^ ]+ *(\\(\\))? *{?");
+
+ if (id)
+ Log::get_instance()->message(ll_debug, lc_context) << "function_keyword '"
+ << entry << "', '" << *id << "', '" << name << "'";
+ else
+ Log::get_instance()->message(ll_debug, lc_context) << "function_keyword '"
+ << entry << "', '" << name << "'";
+
+ std::list<std::string> lines;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(content, "\n", "", std::back_inserter(lines));
+
+ unsigned line_number(0);
+ for (std::list<std::string>::iterator it(lines.begin()),
+ it_end(lines.end()); it_end != it; ++it)
+ {
+ ++line_number;
+
+ if (it->empty())
+ continue;
+
+ if (r_function.search(*it))
+ reporter.message(with_id(QAMessage(entry, qaml_minor, name, "Use of the keyword 'function' on line " + stringify(line_number)), id));
+ }
+
+ return true;
+}
+
diff --git a/paludis/repositories/e/qa/function_keyword.hh b/paludis/repositories/e/qa/function_keyword.hh
new file mode 100644
index 0000000..df51e8c
--- /dev/null
+++ b/paludis/repositories/e/qa/function_keyword.hh
@@ -0,0 +1,44 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 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
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_FUNCTION_KEYWORD_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_QA_FUNCTION_KEYWORD_HH 1
+
+#include <paludis/qa-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/fs_entry-fwd.hh>
+#include <paludis/repositories/e/e_repository.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ bool function_keyword_check(
+ const FSEntry &,
+ QAReporter &,
+ const tr1::shared_ptr<const PackageID> &,
+ const std::string &,
+ const std::string &) PALUDIS_VISIBLE;
+ }
+}
+
+
+#endif
diff --git a/paludis/repositories/e/qa/function_keyword_TEST.cc b/paludis/repositories/e/qa/function_keyword_TEST.cc
new file mode 100644
index 0000000..d1ddae8
--- /dev/null
+++ b/paludis/repositories/e/qa/function_keyword_TEST.cc
@@ -0,0 +1,89 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007 Fernando J. Pereda
+ *
+ * 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 "function_keyword.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(const QAMessage & m)
+ {
+ ++count;
+ }
+
+ void status(const std::string &)
+ {
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct FunctionKeywordTest : TestCase
+ {
+ FunctionKeywordTest() : TestCase("function_keyword") { }
+
+ 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 r1;
+ TEST_CHECK(function_keyword_check(FSEntry("/var/empty"), r1, id, "function something () {\n : ;\n}\n", "function_keyword"));
+ TEST_CHECK_EQUAL(r1.count, 1u);
+
+ TestReporter r2;
+ TEST_CHECK(function_keyword_check(FSEntry("/var/empty"), r2, id, "function foo\n{\n : ;\n}\n", "function_keyword"));
+ TEST_CHECK_EQUAL(r2.count, 1u);
+
+ TestReporter r3;
+ TEST_CHECK(function_keyword_check(FSEntry("/var/empty"), r3, id, "function bar (){\n : ;\n}\n", "function_keyword"));
+ TEST_CHECK_EQUAL(r3.count, 1u);
+
+ TestReporter r4;
+ TEST_CHECK(function_keyword_check(FSEntry("/var/empty"), r4, id, "# function something\nbah() {\n : ;\n}\n", "function_keyword"));
+ TEST_CHECK_EQUAL(r4.count, 0u);
+ }
+ } test_function_keyword;
+}
+
diff --git a/paludis/repositories/e/qa/qa_checks.cc b/paludis/repositories/e/qa/qa_checks.cc
index 235776d..0ddf8c3 100644
--- a/paludis/repositories/e/qa/qa_checks.cc
+++ b/paludis/repositories/e/qa/qa_checks.cc
@@ -44,6 +44,7 @@
#include <paludis/repositories/e/qa/kv_variables.hh>
#include <paludis/repositories/e/qa/root_variable.hh>
#include <paludis/repositories/e/qa/subshell_die.hh>
+#include <paludis/repositories/e/qa/function_keyword.hh>
#include <paludis/repositories/e/qa/whitespace.hh>
#include <paludis/repositories/e/qa/header.hh>
#include <paludis/repositories/e/qa/repo_name.hh>
@@ -101,6 +102,9 @@ QAChecks::QAChecks() :
_imp->eclass_file_contents_checks_group->add_check("header",
tr1::bind(header_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "header"));
+ _imp->eclass_file_contents_checks_group->add_check("function_keyword",
+ tr1::bind(function_keyword_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "function_keyword"));
+
_imp->eclass_file_contents_checks_group->add_check("whitespace",
tr1::bind(whitespace_check, _1, _2, tr1::shared_ptr<const ERepositoryID>(), _5, "whitespace"));
@@ -184,6 +188,9 @@ QAChecks::QAChecks() :
_imp->package_id_file_contents_checks_group->add_check("subshell_die",
tr1::bind(subshell_die_check, _1, _2, _5, _6, "subshell_die"));
+ _imp->package_id_file_contents_checks_group->add_check("function_keyword",
+ tr1::bind(function_keyword_check, _1, _2, _5, _6, "function_keyword"));
+
_imp->package_id_file_contents_checks_group->add_check("whitespace",
tr1::bind(whitespace_check, _1, _2, _5, _6, "whitespace"));