summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/CMakeLists.txt2
-rwxr-xr-xtest/DocTests.py56
2 files changed, 37 insertions, 21 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 159ab5be..796ef0a2 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -45,7 +45,7 @@ if(PYTHONINTERP_FOUND)
get_filename_component(TestFile_Name ${TestFile} NAME_WE)
add_test(${_class}Test_${TestFile_Name}
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/DocTests.py
- ${LEDGER_LOCATION} ${TestFile})
+ --ledger ${LEDGER_LOCATION} --file ${TestFile})
set_target_properties(check PROPERTIES DEPENDS ${_class}Test_${TestFile_Name})
endforeach()
endif()
diff --git a/test/DocTests.py b/test/DocTests.py
index 736be6c7..a50ec03d 100755
--- a/test/DocTests.py
+++ b/test/DocTests.py
@@ -5,29 +5,23 @@ import os
import re
import sys
import hashlib
+import argparse
import subprocess
from difflib import unified_diff
class DocTests:
- def __init__(self, argv):
- if not os.path.isfile(argv[1]):
- print "Cannot find ledger at '%s'" % argv[1]
- sys.exit(1)
- if not os.path.isfile(argv[2]):
- print "Cannot find source path at '%s'" % argv[2]
- sys.exit(1)
-
- self.ledger = os.path.abspath(argv[1])
- self.sourcepath = os.path.abspath(argv[2])
- scriptpath = os.path.dirname(os.path.realpath(__file__))
- self.verbose = False
- self.debug = False
- self.examples = dict()
- self.testin_token = 'command'
+ def __init__(self, args):
+ scriptpath = os.path.dirname(os.path.realpath(__file__))
+ self.ledger = os.path.abspath(args.ledger)
+ self.sourcepath = os.path.abspath(args.file)
+ self.verbose = args.verbose
+
+ self.examples = dict()
+ self.test_files = list()
+ self.testin_token = 'command'
self.testout_token = 'output'
self.testdat_token = 'input'
- self.test_files = list()
def read_example(self):
endexample = re.compile(r'^@end\s+smallexample\s*$')
@@ -137,19 +131,20 @@ class DocTests:
if test_file_created:
os.remove(test_file)
valid = (output == verify)
- if self.verbose:
+ if self.verbose > 0:
print test_id, ':', 'Passed' if valid else 'FAILED'
else:
sys.stdout.write('.' if valid else 'E')
if not valid:
- if self.debug:
failed.add(test_id)
+ if self.verbose > 1:
print ' '.join(command)
for line in unified_diff(output.split('\n'), verify.split('\n'), fromfile='generated', tofile='expected'):
print(line)
print
- print
+ if not self.verbose:
+ print
if len(failed) > 0:
print "\nThe following examples failed:"
print " ", "\n ".join(failed)
@@ -164,6 +159,27 @@ class DocTests:
return failed_examples
if __name__ == "__main__":
- script = DocTests(sys.argv)
+ def getargs():
+ parser = argparse.ArgumentParser(description='DocTests', prefix_chars='-')
+ parser.add_argument('-v', '--verbose',
+ dest='verbose',
+ action='count',
+ help='be verbose. Add -vv for more verbosity')
+ 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('-f', '--file',
+ dest='file',
+ type=str,
+ action='store',
+ required=True,
+ help='the texinfo documentation file to run the examples from')
+ return parser.parse_args()
+
+ args = getargs()
+ script = DocTests(args)
status = script.main()
sys.exit(status)