diff options
author | Alexis Hildebrandt <afh@surryhill.net> | 2015-01-25 11:46:40 +0100 |
---|---|---|
committer | Alexis Hildebrandt <afh@surryhill.net> | 2015-01-25 11:51:50 +0100 |
commit | f6fa4de9c5387ec0a60232d7295c0dae624cf029 (patch) | |
tree | 17a34f356cc85f9ce699b5543fca57ef68a87449 /test/CheckOptions.py | |
parent | d94d164b65258d2867245a63877ca75ec3bd471a (diff) | |
download | fork-ledger-f6fa4de9c5387ec0a60232d7295c0dae624cf029.tar.gz fork-ledger-f6fa4de9c5387ec0a60232d7295c0dae624cf029.tar.bz2 fork-ledger-f6fa4de9c5387ec0a60232d7295c0dae624cf029.zip |
[tests] Grep for option alternates during checks
Diffstat (limited to 'test/CheckOptions.py')
-rwxr-xr-x | test/CheckOptions.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/test/CheckOptions.py b/test/CheckOptions.py index 57d711db..124ce197 100755 --- a/test/CheckOptions.py +++ b/test/CheckOptions.py @@ -3,10 +3,12 @@ from __future__ import print_function -import sys import re import os +import sys +import shlex import argparse +import subprocess from os.path import * from subprocess import Popen, PIPE @@ -24,19 +26,22 @@ class CheckOptions (object): self.missing_options = set() self.unknown_options = set() - self.known_alternates = [ - 'cost', - 'first', - 'import', - 'last', - 'leeway', - 'period-sort' - ] - def find_options(self, filename): regex = re.compile(self.option_pattern) return {match.group(1) for match in {regex.match(line) for line in open(filename)} if match} + def find_alternates(self): + regex = re.compile(r'OPT_ALT\([^,]*,\s*([^)]+?)_?\)'); + command = shlex.split('grep --no-filename OPT_ALT') + for source_file in ['session', 'report']: + command.append(os.path.join(self.source, 'src', '%s.cc' % source_file)) + try: + output = subprocess.check_output(command).split('\n'); + except subprocess.CalledProcessError: + output = '' + alternates = {match.group(1).replace('_', '-') for match in {regex.search(line) for line in output} if match} + return alternates + def ledger_options(self): pipe = Popen('%s --debug option.names parse true' % self.ledger, shell=True, stdout=PIPE, stderr=PIPE) @@ -53,7 +58,8 @@ class CheckOptions (object): else: options.remove(option) - self.unknown_options = {option for option in options if option not in self.known_alternates} + known_alternates = self.find_alternates() + self.unknown_options = {option for option in options if option not in known_alternates} if len(self.missing_options): print("Missing %s entries for:%s%s\n" % (self.source_type, self.sep, self.sep.join(sorted(list(self.missing_options))))) |