tests/run-tests.py
changeset 21378 f7ac3c63d844
parent 21377 71081f7f9e52
child 21379 ab1a95270a50
equal deleted inserted replaced
21377:71081f7f9e52 21378:f7ac3c63d844
  1156                     and (t.endswith('.py') or t.endswith('.t'))]
  1156                     and (t.endswith('.py') or t.endswith('.t'))]
  1157 
  1157 
  1158     def _runtests(self, tests):
  1158     def _runtests(self, tests):
  1159         try:
  1159         try:
  1160             if self.inst:
  1160             if self.inst:
  1161                 self.installhg()
  1161                 self._installhg()
  1162                 self.checkhglib("Testing")
  1162                 self._checkhglib("Testing")
  1163             else:
  1163             else:
  1164                 self.usecorrectpython()
  1164                 self._usecorrectpython()
  1165 
  1165 
  1166             if self.options.restart:
  1166             if self.options.restart:
  1167                 orig = list(tests)
  1167                 orig = list(tests)
  1168                 while tests:
  1168                 while tests:
  1169                     if os.path.exists(tests[0] + ".err"):
  1169                     if os.path.exists(tests[0] + ".err"):
  1187                     print "Skipped %s: %s" % s
  1187                     print "Skipped %s: %s" % s
  1188             for s in self.results['~']:
  1188             for s in self.results['~']:
  1189                 print "Warned %s: %s" % s
  1189                 print "Warned %s: %s" % s
  1190             for s in self.results['!']:
  1190             for s in self.results['!']:
  1191                 print "Failed %s: %s" % s
  1191                 print "Failed %s: %s" % s
  1192             self.checkhglib("Tested")
  1192             self._checkhglib("Tested")
  1193             print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
  1193             print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
  1194                 tested, skipped + ignored, warned, failed)
  1194                 tested, skipped + ignored, warned, failed)
  1195             if self.results['!']:
  1195             if self.results['!']:
  1196                 print 'python hash seed:', os.environ['PYTHONHASHSEED']
  1196                 print 'python hash seed:', os.environ['PYTHONHASHSEED']
  1197             if self.options.time:
  1197             if self.options.time:
  1198                 self.outputtimes()
  1198                 self._outputtimes()
  1199 
  1199 
  1200             if self.options.anycoverage:
  1200             if self.options.anycoverage:
  1201                 self.outputcoverage()
  1201                 self._outputcoverage()
  1202         except KeyboardInterrupt:
  1202         except KeyboardInterrupt:
  1203             failed = True
  1203             failed = True
  1204             print "\ninterrupted!"
  1204             print "\ninterrupted!"
  1205 
  1205 
  1206         if failed:
  1206         if failed:
  1207             return 1
  1207             return 1
  1208         if warned:
  1208         if warned:
  1209             return 80
  1209             return 80
  1210 
  1210 
  1211     def gettest(self, test, count):
  1211     def _gettest(self, test, count):
  1212         """Obtain a Test by looking at its filename.
  1212         """Obtain a Test by looking at its filename.
  1213 
  1213 
  1214         Returns a Test instance. The Test may not be runnable if it doesn't
  1214         Returns a Test instance. The Test may not be runnable if it doesn't
  1215         map to a known type.
  1215         map to a known type.
  1216         """
  1216         """
  1239             try:
  1239             try:
  1240                 os.remove(f)
  1240                 os.remove(f)
  1241             except OSError:
  1241             except OSError:
  1242                 pass
  1242                 pass
  1243 
  1243 
  1244     def usecorrectpython(self):
  1244     def _usecorrectpython(self):
  1245         # Some tests run the Python interpreter. They must use the
  1245         # Some tests run the Python interpreter. They must use the
  1246         # same interpreter or bad things will happen.
  1246         # same interpreter or bad things will happen.
  1247         pyexename = sys.platform == 'win32' and 'python.exe' or 'python'
  1247         pyexename = sys.platform == 'win32' and 'python.exe' or 'python'
  1248         if getattr(os, 'symlink', None):
  1248         if getattr(os, 'symlink', None):
  1249             vlog("# Making python executable in test path a symlink to '%s'" %
  1249             vlog("# Making python executable in test path a symlink to '%s'" %
  1273                 path.remove(exedir)
  1273                 path.remove(exedir)
  1274             os.environ['PATH'] = os.pathsep.join([exedir] + path)
  1274             os.environ['PATH'] = os.pathsep.join([exedir] + path)
  1275             if not self._findprogram(pyexename):
  1275             if not self._findprogram(pyexename):
  1276                 print "WARNING: Cannot find %s in search path" % pyexename
  1276                 print "WARNING: Cannot find %s in search path" % pyexename
  1277 
  1277 
  1278     def installhg(self):
  1278     def _installhg(self):
  1279         vlog("# Performing temporary installation of HG")
  1279         vlog("# Performing temporary installation of HG")
  1280         installerrs = os.path.join("tests", "install.err")
  1280         installerrs = os.path.join("tests", "install.err")
  1281         compiler = ''
  1281         compiler = ''
  1282         if self.options.compiler:
  1282         if self.options.compiler:
  1283             compiler = '--compiler ' + self.options.compiler
  1283             compiler = '--compiler ' + self.options.compiler
  1318                 print line,
  1318                 print line,
  1319             f.close()
  1319             f.close()
  1320             sys.exit(1)
  1320             sys.exit(1)
  1321         os.chdir(self.testdir)
  1321         os.chdir(self.testdir)
  1322 
  1322 
  1323         self.usecorrectpython()
  1323         self._usecorrectpython()
  1324 
  1324 
  1325         if self.options.py3k_warnings and not self.options.anycoverage:
  1325         if self.options.py3k_warnings and not self.options.anycoverage:
  1326             vlog("# Updating hg command to enable Py3k Warnings switch")
  1326             vlog("# Updating hg command to enable Py3k Warnings switch")
  1327             f = open(os.path.join(self.bindir, 'hg'), 'r')
  1327             f = open(os.path.join(self.bindir, 'hg'), 'r')
  1328             lines = [line.rstrip() for line in f]
  1328             lines = [line.rstrip() for line in f]
  1358             vlog('# Installing coverage rc to %s' % rc)
  1358             vlog('# Installing coverage rc to %s' % rc)
  1359             os.environ['COVERAGE_PROCESS_START'] = rc
  1359             os.environ['COVERAGE_PROCESS_START'] = rc
  1360             fn = os.path.join(self.inst, '..', '.coverage')
  1360             fn = os.path.join(self.inst, '..', '.coverage')
  1361             os.environ['COVERAGE_FILE'] = fn
  1361             os.environ['COVERAGE_FILE'] = fn
  1362 
  1362 
  1363     def checkhglib(self, verb):
  1363     def _checkhglib(self, verb):
  1364         """Ensure that the 'mercurial' package imported by python is
  1364         """Ensure that the 'mercurial' package imported by python is
  1365         the one we expect it to be.  If not, print a warning to stderr."""
  1365         the one we expect it to be.  If not, print a warning to stderr."""
  1366         expecthg = os.path.join(self.pythondir, 'mercurial')
  1366         expecthg = os.path.join(self.pythondir, 'mercurial')
  1367         actualhg = _gethgpath()
  1367         actualhg = _gethgpath()
  1368         if os.path.abspath(actualhg) != os.path.abspath(expecthg):
  1368         if os.path.abspath(actualhg) != os.path.abspath(expecthg):
  1369             sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
  1369             sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
  1370                              '         (expected %s)\n'
  1370                              '         (expected %s)\n'
  1371                              % (verb, actualhg, expecthg))
  1371                              % (verb, actualhg, expecthg))
  1372 
  1372 
  1373     def outputtimes(self):
  1373     def _outputtimes(self):
  1374         vlog('# Producing time report')
  1374         vlog('# Producing time report')
  1375         self.times.sort(key=lambda t: (t[1], t[0]), reverse=True)
  1375         self.times.sort(key=lambda t: (t[1], t[0]), reverse=True)
  1376         cols = '%7.3f   %s'
  1376         cols = '%7.3f   %s'
  1377         print '\n%-7s   %s' % ('Time', 'Test')
  1377         print '\n%-7s   %s' % ('Time', 'Test')
  1378         for test, timetaken in self.times:
  1378         for test, timetaken in self.times:
  1379             print cols % (timetaken, test)
  1379             print cols % (timetaken, test)
  1380 
  1380 
  1381     def outputcoverage(self):
  1381     def _outputcoverage(self):
  1382         vlog('# Producing coverage report')
  1382         vlog('# Producing coverage report')
  1383         os.chdir(self.pythondir)
  1383         os.chdir(self.pythondir)
  1384 
  1384 
  1385         def covrun(*args):
  1385         def covrun(*args):
  1386             cmd = 'coverage %s' % ' '.join(args)
  1386             cmd = 'coverage %s' % ' '.join(args)
  1407         running = 0
  1407         running = 0
  1408         count = 0
  1408         count = 0
  1409 
  1409 
  1410         def job(test, count):
  1410         def job(test, count):
  1411             try:
  1411             try:
  1412                 t = self.gettest(test, count)
  1412                 t = self._gettest(test, count)
  1413                 done.put(t.run())
  1413                 done.put(t.run())
  1414                 t.cleanup()
  1414                 t.cleanup()
  1415             except KeyboardInterrupt:
  1415             except KeyboardInterrupt:
  1416                 pass
  1416                 pass
  1417             except: # re-raises
  1417             except: # re-raises