tests/run-tests.py
changeset 14000 636a6f5aa2cd
parent 13999 8f9478be9a94
child 14001 9c4da6ab4e5a
equal deleted inserted replaced
13999:8f9478be9a94 14000:636a6f5aa2cd
    51 import signal
    51 import signal
    52 import sys
    52 import sys
    53 import tempfile
    53 import tempfile
    54 import time
    54 import time
    55 import re
    55 import re
       
    56 import threading
    56 
    57 
    57 closefds = os.name == 'posix'
    58 closefds = os.name == 'posix'
    58 def Popen4(cmd, bufsize=-1):
    59 def Popen4(cmd, bufsize=-1):
    59     p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
    60     p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
    60                          close_fds=closefds,
    61                          close_fds=closefds,
   631 
   632 
   632     for s, r in replacements:
   633     for s, r in replacements:
   633         output = re.sub(s, r, output)
   634         output = re.sub(s, r, output)
   634     return ret, splitnewlines(output)
   635     return ret, splitnewlines(output)
   635 
   636 
   636 def runone(options, test, results):
   637 def runone(options, test):
   637     '''tristate output:
   638     '''tristate output:
   638     None -> skipped
   639     None -> skipped
   639     True -> passed
   640     True -> passed
   640     False -> failed'''
   641     False -> failed'''
   641 
   642 
       
   643     global results, resultslock
       
   644 
   642     testpath = os.path.join(TESTDIR, test)
   645     testpath = os.path.join(TESTDIR, test)
       
   646 
       
   647     def result(l, e):
       
   648         resultslock.acquire()
       
   649         results[l].append(e)
       
   650         resultslock.release()
   643 
   651 
   644     def skip(msg):
   652     def skip(msg):
   645         if not options.verbose:
   653         if not options.verbose:
   646             results['s'].append((test, msg))
   654             result('s', (test, msg))
   647         else:
   655         else:
   648             print "\nSkipping %s: %s" % (testpath, msg)
   656             print "\nSkipping %s: %s" % (testpath, msg)
   649         return None
   657         return None
   650 
   658 
   651     def fail(msg, ret):
   659     def fail(msg, ret):
   659                 if test.endswith(".t"):
   667                 if test.endswith(".t"):
   660                     rename(testpath + ".err", testpath)
   668                     rename(testpath + ".err", testpath)
   661                 else:
   669                 else:
   662                     rename(testpath + ".err", testpath + ".out")
   670                     rename(testpath + ".err", testpath + ".out")
   663                 return
   671                 return
   664         results['f'].append((test, msg))
   672         result('f', (test, msg))
   665 
   673 
   666     def success():
   674     def success():
   667         results['p'].append(test)
   675         result('p', test)
   668 
   676 
   669     def ignore(msg):
   677     def ignore(msg):
   670         results['i'].append((test, msg))
   678         result('i', (test, msg))
   671 
   679 
   672     if (test.startswith("test-") and '~' not in test and
   680     if (test.startswith("test-") and '~' not in test and
   673         ('.' not in test or test.endswith('.py') or
   681         ('.' not in test or test.endswith('.py') or
   674          test.endswith('.bat') or test.endswith('.t'))):
   682          test.endswith('.bat') or test.endswith('.t'))):
   675         if not os.path.exists(test):
   683         if not os.path.exists(test):
   679         return None # not a supported test, don't record
   687         return None # not a supported test, don't record
   680 
   688 
   681     if options.blacklist:
   689     if options.blacklist:
   682         filename = options.blacklist.get(test)
   690         filename = options.blacklist.get(test)
   683         if filename is not None:
   691         if filename is not None:
   684             skipped.append((test, "blacklisted (%s)" % filename))
   692             skip("blacklisted")
   685             return None
   693             return None
   686 
   694 
   687     if options.retest and not os.path.exists(test + ".err"):
   695     if options.retest and not os.path.exists(test + ".err"):
   688         ignore("not retesting")
   696         ignore("not retesting")
   689         return None
   697         return None
   933 
   941 
   934     if options.anycoverage:
   942     if options.anycoverage:
   935         outputcoverage(options)
   943         outputcoverage(options)
   936     sys.exit(failures != 0)
   944     sys.exit(failures != 0)
   937 
   945 
       
   946 results = dict(p=[], f=[], s=[], i=[])
       
   947 resultslock = threading.Lock()
       
   948 
   938 def runqueue(options, tests, results):
   949 def runqueue(options, tests, results):
   939     for test in tests:
   950     for test in tests:
   940         ret = runone(options, test, results)
   951         ret = runone(options, test)
   941         if options.first and ret is not None and not ret:
   952         if options.first and ret is not None and not ret:
   942             break
   953             break
   943 
   954 
   944 def runtests(options, tests):
   955 def runtests(options, tests):
   945     global DAEMON_PIDS, HGRCPATH
   956     global DAEMON_PIDS, HGRCPATH
   946     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
   957     DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
   947     HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
   958     HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
   948 
       
   949     results = dict(p=[], f=[], s=[], i=[])
       
   950 
   959 
   951     try:
   960     try:
   952         if INST:
   961         if INST:
   953             installhg(options)
   962             installhg(options)
   954             _checkhglib("Testing")
   963             _checkhglib("Testing")