[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Findutils-patches] [PATCH 4/4] Routinely check .xo and .exp test file l
From: |
James Youngman |
Subject: |
[Findutils-patches] [PATCH 4/4] Routinely check .xo and .exp test file lists in a clearer way. |
Date: |
Sun, 1 Jun 2014 00:29:20 +0100 |
* find/testsuite/checklists.py: Tiny program for checking that the
correct lists of .xo and .exp files exist in the Makefile.am file.
* Makefile.am (checklists): Update target to use the new program.
Make this target phony.
---
ChangeLog | 6 +++
find/testsuite/Makefile.am | 21 +++++-----
find/testsuite/checklists.py | 91 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+), 9 deletions(-)
create mode 100644 find/testsuite/checklists.py
diff --git a/ChangeLog b/ChangeLog
index 9297aa3..4508108 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,12 @@
Automake-driven tests scroll offscreen.
(TEST_EXTENSIONS): Add .sh and .py.
+ Routinely check .xo and .exp test file lists in a clearer way.
+ * find/testsuite/checklists.py: Tiny program for checking that the
+ correct lists of .xo and .exp files exist in the Makefile.am file.
+ * Makefile.am (checklists): Update target to use the new program.
+ Make this target phony.
+
2014-05-25 Eric S. Raymond <address@hidden>
Fix errant backslash in find manpage.
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
index 70b84c0..0e0ac0a 100644
--- a/find/testsuite/Makefile.am
+++ b/find/testsuite/Makefile.am
@@ -239,9 +239,9 @@ sv-34079.sh \
sv-34976-execdir-fd-leak.sh
EXTRA_DIST = $(EXTRA_DIST_EXP) $(EXTRA_DIST_XO) $(EXTRA_DIST_GOLDEN) \
- $(test_shell_progs) binary_locations.sh
+ $(test_shell_progs) binary_locations.sh checklists.py
-CLEANFILES = *.log *.sum site.exp site.bak
+CLEANFILES = *.log *.sum site.exp site.bak configured-testfiles.txt
#DIST_SUBDIRS = config
@@ -251,10 +251,13 @@ TEST_EXTENSIONS = .sh .py
check-local: checklists
-checklists:
- @cd $(srcdir) && \
- ( find config find.gnu find.posix \( -name "*.exp" -o -name "*.xo" \)
-print ; \
- ls $(EXTRA_DIST_XO) ; \
- ls $(EXTRA_DIST_EXP) ; ) | \
- sort | uniq -c | \
- awk '$$1 != 2 { print; fail=1; } END { if (fail) { print "FAIL:
Duplicate test files"; exit(1); } }'
+configured-testfiles.txt: Makefile
+ @echo Generating $@
+ @( cd $(srcdir) && ls $(EXTRA_DIST_XO) && ls $(EXTRA_DIST_EXP) ) >| $@
+
+.PHONY: checklists
+
+checklists: configured-testfiles.txt Makefile
+ $(PYTHON) $(srcdir)/checklists.py configured-testfiles.txt $(srcdir)
config find.gnu find.posix
+
+
diff --git a/find/testsuite/checklists.py b/find/testsuite/checklists.py
new file mode 100644
index 0000000..2a2fd10
--- /dev/null
+++ b/find/testsuite/checklists.py
@@ -0,0 +1,91 @@
+"""Check that the list of test files in Makefile.am is complete and not
redundant.
+
+Usage:
+ checklists file-listing-configured-files test-root subdir-1-containing-tests
[subdir-2-containing-tests ...]
+"""
+
+import os
+import os.path
+import re
+import sys
+
+def report_unlisted(filename):
+ sys.stderr.write(
+ 'Error: test file %s is not listed in Makefile.am but exists on
disk.\n'
+ % (filename,))
+
+
+def report_missing(filename):
+ sys.stderr.write(
+ 'Error: test file %s is listed in Makefile.am but does not exist on
disk.\n'
+ % (filename,))
+
+def report_dupe(filename):
+ sys.stderr.write(
+ 'Error: test file %s is listed more than once in Makefile.am.\n'
+ % (filename,))
+
+
+def report_problems(problem_filenames, reporting_function):
+ for f in problem_filenames:
+ reporting_function(f)
+ return len(problem_filenames)
+
+
+def file_names(listfile_name):
+ for line in open(listfile_name, 'r').readlines():
+ yield line.rstrip('\n')
+
+
+def configured_file_names(listfile_name):
+ dupes = set()
+ result = set()
+ for filename in file_names(listfile_name):
+ if filename in result:
+ dupes.add(filename)
+ else:
+ result.add(filename)
+ return dupes, result
+
+
+def find_test_files(roots):
+ testfile_rx = re.compile(r'\.(exp|xo)$')
+ for root in roots:
+ for parent, dirs, files in os.walk(root):
+ for file_basename in files:
+ if testfile_rx.search(file_basename):
+ yield os.path.join(parent, file_basename)
+
+
+class TemporaryWorkingDirectory(object):
+
+ def __init__(self, cwd):
+ self.new_cwd = cwd
+ self.old_cwd = os.getcwd()
+
+ def __enter__(self):
+ os.chdir(self.new_cwd)
+
+ def __exit__(self, *unused_args):
+ os.chdir(self.old_cwd)
+
+
+def main(args):
+ if len(args) < 3:
+ sys.stderr.write(__doc__)
+ return 1
+ dupes, configured = configured_file_names(args[1])
+ with TemporaryWorkingDirectory(args[2]):
+ actual = set(find_test_files(args[3:]))
+ print '%d test files configured for find, %s files on-disk' %
(len(configured), len(actual))
+ problem_count = 0
+ problem_count += report_problems(dupes, report_dupe)
+ problem_count += report_problems(configured - actual, report_missing)
+ problem_count += report_problems(actual - configured, report_unlisted)
+ if problem_count:
+ return 1
+ else:
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
--
1.7.10.4