tests/run-tests.py
branchstable
changeset 1236 b1062bc760a9
parent 1235 8fd26ac1deca
child 1237 ac098555f410
equal deleted inserted replaced
1235:8fd26ac1deca 1236:b1062bc760a9
   823     for s, r in replacements:
   823     for s, r in replacements:
   824         output = re.sub(s, r, output)
   824         output = re.sub(s, r, output)
   825     return ret, output.splitlines(True)
   825     return ret, output.splitlines(True)
   826 
   826 
   827 def runone(options, test):
   827 def runone(options, test):
   828     '''tristate output:
   828     '''returns a result element: (code, test, msg)'''
   829     None -> skipped
   829 
   830     True -> passed
   830     global iolock
   831     False -> failed'''
       
   832 
       
   833     global results, resultslock, iolock
       
   834 
       
   835     def result(l, e):
       
   836         resultslock.acquire()
       
   837         results[l].append(e)
       
   838         resultslock.release()
       
   839 
   831 
   840     def skip(msg):
   832     def skip(msg):
   841         if not options.verbose:
   833         if options.verbose:
   842             result('s', (test, msg))
       
   843         else:
       
   844             iolock.acquire()
   834             iolock.acquire()
   845             print "\nSkipping %s: %s" % (testpath, msg)
   835             print "\nSkipping %s: %s" % (testpath, msg)
   846             iolock.release()
   836             iolock.release()
   847         return None
   837         return 's', test, msg
   848 
   838 
   849     def fail(msg, ret):
   839     def fail(msg, ret):
   850         if not options.nodiff:
   840         if not options.nodiff:
   851             iolock.acquire()
   841             iolock.acquire()
   852             print "\nERROR: %s %s" % (testpath, msg)
   842             print "\nERROR: %s %s" % (testpath, msg)
   860             if answer.lower() in "y yes".split():
   850             if answer.lower() in "y yes".split():
   861                 if test.endswith(".t"):
   851                 if test.endswith(".t"):
   862                     rename(testpath + ".err", testpath)
   852                     rename(testpath + ".err", testpath)
   863                 else:
   853                 else:
   864                     rename(testpath + ".err", testpath + ".out")
   854                     rename(testpath + ".err", testpath + ".out")
   865                 result('p', test)
   855                 return 'p', test, ''
   866                 return
   856         return 'f', test, msg
   867         result('f', (test, msg))
       
   868 
   857 
   869     def success():
   858     def success():
   870         result('p', test)
   859         return 'p', test, ''
   871 
   860 
   872     def ignore(msg):
   861     def ignore(msg):
   873         result('i', (test, msg))
   862         return 'i', test, msg
   874 
   863 
   875     def describe(ret):
   864     def describe(ret):
   876         if ret < 0:
   865         if ret < 0:
   877             return 'killed by signal %d' % -ret
   866             return 'killed by signal %d' % -ret
   878         return 'returned error code %d' % ret
   867         return 'returned error code %d' % ret
   880     testpath = os.path.join(TESTDIR, test)
   869     testpath = os.path.join(TESTDIR, test)
   881     err = os.path.join(TESTDIR, test + ".err")
   870     err = os.path.join(TESTDIR, test + ".err")
   882     lctest = test.lower()
   871     lctest = test.lower()
   883 
   872 
   884     if not os.path.exists(testpath):
   873     if not os.path.exists(testpath):
   885             skip("doesn't exist")
   874             return skip("doesn't exist")
   886             return None
       
   887 
   875 
   888     if not (options.whitelisted and test in options.whitelisted):
   876     if not (options.whitelisted and test in options.whitelisted):
   889         if options.blacklist and test in options.blacklist:
   877         if options.blacklist and test in options.blacklist:
   890             skip("blacklisted")
   878             return skip("blacklisted")
   891             return None
       
   892 
   879 
   893         if options.retest and not os.path.exists(test + ".err"):
   880         if options.retest and not os.path.exists(test + ".err"):
   894             ignore("not retesting")
   881             ignore("not retesting")
   895             return None
   882             return None
   896 
   883 
   980         else:
   967         else:
   981             missing, failed = parsehghaveoutput(out)
   968             missing, failed = parsehghaveoutput(out)
   982         if not missing:
   969         if not missing:
   983             missing = ['irrelevant']
   970             missing = ['irrelevant']
   984         if failed:
   971         if failed:
   985             fail("hghave failed checking for %s" % failed[-1], ret)
   972             result = fail("hghave failed checking for %s" % failed[-1], ret)
   986             skipped = False
   973             skipped = False
   987         else:
   974         else:
   988             skip(missing[-1])
   975             result = skip(missing[-1])
   989     elif ret == 'timeout':
   976     elif ret == 'timeout':
   990         mark = 't'
   977         mark = 't'
   991         fail("timed out", ret)
   978         result = fail("timed out", ret)
   992     elif out != refout:
   979     elif out != refout:
   993         mark = '!'
   980         mark = '!'
   994         if not options.nodiff:
   981         if not options.nodiff:
   995             iolock.acquire()
   982             iolock.acquire()
   996             if options.view:
   983             if options.view:
   997                 os.system("%s %s %s" % (options.view, ref, err))
   984                 os.system("%s %s %s" % (options.view, ref, err))
   998             else:
   985             else:
   999                 showdiff(refout, out, ref, err)
   986                 showdiff(refout, out, ref, err)
  1000             iolock.release()
   987             iolock.release()
  1001         if ret:
   988         if ret:
  1002             fail("output changed and " + describe(ret), ret)
   989             result = fail("output changed and " + describe(ret), ret)
  1003         else:
   990         else:
  1004             fail("output changed", ret)
   991             result = fail("output changed", ret)
  1005         ret = 1
       
  1006     elif ret:
   992     elif ret:
  1007         mark = '!'
   993         mark = '!'
  1008         fail(describe(ret), ret)
   994         result = fail(describe(ret), ret)
  1009     else:
   995     else:
  1010         success()
   996         result = success()
  1011 
   997 
  1012     if not options.verbose:
   998     if not options.verbose:
  1013         iolock.acquire()
   999         iolock.acquire()
  1014         sys.stdout.write(mark)
  1000         sys.stdout.write(mark)
  1015         sys.stdout.flush()
  1001         sys.stdout.flush()
  1016         iolock.release()
  1002         iolock.release()
  1017 
  1003 
  1018     if not options.keep_tmpdir:
  1004     if not options.keep_tmpdir:
  1019         shutil.rmtree(testtmp, True)
  1005         shutil.rmtree(testtmp, True)
  1020     if skipped:
  1006     return result
  1021         return None
       
  1022     return ret == 0
       
  1023 
  1007 
  1024 _hgpath = None
  1008 _hgpath = None
  1025 
  1009 
  1026 def _gethgpath():
  1010 def _gethgpath():
  1027     """Return the path to the mercurial package that is actually found by
  1011     """Return the path to the mercurial package that is actually found by
  1167 resultslock = threading.Lock()
  1151 resultslock = threading.Lock()
  1168 times = []
  1152 times = []
  1169 iolock = threading.Lock()
  1153 iolock = threading.Lock()
  1170 
  1154 
  1171 def runqueue(options, tests):
  1155 def runqueue(options, tests):
       
  1156     global results, resultslock
       
  1157 
  1172     for test in tests:
  1158     for test in tests:
  1173         ret = runone(options, test)
  1159         code, test, msg = runone(options, test)
  1174         if options.first and ret is not None and not ret:
  1160         resultslock.acquire()
       
  1161         results[code].append((test, msg))
       
  1162         resultslock.release()
       
  1163 
       
  1164         if options.first and code not in '.si':
  1175             break
  1165             break
  1176 
  1166 
  1177 def runtests(options, tests):
  1167 def runtests(options, tests):
  1178     global DAEMON_PIDS, HGRCPATH
  1168     global DAEMON_PIDS, HGRCPATH
  1179     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
  1169     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')