tests/heredoctest.py
branchstable
changeset 1110 d5b3404b82ce
parent 1109 8458561f6f94
equal deleted inserted replaced
1109:8458561f6f94 1110:d5b3404b82ce
     1 import doctest, tempfile, os, sys
     1 import sys
     2 
     2 
     3 if __name__ == "__main__":
     3 globalvars = {}
     4     if 'TERM' in os.environ:
     4 localvars = {}
     5         del os.environ['TERM']
     5 lines = sys.stdin.readlines()
     6 
     6 while lines:
     7     fd, name = tempfile.mkstemp(suffix='hg-tst')
     7     l = lines.pop(0)
     8 
     8     if l.startswith('SALT'):
     9     try:
     9         print l[:-1]
    10         os.write(fd, sys.stdin.read())
    10     elif l.startswith('>>> '):
    11         os.close(fd)
    11         snippet = l[4:]
    12         failures, _ = doctest.testfile(name, module_relative=False)
    12         while lines and lines[0].startswith('... '):
    13         if failures:
    13             l = lines.pop(0)
    14             sys.exit(1)
    14             snippet += "\n" + l[4:]
    15     finally:
    15         c = compile(snippet, '<heredoc>', 'single')
    16         os.remove(name)
    16         try:
       
    17             exec c in globalvars, localvars
       
    18         except Exception, inst:
       
    19             print repr(inst)