comparison tests/run-tests.py @ 34803:d817bf1fc675

run-tests: extract Popen logic to a single method This removes 3 lines in total LOC and makes the upcoming changes easier. Differential Revision: https://phab.mercurial-scm.org/D948
author Jun Wu <quark@fb.com>
date Wed, 04 Oct 2017 18:50:18 -0700
parents 9c7548eb7d1c
children 149109c96904
comparison
equal deleted inserted replaced
34802:9c7548eb7d1c 34803:d817bf1fc675
2101 def _bisecttests(self, tests): 2101 def _bisecttests(self, tests):
2102 bisectcmd = ['hg', 'bisect'] 2102 bisectcmd = ['hg', 'bisect']
2103 bisectrepo = self._runner.options.bisect_repo 2103 bisectrepo = self._runner.options.bisect_repo
2104 if bisectrepo: 2104 if bisectrepo:
2105 bisectcmd.extend(['-R', os.path.abspath(bisectrepo)]) 2105 bisectcmd.extend(['-R', os.path.abspath(bisectrepo)])
2106 def nooutput(args): 2106 def pread(args):
2107 p = subprocess.Popen(args, stderr=subprocess.STDOUT, 2107 p = subprocess.Popen(args, stderr=subprocess.STDOUT,
2108 stdout=subprocess.PIPE) 2108 stdout=subprocess.PIPE)
2109 p.stdout.read() 2109 data = p.stdout.read()
2110 p.wait() 2110 p.wait()
2111 return data
2111 for test in tests: 2112 for test in tests:
2112 nooutput(bisectcmd + ['--reset']), 2113 pread(bisectcmd + ['--reset']),
2113 nooutput(bisectcmd + ['--bad', '.']) 2114 pread(bisectcmd + ['--bad', '.'])
2114 nooutput(bisectcmd + ['--good', 2115 pread(bisectcmd + ['--good', self._runner.options.known_good_rev])
2115 self._runner.options.known_good_rev])
2116 # TODO: we probably need to forward more options 2116 # TODO: we probably need to forward more options
2117 # that alter hg's behavior inside the tests. 2117 # that alter hg's behavior inside the tests.
2118 opts = '' 2118 opts = ''
2119 withhg = self._runner.options.with_hg 2119 withhg = self._runner.options.with_hg
2120 if withhg: 2120 if withhg:
2121 opts += ' --with-hg=%s ' % shellquote(_strpath(withhg)) 2121 opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
2122 rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts, 2122 rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts,
2123 test) 2123 test)
2124 sub = subprocess.Popen(bisectcmd + ['--command', rtc], 2124 data = pread(bisectcmd + ['--command', rtc])
2125 stderr=subprocess.STDOUT,
2126 stdout=subprocess.PIPE)
2127 data = sub.stdout.read()
2128 sub.wait()
2129 m = re.search( 2125 m = re.search(
2130 (br'\nThe first (?P<goodbad>bad|good) revision ' 2126 (br'\nThe first (?P<goodbad>bad|good) revision '
2131 br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n' 2127 br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n'
2132 br'summary: +(?P<summary>[^\n]+)\n'), 2128 br'summary: +(?P<summary>[^\n]+)\n'),
2133 data, (re.MULTILINE | re.DOTALL)) 2129 data, (re.MULTILINE | re.DOTALL))