tests/run-tests.py
branchstable
changeset 1252 e9ad07011f87
parent 1251 5dfbf34da361
child 1253 79e201b6826a
equal deleted inserted replaced
1251:5dfbf34da361 1252:e9ad07011f87
   360             assert '=' in key, ('extra config opt %s must '
   360             assert '=' in key, ('extra config opt %s must '
   361                                 'have an = for assignment' % opt)
   361                                 'have an = for assignment' % opt)
   362             hgrc.write('[%s]\n%s\n' % (section, key))
   362             hgrc.write('[%s]\n%s\n' % (section, key))
   363     hgrc.close()
   363     hgrc.close()
   364 
   364 
   365 def createenv(options, testtmp):
   365 def createenv(options, testtmp, threadtmp):
   366     env = os.environ.copy()
   366     env = os.environ.copy()
   367     env['TESTTMP'] = testtmp
   367     env['TESTTMP'] = testtmp
   368     env['HOME'] = testtmp
   368     env['HOME'] = testtmp
   369     env["HGPORT"] = str(options.port)
   369     env["HGPORT"] = str(options.port)
   370     env["HGPORT1"] = str(options.port + 1)
   370     env["HGPORT1"] = str(options.port + 1)
   371     env["HGPORT2"] = str(options.port + 2)
   371     env["HGPORT2"] = str(options.port + 2)
   372     env["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
   372     env["HGRCPATH"] = os.path.join(threadtmp, '.hgrc')
   373     env["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
   373     env["DAEMON_PIDS"] = os.path.join(threadtmp, 'daemon.pids')
   374     env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
   374     env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
   375     env["HGMERGE"] = "internal:merge"
   375     env["HGMERGE"] = "internal:merge"
   376     env["HGUSER"]   = "test"
   376     env["HGUSER"]   = "test"
   377     env["HGENCODING"] = "ascii"
   377     env["HGENCODING"] = "ascii"
   378     env["HGENCODINGMODE"] = "strict"
   378     env["HGENCODINGMODE"] = "strict"
   868 
   868 
   869     for s, r in replacements:
   869     for s, r in replacements:
   870         output = re.sub(s, r, output)
   870         output = re.sub(s, r, output)
   871     return ret, output.splitlines(True)
   871     return ret, output.splitlines(True)
   872 
   872 
   873 def runone(options, test):
   873 def runone(options, test, count):
   874     '''returns a result element: (code, test, msg)'''
   874     '''returns a result element: (code, test, msg)'''
   875 
   875 
   876     def skip(msg):
   876     def skip(msg):
   877         if options.verbose:
   877         if options.verbose:
   878             log("\nSkipping %s: %s" % (testpath, msg))
   878             log("\nSkipping %s: %s" % (testpath, msg))
   944 
   944 
   945     if os.path.exists(err):
   945     if os.path.exists(err):
   946         os.remove(err)       # Remove any previous output files
   946         os.remove(err)       # Remove any previous output files
   947 
   947 
   948     # Make a tmp subdirectory to work in
   948     # Make a tmp subdirectory to work in
   949     testtmp = os.path.join(HGTMP, os.path.basename(test))
   949     threadtmp = os.path.join(HGTMP, "child%d" % count)
       
   950     testtmp = os.path.join(threadtmp, os.path.basename(test))
       
   951     os.mkdir(threadtmp)
   950     os.mkdir(testtmp)
   952     os.mkdir(testtmp)
   951 
   953 
   952     replacements = [
   954     replacements = [
   953         (r':%s\b' % options.port, ':$HGPORT'),
   955         (r':%s\b' % options.port, ':$HGPORT'),
   954         (r':%s\b' % (options.port + 1), ':$HGPORT1'),
   956         (r':%s\b' % (options.port + 1), ':$HGPORT1'),
   962                      '\\' + c
   964                      '\\' + c
   963                      for c in testtmp), '$TESTTMP'))
   965                      for c in testtmp), '$TESTTMP'))
   964     else:
   966     else:
   965         replacements.append((re.escape(testtmp), '$TESTTMP'))
   967         replacements.append((re.escape(testtmp), '$TESTTMP'))
   966 
   968 
   967     env = createenv(options, testtmp)
   969     env = createenv(options, testtmp, threadtmp)
   968     createhgrc(env['HGRCPATH'], options)
   970     createhgrc(env['HGRCPATH'], options)
   969 
   971 
   970     if options.time:
   972     if options.time:
   971         starttime = time.time()
   973         starttime = time.time()
   972     ret, out = runner(testpath, testtmp, options, replacements, env)
   974     ret, out = runner(testpath, testtmp, options, replacements, env)
  1034         sys.stdout.write(result[0])
  1036         sys.stdout.write(result[0])
  1035         sys.stdout.flush()
  1037         sys.stdout.flush()
  1036         iolock.release()
  1038         iolock.release()
  1037 
  1039 
  1038     if not options.keep_tmpdir:
  1040     if not options.keep_tmpdir:
  1039         shutil.rmtree(testtmp, True)
  1041         shutil.rmtree(threadtmp, True)
  1040     return result
  1042     return result
  1041 
  1043 
  1042 _hgpath = None
  1044 _hgpath = None
  1043 
  1045 
  1044 def _gethgpath():
  1046 def _gethgpath():
  1187 iolock = threading.Lock()
  1189 iolock = threading.Lock()
  1188 abort = False
  1190 abort = False
  1189 
  1191 
  1190 def runqueue(options, tests):
  1192 def runqueue(options, tests):
  1191     for test in tests:
  1193     for test in tests:
  1192         code, test, msg = runone(options, test)
  1194         code, test, msg = runone(options, test, 0)
  1193         resultslock.acquire()
  1195         resultslock.acquire()
  1194         results[code].append((test, msg))
  1196         results[code].append((test, msg))
  1195         resultslock.release()
  1197         resultslock.release()
  1196 
  1198 
  1197         if options.first and code not in '.si':
  1199         if options.first and code not in '.si':