tests/run-tests.py
branchstable
changeset 1086 a2e8ccb65224
parent 1085 a2e7456b162e
child 1088 e2d5315a6e38
equal deleted inserted replaced
1085:a2e7456b162e 1086:a2e8ccb65224
   592 
   592 
   593     # We keep track of whether or not we're in a Python block so we
   593     # We keep track of whether or not we're in a Python block so we
   594     # can generate the surrounding doctest magic
   594     # can generate the surrounding doctest magic
   595     inpython = False
   595     inpython = False
   596 
   596 
       
   597     # True or False when in a true or false conditional section
       
   598     skipping = None
       
   599 
       
   600     def hghave(reqs):
       
   601         # TODO: do something smarter when all other uses of hghave is gone
       
   602         proc = Popen4('%s -c "%s/hghave %s"' %
       
   603                       (options.shell, TESTDIR, ' '.join(reqs)), TESTDIR, 0)
       
   604         proc.communicate()
       
   605         ret = proc.wait()
       
   606         if wifexited(ret):
       
   607             ret = os.WEXITSTATUS(ret)
       
   608         return ret == 0
       
   609 
   597     f = open(test)
   610     f = open(test)
   598     t = f.readlines()
   611     t = f.readlines()
   599     f.close()
   612     f.close()
   600 
   613 
   601     script = []
   614     script = []
   604     if os.getenv('MSYSTEM'):
   617     if os.getenv('MSYSTEM'):
   605         script.append('alias pwd="pwd -W"\n')
   618         script.append('alias pwd="pwd -W"\n')
   606     for n, l in enumerate(t):
   619     for n, l in enumerate(t):
   607         if not l.endswith('\n'):
   620         if not l.endswith('\n'):
   608             l += '\n'
   621             l += '\n'
   609         if l.startswith('  >>> '): # python inlines
   622         if l.startswith('#if'):
       
   623             if skipping is not None:
       
   624                 after.setdefault(pos, []).append('  !!! nested #if\n')
       
   625             skipping = not hghave(l.split()[1:])
       
   626             after.setdefault(pos, []).append(l)
       
   627         elif l.startswith('#else'):
       
   628             if skipping is None:
       
   629                 after.setdefault(pos, []).append('  !!! missing #if\n')
       
   630             skipping = not skipping
       
   631             after.setdefault(pos, []).append(l)
       
   632         elif l.startswith('#endif'):
       
   633             if skipping is None:
       
   634                 after.setdefault(pos, []).append('  !!! missing #if\n')
       
   635             skipping = None
       
   636             after.setdefault(pos, []).append(l)
       
   637         elif skipping:
       
   638             after.setdefault(pos, []).append(l)
       
   639         elif l.startswith('  >>> '): # python inlines
   610             after.setdefault(pos, []).append(l)
   640             after.setdefault(pos, []).append(l)
   611             prepos = pos
   641             prepos = pos
   612             pos = n
   642             pos = n
   613             if not inpython:
   643             if not inpython:
   614                 # we've just entered a Python block, add the header
   644                 # we've just entered a Python block, add the header
   642             # non-command/result - queue up for merged output
   672             # non-command/result - queue up for merged output
   643             after.setdefault(pos, []).append(l)
   673             after.setdefault(pos, []).append(l)
   644 
   674 
   645     if inpython:
   675     if inpython:
   646         script.append("EOF\n")
   676         script.append("EOF\n")
       
   677     if skipping is not None:
       
   678         after.setdefault(pos, []).append('  !!! missing #endif\n')
   647     addsalt(n + 1, False)
   679     addsalt(n + 1, False)
   648 
   680 
   649     # Write out the script and execute it
   681     # Write out the script and execute it
   650     fd, name = tempfile.mkstemp(suffix='hg-tst')
   682     fd, name = tempfile.mkstemp(suffix='hg-tst')
   651     try:
   683     try: