tests/run-tests.py
branchstable
changeset 1003 59bd7f017103
parent 1002 9a8202faebb3
child 1005 d86b26020b48
equal deleted inserted replaced
1002:9a8202faebb3 1003:59bd7f017103
   557          el.endswith(" (esc)\n") and el.decode('string-escape') == l)):
   557          el.endswith(" (esc)\n") and el.decode('string-escape') == l)):
   558         return True
   558         return True
   559     return False
   559     return False
   560 
   560 
   561 def tsttest(test, wd, options, replacements):
   561 def tsttest(test, wd, options, replacements):
   562     t = open(test)
       
   563     out = []
       
   564     script = []
       
   565 
       
   566     # We generate a shell script which outputs unique markers to line
   562     # We generate a shell script which outputs unique markers to line
   567     # up script results with our source. These markers include input
   563     # up script results with our source. These markers include input
   568     # line number and the last return code
   564     # line number and the last return code
   569     salt = "SALT" + str(time.time())
   565     salt = "SALT" + str(time.time())
   570     def addsalt(line):
   566     def addsalt(line):
   582 
   578 
   583     # We keep track of whether or not we're in a Python block so we
   579     # We keep track of whether or not we're in a Python block so we
   584     # can generate the surrounding doctest magic
   580     # can generate the surrounding doctest magic
   585     inpython = False
   581     inpython = False
   586 
   582 
       
   583     f = open(test)
       
   584     t = f.readlines()
       
   585     f.close()
       
   586 
       
   587     script = []
   587     for n, l in enumerate(t):
   588     for n, l in enumerate(t):
   588         if not l.endswith('\n'):
   589         if not l.endswith('\n'):
   589             l += '\n'
   590             l += '\n'
   590         if l.startswith('  >>> '): # python inlines
   591         if l.startswith('  >>> '): # python inlines
   591             if not inpython:
   592             if not inpython:
   621                 script.append("EOF\n")
   622                 script.append("EOF\n")
   622                 inpython = False
   623                 inpython = False
   623             # non-command/result - queue up for merged output
   624             # non-command/result - queue up for merged output
   624             after.setdefault(pos, []).append(l)
   625             after.setdefault(pos, []).append(l)
   625 
   626 
   626     t.close()
       
   627 
       
   628     if inpython:
   627     if inpython:
   629         script.append("EOF\n")
   628         script.append("EOF\n")
   630     addsalt(n + 1)
   629     addsalt(n + 1)
   631 
   630 
       
   631     # Write out the script and execute it
   632     fd, name = tempfile.mkstemp(suffix='hg-tst')
   632     fd, name = tempfile.mkstemp(suffix='hg-tst')
   633     try:
   633     try:
   634         for l in script:
   634         for l in script:
   635             os.write(fd, l)
   635             os.write(fd, l)
   636         os.close(fd)
   636         os.close(fd)