aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-14 13:02:56 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-14 13:02:56 +0000
commit83f508a6cac3660f84fbe36f700988999ec35c3b (patch)
treeaaad620abf15fd5f7c7fe867ab8cc3ca3dec3b2f
parent44a93ae99625de2d05067b590e1a06cc527106d6 (diff)
downloadpaludis-83f508a6cac3660f84fbe36f700988999ec35c3b.tar.gz
paludis-83f508a6cac3660f84fbe36f700988999ec35c3b.tar.xz
More checks
-rw-r--r--paludis/qa/changelog_check.cc50
-rw-r--r--paludis/qa/changelog_check.hh46
-rw-r--r--paludis/qa/check_result.cc8
-rw-r--r--paludis/qa/check_result.hh2
-rw-r--r--paludis/qa/file_name_check.cc53
-rw-r--r--paludis/qa/file_name_check.hh46
-rw-r--r--paludis/qa/files.m43
-rw-r--r--paludis/qa/glep_31_check.cc126
-rw-r--r--paludis/qa/glep_31_check.hh50
-rw-r--r--paludis/qa/glep_31_check_TEST.cc72
-rw-r--r--src/qualudis/qualudis.cc2
11 files changed, 456 insertions, 2 deletions
diff --git a/paludis/qa/changelog_check.cc b/paludis/qa/changelog_check.cc
new file mode 100644
index 0000000..650bbef
--- /dev/null
+++ b/paludis/qa/changelog_check.cc
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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 "changelog_check.hh"
+#include <paludis/pstream.hh>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+ChangeLogCheck::ChangeLogCheck()
+{
+}
+
+CheckResult
+ChangeLogCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ if (f.basename() != "ChangeLog")
+ result << Message(qal_skip, "Not a ChangeLog");
+ else if (! f.is_regular_file())
+ result << Message(qal_major, "Not a regular file");
+
+ return result;
+}
+
+const std::string &
+ChangeLogCheck::identifier()
+{
+ static const std::string id("changelog");
+ return id;
+}
+
+
diff --git a/paludis/qa/changelog_check.hh b/paludis/qa/changelog_check.hh
new file mode 100644
index 0000000..15257e1
--- /dev/null
+++ b/paludis/qa/changelog_check.hh
@@ -0,0 +1,46 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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_CHANGELOG_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_CHANGELOG_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class ChangeLogCheck :
+ public FileCheck
+ {
+ public:
+ ChangeLogCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+ };
+
+ static const FileCheckMaker::RegisterMaker register_changelog_check(
+ ChangeLogCheck::identifier(), &make_file_check<ChangeLogCheck>);
+ }
+}
+
+#endif
diff --git a/paludis/qa/check_result.cc b/paludis/qa/check_result.cc
index a216cc4..eb1b5c1 100644
--- a/paludis/qa/check_result.cc
+++ b/paludis/qa/check_result.cc
@@ -24,7 +24,13 @@ using namespace paludis::qa;
CheckResult::CheckResult(const FSEntry & f, const std::string & r) :
_item(stringify(f)),
- _rule(stringify(r))
+ _rule(r)
+{
+}
+
+CheckResult::CheckResult(const std::string & f, const std::string & r) :
+ _item(f),
+ _rule(r)
{
}
diff --git a/paludis/qa/check_result.hh b/paludis/qa/check_result.hh
index 96cbf95..12e0799 100644
--- a/paludis/qa/check_result.hh
+++ b/paludis/qa/check_result.hh
@@ -50,6 +50,8 @@ namespace paludis
public:
CheckResult(const FSEntry &, const std::string &);
+ CheckResult(const std::string &, const std::string &);
+
bool empty() const
{
return _messages.empty();
diff --git a/paludis/qa/file_name_check.cc b/paludis/qa/file_name_check.cc
new file mode 100644
index 0000000..aae5084
--- /dev/null
+++ b/paludis/qa/file_name_check.cc
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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 "file_name_check.hh"
+
+using namespace paludis;
+using namespace paludis::qa;
+
+FileNameCheck::FileNameCheck()
+{
+}
+
+CheckResult
+FileNameCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static const std::string allowed(
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789"
+ "+-_.:");
+
+ if (std::string::npos != f.basename().find_first_not_of(allowed))
+ result << Message(qal_major, "Illegal filename");
+
+ return result;
+}
+
+const std::string &
+FileNameCheck::identifier()
+{
+ static const std::string id("file name");
+ return id;
+}
+
+
diff --git a/paludis/qa/file_name_check.hh b/paludis/qa/file_name_check.hh
new file mode 100644
index 0000000..decb36a
--- /dev/null
+++ b/paludis/qa/file_name_check.hh
@@ -0,0 +1,46 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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_FILE_NAME_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_FILE_NAME_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class FileNameCheck :
+ public FileCheck
+ {
+ public:
+ FileNameCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+ };
+
+ static const FileCheckMaker::RegisterMaker register_file_name_check(
+ FileNameCheck::identifier(), &make_file_check<FileNameCheck>);
+ }
+}
+
+#endif
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 061cef5..5888837 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -8,11 +8,14 @@ dnl the base filename with no extension; later parameters can be `hh', `cc',
dnl `test', `impl', `testscript'. Note that there isn't much error checking done
dnl on this file at present...
+add(`changelog_check', `hh', `cc')
add(`check', `hh', `cc')
add(`check_result', `hh', `cc', `test')
add(`environment', `hh', `cc')
add(`file_check', `hh', `cc')
+add(`file_name_check', `hh', `cc')
add(`file_permissions_check', `hh', `cc', `test', `testscript')
+add(`glep_31_check', `hh', `cc', `test')
add(`has_ebuilds_check', `hh', `cc', `test', `testscript')
add(`has_misc_files_check', `hh', `cc', `test', `testscript')
add(`message', `hh', `cc', `test')
diff --git a/paludis/qa/glep_31_check.cc b/paludis/qa/glep_31_check.cc
new file mode 100644
index 0000000..9992508
--- /dev/null
+++ b/paludis/qa/glep_31_check.cc
@@ -0,0 +1,126 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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 "glep_31_check.hh"
+#include <fstream>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+void
+Glep31Check::check_utf8(std::istream & f, CheckResult & r)
+{
+ struct BadChar
+ {
+ };
+
+ int c, line_number(1);
+ try
+ {
+ while (std::istream::traits_type::eof() != ((c = f.get())))
+ {
+ if (c < 0)
+ throw BadChar();
+
+ else if (c > 0x7e && (((c & 0xe0) == 0xc0)))
+ {
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+ }
+ else if (c > 0x7e && (((c & 0xf0) == 0xe0)))
+ {
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+ }
+ else if (c > 0x7e && (((c & 0xf8) == 0xf0)))
+ {
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+
+ if (std::istream::traits_type::eof() == ((c = f.get())))
+ throw BadChar();
+
+ if ((c & 0xc0) != 0x80)
+ throw BadChar();
+ }
+ else if ('\n' == c)
+ ++line_number;
+ else if (c <= 0x7e)
+ ;
+ else
+ throw BadChar();
+ }
+ }
+ catch (const BadChar &)
+ {
+ r << Message(qal_major, "Bad character on line " + stringify(line_number));
+ }
+}
+
+Glep31Check::Glep31Check()
+{
+}
+
+CheckResult
+Glep31Check::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ if (! f.is_regular_file())
+ result << Message(qal_skip, "Not a regular file");
+ else
+ {
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ result << Message(qal_major, "Can't read file");
+ else
+ check_utf8(ff, result);
+ }
+
+ return result;
+}
+
+const std::string &
+Glep31Check::identifier()
+{
+ static const std::string id("glep 31");
+ return id;
+}
+
diff --git a/paludis/qa/glep_31_check.hh b/paludis/qa/glep_31_check.hh
new file mode 100644
index 0000000..2a4771a
--- /dev/null
+++ b/paludis/qa/glep_31_check.hh
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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_GLEP_31_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_GLEP_31_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+#include <string>
+#include <istream>
+
+namespace paludis
+{
+ namespace qa
+ {
+ class Glep31Check :
+ public FileCheck
+ {
+ public:
+ Glep31Check();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ static void check_utf8(std::istream &, CheckResult &);
+ };
+
+ static const FileCheckMaker::RegisterMaker register_glep_31_check(
+ Glep31Check::identifier(), &make_file_check<Glep31Check>);
+ }
+}
+
+
+#endif
diff --git a/paludis/qa/glep_31_check_TEST.cc b/paludis/qa/glep_31_check_TEST.cc
new file mode 100644
index 0000000..b4e8a73
--- /dev/null
+++ b/paludis/qa/glep_31_check_TEST.cc
@@ -0,0 +1,72 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@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 "glep_31_check.hh"
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+#include <sstream>
+
+using namespace paludis;
+using namespace paludis::qa;
+using namespace test;
+
+namespace test_cases
+{
+ struct Utf8Test : TestCase
+ {
+ Utf8Test() : TestCase("utf8") { }
+
+ void check_valid(const std::string & s)
+ {
+ std::stringstream ss(s);
+ CheckResult r("glep_31_check_TEST.cc", "test");
+ TEST_CHECK(r.empty());
+ Glep31Check::check_utf8(ss, r);
+ TEST_CHECK(r.empty());
+ }
+
+ void check_invalid(const std::string & s)
+ {
+ std::stringstream ss(s);
+ CheckResult r("glep_31_check_TEST.cc", "test");
+ TEST_CHECK(r.empty());
+ Glep31Check::check_utf8(ss, r);
+ TEST_CHECK(! r.empty());
+ }
+
+ void run()
+ {
+ check_valid("");
+ check_valid("abcde");
+ check_valid("abc""\xc2""\xa3""de");
+ check_valid("abc""\xd7""\x90""de");
+ check_valid("abc""\xe2""\x82""\xac""de");
+ check_valid("abc""\xf0""\xa1""\xa1""\xa1""de");
+
+ check_invalid("abc""\xff""de");
+ check_invalid("abc""\xc2""\x2a""de");
+ check_invalid("abc""\xe1""\x2a""\x2a""de");
+ check_invalid("abc""\xe1""\xaa""\x2a""de");
+ check_invalid("abc""\xf0""\x2a""\x2a""\x2a""de");
+ check_invalid("abc""\xf0""\xaa""\x2a""\x2a""de");
+ check_invalid("abc""\xf0""\xa1""\xa1""\x2a""de");
+ }
+ } test_utf8;
+}
+
diff --git a/src/qualudis/qualudis.cc b/src/qualudis/qualudis.cc
index 2c2e6a0..27111ee 100644
--- a/src/qualudis/qualudis.cc
+++ b/src/qualudis/qualudis.cc
@@ -249,7 +249,7 @@ namespace
ok = false;
}
- if (f->is_directory())
+ if (f->is_directory() && f->basename() != "CVS" && '.' != f->basename().at(0))
files.insert(files.end(), DirIterator(*f), DirIterator());
}
}