D947: run-tests: move bisect logic to a separate method

quark (Jun Wu) phabricator at mercurial-scm.org
Thu Oct 5 04:22:23 UTC 2017


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This removes 8 space indentation and makes upcoming changes easier.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D947

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -2085,47 +2085,7 @@
             savetimes(self._runner._outputdir, result)
 
             if failed and self._runner.options.known_good_rev:
-                bisectcmd = ['hg', 'bisect']
-                bisectrepo = self._runner.options.bisect_repo
-                if bisectrepo:
-                    bisectcmd.extend(['-R', os.path.abspath(bisectrepo)])
-                def nooutput(args):
-                    p = subprocess.Popen(args, stderr=subprocess.STDOUT,
-                                         stdout=subprocess.PIPE)
-                    p.stdout.read()
-                    p.wait()
-                for test, msg in result.failures:
-                    nooutput(bisectcmd + ['--reset']),
-                    nooutput(bisectcmd + ['--bad', '.'])
-                    nooutput(bisectcmd + ['--good',
-                              self._runner.options.known_good_rev])
-                    # TODO: we probably need to forward more options
-                    # that alter hg's behavior inside the tests.
-                    opts = ''
-                    withhg = self._runner.options.with_hg
-                    if withhg:
-                        opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
-                    rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts,
-                                           test)
-                    sub = subprocess.Popen(bisectcmd + ['--command', rtc],
-                                           stderr=subprocess.STDOUT,
-                                           stdout=subprocess.PIPE)
-                    data = sub.stdout.read()
-                    sub.wait()
-                    m = re.search(
-                        (br'\nThe first (?P<goodbad>bad|good) revision '
-                         br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n'
-                         br'summary: +(?P<summary>[^\n]+)\n'),
-                        data, (re.MULTILINE | re.DOTALL))
-                    if m is None:
-                        self.stream.writeln(
-                            'Failed to identify failure point for %s' % test)
-                        continue
-                    dat = m.groupdict()
-                    verb = 'broken' if dat['goodbad'] == 'bad' else 'fixed'
-                    self.stream.writeln(
-                        '%s %s by %s (%s)' % (
-                            test, verb, dat['node'], dat['summary']))
+                self._bisecttests(t for t, m in result.failures)
             self.stream.writeln(
                 '# Ran %d tests, %d skipped, %d failed.'
                 % (result.testsRun, skipped + ignored, failed))
@@ -2138,6 +2098,49 @@
 
         return result
 
+    def _bisecttests(self, tests):
+        bisectcmd = ['hg', 'bisect']
+        bisectrepo = self._runner.options.bisect_repo
+        if bisectrepo:
+            bisectcmd.extend(['-R', os.path.abspath(bisectrepo)])
+        def nooutput(args):
+            p = subprocess.Popen(args, stderr=subprocess.STDOUT,
+                                 stdout=subprocess.PIPE)
+            p.stdout.read()
+            p.wait()
+        for test in tests:
+            nooutput(bisectcmd + ['--reset']),
+            nooutput(bisectcmd + ['--bad', '.'])
+            nooutput(bisectcmd + ['--good',
+                      self._runner.options.known_good_rev])
+            # TODO: we probably need to forward more options
+            # that alter hg's behavior inside the tests.
+            opts = ''
+            withhg = self._runner.options.with_hg
+            if withhg:
+                opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
+            rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts,
+                                   test)
+            sub = subprocess.Popen(bisectcmd + ['--command', rtc],
+                                   stderr=subprocess.STDOUT,
+                                   stdout=subprocess.PIPE)
+            data = sub.stdout.read()
+            sub.wait()
+            m = re.search(
+                (br'\nThe first (?P<goodbad>bad|good) revision '
+                 br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n'
+                 br'summary: +(?P<summary>[^\n]+)\n'),
+                data, (re.MULTILINE | re.DOTALL))
+            if m is None:
+                self.stream.writeln(
+                    'Failed to identify failure point for %s' % test)
+                continue
+            dat = m.groupdict()
+            verb = 'broken' if dat['goodbad'] == 'bad' else 'fixed'
+            self.stream.writeln(
+                '%s %s by %s (%s)' % (
+                    test, verb, dat['node'], dat['summary']))
+
     def printtimes(self, times):
         # iolock held by run
         self.stream.writeln('# Producing time report')



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list