1 """Check that the list of test files in Makefile.am is complete and not redundant.
4 checklists file-listing-configured-files test-root subdir-1-containing-tests [subdir-2-containing-tests ...]
12 def report_unlisted(filename):
14 'Error: test file %s is not listed in Makefile.am but exists on disk.\n'
18 def report_missing(filename):
20 'Error: test file %s is listed in Makefile.am but does not exist on disk.\n'
23 def report_dupe(filename):
25 'Error: test file %s is listed more than once in Makefile.am.\n'
29 def report_problems(problem_filenames, reporting_function):
30 for f in problem_filenames:
32 return len(problem_filenames)
35 def file_names(listfile_name):
36 for line in open(listfile_name, 'r').readlines():
37 yield line.rstrip('\n')
40 def configured_file_names(listfile_name):
43 for filename in file_names(listfile_name):
44 if filename in result:
51 def find_test_files(roots):
52 testfile_rx = re.compile(r'\.(exp|xo)$')
54 for parent, dirs, files in os.walk(root):
55 for file_basename in files:
56 if testfile_rx.search(file_basename):
57 yield os.path.join(parent, file_basename)
60 class TemporaryWorkingDirectory(object):
62 def __init__(self, cwd):
64 self.old_cwd = os.getcwd()
67 os.chdir(self.new_cwd)
69 def __exit__(self, *unused_args):
70 os.chdir(self.old_cwd)
75 sys.stderr.write(__doc__)
77 dupes, configured = configured_file_names(args[1])
78 with TemporaryWorkingDirectory(args[2]):
79 actual = set(find_test_files(args[3:]))
80 print '%d test files configured for find, %s files on-disk' % (len(configured), len(actual))
82 problem_count += report_problems(dupes, report_dupe)
83 problem_count += report_problems(configured - actual, report_missing)
84 problem_count += report_problems(actual - configured, report_unlisted)
90 if __name__ == '__main__':
91 sys.exit(main(sys.argv))