tests/run-tests.py
changeset 1140 689f8b6b711c
parent 1139 cdabdd17f980
child 1143 38b7bb8f1c85
equal deleted inserted replaced
1137:2d9daef1e473 1140:689f8b6b711c
   281     for existing destination support.
   281     for existing destination support.
   282     """
   282     """
   283     shutil.copy(src, dst)
   283     shutil.copy(src, dst)
   284     os.remove(src)
   284     os.remove(src)
   285 
   285 
   286 def splitnewlines(text):
       
   287     '''like str.splitlines, but only split on newlines.
       
   288     keep line endings.'''
       
   289     i = 0
       
   290     lines = []
       
   291     while True:
       
   292         n = text.find('\n', i)
       
   293         if n == -1:
       
   294             last = text[i:]
       
   295             if last:
       
   296                 lines.append(last)
       
   297             return lines
       
   298         lines.append(text[i:n + 1])
       
   299         i = n + 1
       
   300 
       
   301 def parsehghaveoutput(lines):
   286 def parsehghaveoutput(lines):
   302     '''Parse hghave log lines.
   287     '''Parse hghave log lines.
   303     Return tuple of lists (missing, failed):
   288     Return tuple of lists (missing, failed):
   304       * the missing/unknown features
   289       * the missing/unknown features
   305       * the features for which existence check failed'''
   290       * the features for which existence check failed'''
   688         lout, lcmd = l, None
   673         lout, lcmd = l, None
   689         if salt in l:
   674         if salt in l:
   690             lout, lcmd = l.split(salt, 1)
   675             lout, lcmd = l.split(salt, 1)
   691 
   676 
   692         if lout:
   677         if lout:
   693             if lcmd:
   678             if not lout.endswith('\n'):
   694                 # output block had no trailing newline, clean up
       
   695                 lout += ' (no-eol)\n'
   679                 lout += ' (no-eol)\n'
   696 
   680 
   697             # find the expected output at the current position
   681             # find the expected output at the current position
   698             el = None
   682             el = None
   699             if pos in expected and expected[pos]:
   683             if pos in expected and expected[pos]:
   760     if ret:
   744     if ret:
   761         killdaemons()
   745         killdaemons()
   762 
   746 
   763     for s, r in replacements:
   747     for s, r in replacements:
   764         output = re.sub(s, r, output)
   748         output = re.sub(s, r, output)
   765     return ret, splitnewlines(output)
   749     return ret, output.splitlines(True)
   766 
   750 
   767 def runone(options, test):
   751 def runone(options, test):
   768     '''tristate output:
   752     '''tristate output:
   769     None -> skipped
   753     None -> skipped
   770     True -> passed
   754     True -> passed
   923     # check test output against it.
   907     # check test output against it.
   924     if options.debug:
   908     if options.debug:
   925         refout = None                   # to match "out is None"
   909         refout = None                   # to match "out is None"
   926     elif os.path.exists(ref):
   910     elif os.path.exists(ref):
   927         f = open(ref, "r")
   911         f = open(ref, "r")
   928         refout = list(splitnewlines(f.read()))
   912         refout = f.read().splitlines(True)
   929         f.close()
   913         f.close()
   930     else:
   914     else:
   931         refout = []
   915         refout = []
   932 
   916 
   933     if (ret != 0 or out != refout) and not skipped and not options.debug:
   917     if (ret != 0 or out != refout) and not skipped and not options.debug: