aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-02-18 22:05:50 +0000
committerAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-02-18 22:05:50 +0000
commit99d62760803ecf23cc3fc6d012c2b8a95f75bcc5 (patch)
treee019698dd55bcd38b497766a195e1d2777717607
parent43b4d2f463a532d62844bccd659edfa2445b204f (diff)
downloadpaludis-99d62760803ecf23cc3fc6d012c2b8a95f75bcc5.tar.gz
paludis-99d62760803ecf23cc3fc6d012c2b8a95f75bcc5.tar.xz
Check for people using the 'function' keyword. Fixes ticket:105
-rw-r--r--paludis/qa/file_check.cc2
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/function_check.cc75
-rw-r--r--paludis/qa/function_check.hh53
-rw-r--r--paludis/qa/function_check_TEST.cc67
-rwxr-xr-xpaludis/qa/function_check_TEST_cleanup.sh8
-rwxr-xr-xpaludis/qa/function_check_TEST_setup.sh33
7 files changed, 239 insertions, 0 deletions
diff --git a/paludis/qa/file_check.cc b/paludis/qa/file_check.cc
index b0f5f1a..76cc729 100644
--- a/paludis/qa/file_check.cc
+++ b/paludis/qa/file_check.cc
@@ -23,6 +23,7 @@
#include <paludis/qa/deprecated_functions_check.hh>
#include <paludis/qa/filename_check.hh>
#include <paludis/qa/file_permissions_check.hh>
+#include <paludis/qa/function_check.hh>
#include <paludis/qa/glep_31_check.hh>
#include <paludis/qa/header_check.hh>
#include <paludis/qa/metadata_check.hh>
@@ -50,6 +51,7 @@ FileCheckMaker::FileCheckMaker()
register_maker(DeprecatedFunctionsCheck::identifier(), &MakeFileCheck<DeprecatedFunctionsCheck>::make_file_check);
register_maker(FileNameCheck::identifier(), &MakeFileCheck<FileNameCheck>::make_file_check);
register_maker(FilePermissionsCheck::identifier(), &MakeFileCheck<FilePermissionsCheck>::make_file_check);
+ register_maker(FunctionCheck::identifier(), &MakeFileCheck<FunctionCheck>::make_file_check);
register_maker(Glep31Check::identifier(), &MakeFileCheck<Glep31Check>::make_file_check);
register_maker(HeaderCheck::identifier(), &MakeFileCheck<HeaderCheck>::make_file_check);
register_maker(MetadataCheck::identifier(), &MakeFileCheck<MetadataCheck>::make_file_check);
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index eb1b05e..2ccfb74 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -30,6 +30,7 @@ add(`file_check', `hh', `cc')
add(`filename_check', `hh', `cc')
add(`file_permissions_check', `hh', `cc', `test', `testscript')
add(`files_dir_size_check', `hh', `cc')
+add(`function_check', `hh', `cc', `test', `testscript')
add(`glep_31_check', `hh', `cc', `test')
add(`gpg_check', `hh', `cc', `test', `testscript')
add(`has_ebuilds_check', `hh', `cc', `test', `testscript')
diff --git a/paludis/qa/function_check.cc b/paludis/qa/function_check.cc
new file mode 100644
index 0000000..4e0298f
--- /dev/null
+++ b/paludis/qa/function_check.cc
@@ -0,0 +1,75 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda <ferdy@gentoo.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 <fstream>
+#include <paludis/qa/function_check.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <pcre++.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+FunctionCheck::FunctionCheck()
+{
+}
+
+CheckResult
+FunctionCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static pcrepp::Pcre::Pcre r_function("^function +[^ ]+ *(\\(\\))? *{?");
+
+ if (! f.is_regular_file())
+ result << Message(qal_skip, "Not a regular file.");
+ else if (! IsFileWithExtension(".ebuild")(f) &&
+ ! IsFileWithExtension(".eclass")(f))
+ result << Message(qal_skip, "Not an ebuild or eclass.");
+ else
+ {
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ result << Message(qal_major, "Could not read file.");
+ else
+ {
+ std::string s;
+ unsigned line_number(0);
+ while (std::getline(ff, s))
+ {
+ ++line_number;
+
+ if (s.empty())
+ continue;
+
+ if (r_function.search(s))
+ result << Message(qal_minor, "Use of the keyword 'function' on line "
+ + stringify(line_number));
+ }
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+FunctionCheck::identifier()
+{
+ static const std::string id("function");
+ return id;
+}
diff --git a/paludis/qa/function_check.hh b/paludis/qa/function_check.hh
new file mode 100644
index 0000000..0fea495
--- /dev/null
+++ b/paludis/qa/function_check.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda <ferdy@gentoo.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
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_QA_FUNCTION_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_FUNCTION_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: use of the 'function' keyword.
+ *
+ * \ingroup grpqacheck
+ */
+ class FunctionCheck :
+ public FileCheck
+ {
+ public:
+ FunctionCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Check if ebuilds use the 'function' keyword.";
+ }
+ };
+ }
+}
+
+#endif
diff --git a/paludis/qa/function_check_TEST.cc b/paludis/qa/function_check_TEST.cc
new file mode 100644
index 0000000..8d14a7d
--- /dev/null
+++ b/paludis/qa/function_check_TEST.cc
@@ -0,0 +1,67 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda <ferdy@gentoo.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 "check_result.hh"
+#include "function_check.hh"
+#include <paludis/util/fs_entry.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace test;
+
+namespace test_cases
+{
+ struct FunctionCheckTest : TestCase
+ {
+ FunctionCheckTest() : TestCase("function") { }
+
+ void run()
+ {
+ FSEntry d("function_check_TEST_dir");
+ TEST_CHECK(d.is_directory());
+
+ FSEntry w1(d / "eclass/with1.eclass");
+ TEST_CHECK(w1.is_regular_file());
+ CheckResult r1((*(*FileCheckMaker::get_instance()->find_maker(
+ FunctionCheck::identifier()))())(w1));
+ TEST_CHECK(! r1.empty());
+
+ FSEntry w2(d / "eclass/with2.eclass");
+ TEST_CHECK(w2.is_regular_file());
+ CheckResult r2((*(*FileCheckMaker::get_instance()->find_maker(
+ FunctionCheck::identifier()))())(w2));
+ TEST_CHECK(! r2.empty());
+
+ FSEntry w3(d / "eclass/with3.eclass");
+ TEST_CHECK(w3.is_regular_file());
+ CheckResult r3((*(*FileCheckMaker::get_instance()->find_maker(
+ FunctionCheck::identifier()))())(w3));
+ TEST_CHECK(! r3.empty());
+
+
+ FSEntry wo(d / "eclass/without.eclass");
+ TEST_CHECK(wo.is_regular_file());
+ CheckResult r4((*(*FileCheckMaker::get_instance()->find_maker(
+ FunctionCheck::identifier()))())(wo));
+ TEST_CHECK(r4.empty());
+ }
+ } function_check_test;
+}
diff --git a/paludis/qa/function_check_TEST_cleanup.sh b/paludis/qa/function_check_TEST_cleanup.sh
new file mode 100755
index 0000000..c12c92f
--- /dev/null
+++ b/paludis/qa/function_check_TEST_cleanup.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d function_check_TEST_dir ] ; then
+ rm -fr function_check_TEST_dir
+else
+ true
+fi
diff --git a/paludis/qa/function_check_TEST_setup.sh b/paludis/qa/function_check_TEST_setup.sh
new file mode 100755
index 0000000..d2ca191
--- /dev/null
+++ b/paludis/qa/function_check_TEST_setup.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir function_check_TEST_dir || exit 2
+cd function_check_TEST_dir || exit 3
+
+mkdir "eclass" || exit 4
+
+cat << EOE > eclass/with1.eclass || exit 5
+function something () {
+ : ;
+}
+EOE
+
+cat << EOE > eclass/with2.eclass || exit 6
+function foo
+{
+ : ;
+}
+EOE
+
+cat << EOE > eclass/with3.eclass || exit 7
+function bar (){
+ : ;
+}
+EOE
+
+cat << EOE > eclass/without.eclass || exit 8
+# function something
+bah() {
+ : ;
+}
+EOE