diff options
Diffstat (limited to 'test/CheckTests.py')
-rwxr-xr-x | test/CheckTests.py | 205 |
1 files changed, 127 insertions, 78 deletions
diff --git a/test/CheckTests.py b/test/CheckTests.py index 1a364ff4..cb9e431e 100755 --- a/test/CheckTests.py +++ b/test/CheckTests.py @@ -1,87 +1,136 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function import sys import re import os +import argparse from os.path import * from subprocess import Popen, PIPE -ledger_binary = sys.argv[1] -source_topdir = sys.argv[2] - -documented_options = [] -for line in open(join(source_topdir, 'doc', 'ledger.1')): - match = re.match('\.It Fl \\\\-([-A-Za-z]+)', line) - if match: - option = match.group(1) - if option not in documented_options: - documented_options.append(option) - -pipe = Popen('%s --debug option.names parse true' % ledger_binary, - shell=True, stdout=PIPE, stderr=PIPE) -errors = 0 - -untested_options = [ - 'anon', - 'args-only', - 'cache', - 'debug', - 'download', - 'file', - 'force-color', - 'force-pager', - 'full-help', - 'help', - 'help-calc', - 'help-comm', - 'help-disp', - 'import', - 'init-file', - 'no-color', - 'options', - 'price-db', - 'price-exp', - 'revalued-total', - 'script', - 'seed', - 'trace', - 'verbose', - 'verify', - 'version' -] - -for line in pipe.stderr: - match = re.search('\[DEBUG\] Option: (.*)', line) - if match: - option = match.group(1) - - option = re.sub('_', '-', option) - option = re.sub('-$', '', option) - - if option not in untested_options and \ - not exists(join(source_topdir, 'test', 'baseline', - 'opt-%s.test' % option)): - print "Baseline test missing for --%s" % option - errors += 1 - - if option not in documented_options: - print "Man page entry missing for --%s" % option - errors += 1 - else: - documented_options.remove(option) - -known_alternates = [ - 'cost', - 'first', - 'import', - 'last', - 'leeway', - 'period-sort' -] - -for option in documented_options: - if option not in known_alternates: - print "Man page entry for unknown option --%s" % option - -sys.exit(errors) +class CheckTests (object): + def __init__(self, args): + self.ledger = os.path.abspath(args.ledger) + self.source = os.path.abspath(args.source) + + self.missing_baseline_tests = set() + self.missing_texi_options = set() + self.unknown_texi_options = set() + self.missing_man_options = set() + self.unknown_man_options = set() + + self.untested_options = [ + 'anon', + 'args-only', + 'cache', + 'debug', + 'download', + 'file', + 'force-color', + 'force-pager', + 'full-help', + 'help', + 'help-calc', + 'help-comm', + 'help-disp', + 'import', + 'init-file', + 'no-color', + 'options', + 'price-db', + 'price-exp', + 'revalued-total', + 'script', + 'seed', + 'trace', + 'verbose', + 'verify', + 'version' + ] + + self.known_alternates = [ + 'cost', + 'first', + 'import', + 'last', + 'leeway', + 'period-sort' + ] + + def find_options(self, pattern, filename): + regex = re.compile(pattern) + return {match.group(1) for match in {regex.match(line) for line in open(filename)} if match} + + def main(self): + man_options = self.find_options('\.It Fl \\\\-([-A-Za-z]+)', + join(self.source, 'doc', 'ledger.1')) + + texi_options = self.find_options('@item --([-A-Za-z]+).*@c option', + join(self.source, 'doc', 'ledger3.texi')) + + pipe = Popen('%s --debug option.names parse true' % self.ledger, + shell=True, stdout=PIPE, stderr=PIPE) + regex = re.compile('\[DEBUG\] Option: (.*)') + for line in filter(regex.search, [line.decode() for line in pipe.stderr]): + match = regex.search(line) + option = match.group(1) + option = re.sub('_', '-', option) + option = re.sub('-$', '', option) + + if option not in self.untested_options and \ + not exists(join(self.source, 'test', 'baseline', + 'opt-%s.test' % option)): + self.missing_baseline_tests.add(option) + + if option not in man_options: + self.missing_man_options.add(option) + else: + man_options.remove(option) + + if option not in texi_options: + self.missing_texi_options.add(option) + else: + texi_options.remove(option) + + self.unknown_man_options = [option for option in man_options if option not in self.known_alternates] + self.unknown_texi_options = [option for option in texi_options if option not in self.known_alternates] + + sep = "\n --" + if len(self.missing_baseline_tests): + print("Missing Baseline test for:%s%s\n" % (sep, sep.join(sorted(list(self.missing_baseline_tests))))) + if len(self.missing_man_options): + print("Missing man page entries for:%s%s\n" % (sep, sep.join(sorted(list(self.missing_man_options))))) + if len(self.missing_texi_options): + print("Missing texi entries for:%s%s\n" % (sep, sep.join(sorted(list(self.missing_texi_options))))) + if len(self.unknown_man_options): + print("Man page entry for unknown options:%s%s" % (sep, sep.join(sorted(list(self.unknown_man_options))))) + if len(self.unknown_texi_options): + print("Texi entry for unknown option:%s%s" % (sep, sep.join(sorted(list(self.unknown_texi_options))))) + + errors = len(self.missing_baseline_tests) + len(self.missing_man_options) + len(self.missing_baseline_tests) + return errors + +if __name__ == "__main__": + def getargs(): + parser = argparse.ArgumentParser(prog='CheckTests', description='Check that ledger options are tested and documented', prefix_chars='-') + parser.add_argument('-l', '--ledger', + dest='ledger', + type=str, + action='store', + required=True, + help='the path to the ledger executable to test with') + parser.add_argument('-s', '--source', + dest='source', + type=str, + action='store', + required=True, + help='the path to the top level ledger source directory') + return parser.parse_args() + + args = getargs() + script = CheckTests(args) + status = script.main() + sys.exit(status) |