# HG changeset patch # User Matt Mackall # Date 1320695201 21600 # Node ID d5b3404b82cea4a6e7defebdee79abe7d654c8eb # Parent 8458561f6f94d80472fb760cc01cf90112181058 run-tests: replace inline python handling with more native scheme Normally changes in tests are reported like this in diffs: $ cat foo - a + b Using -i mode lets us update tests when the new results are correct and/or populate tests with their output. But with the standard doctest framework, inline Python sections in tests changes instead result in a big failure report that's unhelpful. So here, we replace the doctest calls with a simple compile/eval loop. [ original upstream message - missed change to heredoctest ] diff -r 8458561f6f94 -r d5b3404b82ce tests/heredoctest.py --- a/tests/heredoctest.py Tue Nov 01 12:25:54 2011 -0700 +++ b/tests/heredoctest.py Mon Nov 07 13:46:41 2011 -0600 @@ -1,16 +1,19 @@ -import doctest, tempfile, os, sys - -if __name__ == "__main__": - if 'TERM' in os.environ: - del os.environ['TERM'] - - fd, name = tempfile.mkstemp(suffix='hg-tst') +import sys - try: - os.write(fd, sys.stdin.read()) - os.close(fd) - failures, _ = doctest.testfile(name, module_relative=False) - if failures: - sys.exit(1) - finally: - os.remove(name) +globalvars = {} +localvars = {} +lines = sys.stdin.readlines() +while lines: + l = lines.pop(0) + if l.startswith('SALT'): + print l[:-1] + elif l.startswith('>>> '): + snippet = l[4:] + while lines and lines[0].startswith('... '): + l = lines.pop(0) + snippet += "\n" + l[4:] + c = compile(snippet, '', 'single') + try: + exec c in globalvars, localvars + except Exception, inst: + print repr(inst)