[PATCH] Make the lists of files to check consistent across all checks.

David Shea dshea at redhat.com
Mon Mar 17 17:58:23 UTC 2014


Add shell and python functions to provide a list of potential files to
check. Fallback to a full file list if not run from a git tree.
---
 tests/Makefile.am                 |  1 +
 tests/cppcheck/runcppcheck.sh     |  9 +++++-
 tests/gettext/gettext_potfiles.py | 65 ++++++++++++++++++++-------------------
 tests/glade/run_glade_tests.sh    | 10 +++++-
 tests/pylint/runpylint.sh         | 14 ++++++---
 5 files changed, 62 insertions(+), 37 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 479e68c..6ab99b8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,7 @@ dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
 		     glade/format_string/check_format_string.py \
 		     glade/run_glade_tests.sh \
 		     $(srcdir)/lib/*.py \
+		     $(srcdir)/lib/*.sh \
 		     nosetests.sh \
 		     pylint/intl.py \
 		     pylint/preconf.py \
diff --git a/tests/cppcheck/runcppcheck.sh b/tests/cppcheck/runcppcheck.sh
index 7dc2f4d..4b2d519 100755
--- a/tests/cppcheck/runcppcheck.sh
+++ b/tests/cppcheck/runcppcheck.sh
@@ -6,6 +6,8 @@ if [ -z "$top_srcdir" ]; then
     . ${top_srcdir}/tests/testenv.sh
 fi
 
+. ${top_srcdir}/tests/lib/testlib.sh
+
 if ! type cppcheck > /dev/null 2>&1 ; then
     echo "cppcheck must be installed"
     exit 99
@@ -13,10 +15,15 @@ fi
 
 # If files were specified on the command line, use those. Otherwise, look
 # for all .c files
+filelist=
 if [ "$#" -gt 0 ]; then
     filelist="$@"
 else
-    filelist="$(find "$top_srcdir" -name '*.c')"
+    for testfile in $(testfilelist); do
+        if [ "${testfile%.c}" != "${testfile}" ]; then
+            filelist="$filelist $testfile"
+        fi
+    done
 fi
 
 # Disable unusedFunction in widgets since everything will show up as unused
diff --git a/tests/gettext/gettext_potfiles.py b/tests/gettext/gettext_potfiles.py
index 96daec8..5d80308 100755
--- a/tests/gettext/gettext_potfiles.py
+++ b/tests/gettext/gettext_potfiles.py
@@ -11,52 +11,55 @@ if "top_srcdir" not in os.environ:
     # This return code tells the automake test driver that the test setup failed
     sys.exit(99)
 
+# Ensure that tests/lib is in sys.path
+testlibpath = os.path.abspath(os.path.join(os.environ["top_srcdir"], "tests/lib"))
+if testlibpath not in sys.path:
+    sys.path.append(testlibpath)
+
+from filelist import testfilelist
+
 success = True
 
-def check_potfiles(checklist, dirname, names):
+def check_potfile(checkfile, potlist):
     global success
 
-    potcheckfiles = []
+    potcheckfile = None
+    if checkfile.endswith(".py"):
+        # Check whether the file imports the i18n module
+        if subprocess.call(["grep", "-q", "^from pyanaconda.i18n import", checkfile]) == 0:
+            potcheckfile = checkfile
+    elif checkfile.endswith(".c"):
+        # Check whether the file includes intl.h
+        if subprocess.call(["grep", "-q", "#include .intl\\.h.", checkfile]) == 0:
+            potcheckfile = checkfile
+    elif checkfile.endswith(".glade"):
+        # Look for a "translatable=yes" attribute
+        if ET.parse(checkfile).findall(".//*[@translatable='yes']"):
+            potcheckfile = checkfile
+    elif checkfile.endswith(".desktop.in"):
+        # These are handled by intltool, make sure the .h version is present
+        potcheckfile = checkfile + ".h"
 
-    # Skip the .git directory
-    if ".git" in names:
-        names.remove(".git")
+    if not potcheckfile:
+        return
 
-    # Strip the "./" component from the path name
-    dirname = os.path.relpath(dirname, ".")
+    # Compute the path relative to top_srcdir
+    potcheckfile = os.path.relpath(potcheckfile, os.environ["top_srcdir"])
 
-    for checkfile in (os.path.join(dirname, name) for name in names):
-        if checkfile.endswith(".py"):
-            # Check whether the file imports the i18n module
-            if subprocess.call(["grep", "-q", "^from pyanaconda.i18n import", checkfile]) == 0:
-                potcheckfiles.append(checkfile)
-        elif checkfile.endswith(".c"):
-            # Check whether the file includes intl.h
-            if subprocess.call(["grep", "-q", "#include .intl\\.h.", checkfile]) == 0:
-                potcheckfiles.append(checkfile)
-        elif checkfile.endswith(".glade"):
-            # Look for a "translatable=yes" attribute
-            if ET.parse(checkfile).findall(".//*[@translatable='yes']"):
-                potcheckfiles.append(checkfile)
-        elif checkfile.endswith(".desktop.in"):
-            # These are handled by intltool, make sure the .h version is present
-            potcheckfiles.append(checkfile + ".h")
-
-    difference = set(potcheckfiles) - checklist
-    for missing in difference:
-        sys.stderr.write("%s not in POTFILES.in\n" % missing)
+    if potcheckfile not in potlist:
+        sys.stderr.write("%s not in POTFILES.in\n" % potcheckfile)
         success = False
 
 # Read in POTFILES.in, skip comments and blank lines
-POTFILES = []
+POTFILES = set()
 with open(os.path.join(os.environ["top_srcdir"], "po", "POTFILES.in")) as f:
     for line in (line.strip() for line in f):
         if line and not line.startswith("#"):
-            POTFILES.append(line)
+            POTFILES.add(line)
 
 # Walk the source tree and look for files with translatable strings
-os.chdir(os.environ["top_srcdir"])
-os.path.walk(".", check_potfiles, set(POTFILES))
+for testfile in testfilelist():
+    check_potfile(testfile, POTFILES)
 
 if not success:
     sys.exit(1)
diff --git a/tests/glade/run_glade_tests.sh b/tests/glade/run_glade_tests.sh
index 6f34484..4fafe1b 100755
--- a/tests/glade/run_glade_tests.sh
+++ b/tests/glade/run_glade_tests.sh
@@ -3,6 +3,7 @@
 : "${top_srcdir:=$(dirname "$0")/../..}"
 . "${top_srcdir}/tests/testenv.sh"
 srcdir="${top_srcdir}/tests/glade"
+. "${top_srcdir}/tests/lib/testlib.sh"
 
 # If --translated was specified but not --podir, add --podir
 translate_set=0
@@ -19,9 +20,16 @@ if [ "$translate_set" -eq 1 -a "$podir_set" -eq 0 ]; then
     set -- "$@" --podir "${top_srcdir}/po"
 fi
 
+filelist=
+for testfile in $(testfilelist); do
+    if [ "${testfile%.glade}" != "${testfile}" ]; then
+        filelist="$filelist $testfile"
+    fi
+done
+
 status=0
 for check in ${srcdir}/*/check_*.py ; do
-    find "${top_srcdir}" -name '*.glade' | xargs "${check}" "$@"
+    echo $filelist | xargs "${check}" "$@"
     if [ "$?" -ne 0 ]; then
         status=1
     fi
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
index 93896ad..c347724 100755
--- a/tests/pylint/runpylint.sh
+++ b/tests/pylint/runpylint.sh
@@ -34,6 +34,8 @@ if [ -z "$top_srcdir" ]; then
     . ${top_srcdir}/tests/testenv.sh
 fi
 
+. ${top_srcdir}/tests/lib/testlib.sh
+
 srcdir="${top_srcdir}/tests/pylint"
 builddir="${top_builddir}/tests/pylint"
 
@@ -96,10 +98,14 @@ fi
 # run pylint one file / module at a time, otherwise it sometimes gets
 # confused
 if [ -z "$FILES" ]; then
-    # Find any file in the git working tree that either ends in .py
-    # or contains #!/usr/bin/python in the first line.
-    # Scan everything except old_tests
-    for testfile in $(git ls-files -c "${top_srcdir}" | egrep -v '(^|/)old_tests/') ; do
+    # Test any file that either ends in .py or contains #!/usr/bin/python in
+    # the first line.  Scan everything except old_tests
+
+    for testfile in $(testfilelist); do
+        if echo "$testfile" | egrep -q '(^|/)old_tests/'; then
+            continue
+        fi
+
         if [ -f "${testfile}" ] && \
                 ( [ "${testfile%.py}" != "${testfile}" ] || \
                   head -1 "${testfile}" | grep -q '^#!/usr/bin/python' ) ; then
-- 
1.9.0



More information about the anaconda-patches mailing list