tests/run-tests.py
changeset 32704 1270b00a385d
parent 32703 9d1d3199382e
child 32711 04c19c808241
equal deleted inserted replaced
32703:9d1d3199382e 32704:1270b00a385d
   261              " (default: $%s or %d)" % defaults['jobs'])
   261              " (default: $%s or %d)" % defaults['jobs'])
   262     parser.add_option("--keep-tmpdir", action="store_true",
   262     parser.add_option("--keep-tmpdir", action="store_true",
   263         help="keep temporary directory after running tests")
   263         help="keep temporary directory after running tests")
   264     parser.add_option("-k", "--keywords",
   264     parser.add_option("-k", "--keywords",
   265         help="run tests matching keywords")
   265         help="run tests matching keywords")
       
   266     parser.add_option("--list-tests", action="store_true",
       
   267         help="list tests instead of running them")
   266     parser.add_option("-l", "--local", action="store_true",
   268     parser.add_option("-l", "--local", action="store_true",
   267         help="shortcut for --with-hg=<testdir>/../hg, "
   269         help="shortcut for --with-hg=<testdir>/../hg, "
   268              "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
   270              "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
   269     parser.add_option("--loop", action="store_true",
   271     parser.add_option("--loop", action="store_true",
   270         help="loop tests repeatedly")
   272         help="loop tests repeatedly")
  1905     def __init__(self, runner, *args, **kwargs):
  1907     def __init__(self, runner, *args, **kwargs):
  1906         super(TextTestRunner, self).__init__(*args, **kwargs)
  1908         super(TextTestRunner, self).__init__(*args, **kwargs)
  1907 
  1909 
  1908         self._runner = runner
  1910         self._runner = runner
  1909 
  1911 
       
  1912     def listtests(self, test):
       
  1913         result = TestResult(self._runner.options, self.stream,
       
  1914                             self.descriptions, 0)
       
  1915         test = sorted(test, key=lambda t: t.name)
       
  1916         for t in test:
       
  1917             print(t.name)
       
  1918             result.addSuccess(t)
       
  1919 
       
  1920         if self._runner.options.xunit:
       
  1921             with open(self._runner.options.xunit, "wb") as xuf:
       
  1922                 self._writexunit(result, xuf)
       
  1923 
       
  1924         if self._runner.options.json:
       
  1925             jsonpath = os.path.join(self._runner._testdir, b'report.json')
       
  1926             with open(jsonpath, 'w') as fp:
       
  1927                 self._writejson(result, fp)
       
  1928 
       
  1929         return result
       
  1930 
  1910     def run(self, test):
  1931     def run(self, test):
  1911         result = TestResult(self._runner.options, self.stream,
  1932         result = TestResult(self._runner.options, self.stream,
  1912                             self.descriptions, self.verbosity)
  1933                             self.descriptions, self.verbosity)
  1913 
  1934 
  1914         test(result)
  1935         test(result)
  2382             verbosity = 1
  2403             verbosity = 1
  2383             if self.options.verbose:
  2404             if self.options.verbose:
  2384                 verbosity = 2
  2405                 verbosity = 2
  2385             runner = TextTestRunner(self, verbosity=verbosity)
  2406             runner = TextTestRunner(self, verbosity=verbosity)
  2386 
  2407 
  2387             if self._installdir:
  2408             if self.options.list_tests:
  2388                 self._installhg()
  2409                 result = runner.listtests(suite)
  2389                 self._checkhglib("Testing")
       
  2390             else:
  2410             else:
  2391                 self._usecorrectpython()
  2411                 if self._installdir:
  2392             if self.options.chg:
  2412                     self._installhg()
  2393                 assert self._installdir
  2413                     self._checkhglib("Testing")
  2394                 self._installchg()
  2414                 else:
  2395 
  2415                     self._usecorrectpython()
  2396             result = runner.run(suite)
  2416                 if self.options.chg:
       
  2417                     assert self._installdir
       
  2418                     self._installchg()
       
  2419 
       
  2420                 result = runner.run(suite)
  2397 
  2421 
  2398             if result.failures:
  2422             if result.failures:
  2399                 failed = True
  2423                 failed = True
  2400             if result.warned:
  2424             if result.warned:
  2401                 warned = True
  2425                 warned = True