tests/run-tests.py
changeset 2709 e475fe2a6029
parent 2705 030d0abdf91b
child 2975 3091b1153e2c
equal deleted inserted replaced
2708:58913ed8f7f5 2709:e475fe2a6029
   199             if ret == 0:
   199             if ret == 0:
   200                 ret = signal.SIGTERM << 8
   200                 ret = signal.SIGTERM << 8
   201     return ret, splitnewlines(output)
   201     return ret, splitnewlines(output)
   202 
   202 
   203 def run_one(test):
   203 def run_one(test):
       
   204     '''tristate output:
       
   205     None -> skipped
       
   206     True -> passed
       
   207     False -> failed'''
       
   208 
   204     vlog("# Test", test)
   209     vlog("# Test", test)
   205     if not verbose:
   210     if not verbose:
   206         sys.stdout.write('.')
   211         sys.stdout.write('.')
   207         sys.stdout.flush()
   212         sys.stdout.flush()
   208 
   213 
   215     # Make a tmp subdirectory to work in
   220     # Make a tmp subdirectory to work in
   216     tmpd = os.path.join(HGTMP, test)
   221     tmpd = os.path.join(HGTMP, test)
   217     os.mkdir(tmpd)
   222     os.mkdir(tmpd)
   218     os.chdir(tmpd)
   223     os.chdir(tmpd)
   219 
   224 
   220     if test.endswith(".py"):
   225     lctest = test.lower()
       
   226 
       
   227     if lctest.endswith('.py'):
   221         cmd = '%s "%s"' % (sys.executable, os.path.join(TESTDIR, test))
   228         cmd = '%s "%s"' % (sys.executable, os.path.join(TESTDIR, test))
       
   229     elif lctest.endswith('.bat'):
       
   230         # do not run batch scripts on non-windows
       
   231         if os.name != 'nt':
       
   232             print '\nSkipping %s: batch script' % test
       
   233             return None
       
   234         # To reliably get the error code from batch files on WinXP,
       
   235         # the "cmd /c call" prefix is needed. Grrr
       
   236         cmd = 'cmd /c call "%s"' % (os.path.join(TESTDIR, test))
   222     else:
   237     else:
       
   238         # do not run shell scripts on windows
       
   239         if os.name == 'nt':
       
   240             print '\nSkipping %s: shell script' % test
       
   241             return None
       
   242         # do not try to run non-executable programs
       
   243         if not os.access(os.path.join(TESTDIR, test), os.X_OK):
       
   244             print '\nSkipping %s: not executable' % test
       
   245             return None
   223         cmd = '"%s"' % (os.path.join(TESTDIR, test))
   246         cmd = '"%s"' % (os.path.join(TESTDIR, test))
   224 
       
   225     # To reliably get the error code from batch files on WinXP,
       
   226     # the "cmd /c call" prefix is needed. Grrr
       
   227     if os.name == 'nt' and test.endswith(".bat"):
       
   228         cmd = 'cmd /c call "%s"' % (os.path.join(TESTDIR, test))
       
   229 
   247 
   230     if options.timeout > 0:
   248     if options.timeout > 0:
   231         signal.alarm(options.timeout)
   249         signal.alarm(options.timeout)
   232 
   250 
   233     vlog("# Running", cmd)
   251     vlog("# Running", cmd)
   328                 print 'WARNING: cannot run tests with timeouts'
   346                 print 'WARNING: cannot run tests with timeouts'
   329                 options.timeout = 0
   347                 options.timeout = 0
   330 
   348 
   331         tests = 0
   349         tests = 0
   332         failed = 0
   350         failed = 0
       
   351         skipped = 0
   333 
   352 
   334         if len(args) == 0:
   353         if len(args) == 0:
   335             args = os.listdir(".")
   354             args = os.listdir(".")
   336         for test in args:
   355         for test in args:
   337             if (test.startswith("test-") and '~' not in test and
   356             if (test.startswith("test-") and '~' not in test and
   338                 ('.' not in test or test.endswith('.py') or 
   357                 ('.' not in test or test.endswith('.py') or 
   339                  test.endswith('.bat'))):
   358                  test.endswith('.bat'))):
   340                 if not run_one(test):
   359                 ret = run_one(test)
       
   360                 if ret is None:
       
   361                     skipped += 1
       
   362                 elif not ret:
   341                     failed += 1
   363                     failed += 1
   342                 tests += 1
   364                 tests += 1
   343 
   365 
   344         print "\n# Ran %d tests, %d failed." % (tests, failed)
   366         print "\n# Ran %d tests, %d skipped, %d failed." % (tests, skipped,
       
   367                                                             failed)
   345         if coverage:
   368         if coverage:
   346             output_coverage()
   369             output_coverage()
   347     except KeyboardInterrupt:
   370     except KeyboardInterrupt:
   348         failed = True
   371         failed = True
   349         print "\ninterrupted!"
   372         print "\ninterrupted!"