Commit 80ebf7c1 authored by Stefan Behnel's avatar Stefan Behnel

clean up gdb version test in TestLibCython.py

parent dec3890d
...@@ -35,50 +35,39 @@ def test_gdb(): ...@@ -35,50 +35,39 @@ def test_gdb():
if have_gdb is not None: if have_gdb is not None:
return have_gdb return have_gdb
have_gdb = False
try: try:
p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE) p = subprocess.Popen(['gdb', '-nx', '--version'], stdout=subprocess.PIPE)
have_gdb = True
except OSError: except OSError:
# gdb was not installed # gdb not found
have_gdb = False gdb_version = None
else: else:
gdb_version = p.stdout.read().decode('ascii', 'ignore') stdout, _ = p.communicate()
p.wait()
p.stdout.close()
if have_gdb:
# Based on Lib/test/test_gdb.py # Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)" regex = "GNU gdb [^\d]*(\d+)\.(\d+)"
gdb_version_number = list(map(int, re.search(regex, gdb_version).groups())) gdb_version = re.match(regex, stdout.decode('ascii', 'ignore'))
if gdb_version:
gdb_version_number = list(map(int, gdb_version.groups()))
if gdb_version_number >= [7, 2]: if gdb_version_number >= [7, 2]:
python_version_script = tempfile.NamedTemporaryFile(mode='w+') have_gdb = True
try: with tempfile.NamedTemporaryFile(mode='w+') as python_version_script:
python_version_script.write( python_version_script.write(
'python import sys; print("%s %s" % sys.version_info[:2])') 'python import sys; print("%s %s" % sys.version_info[:2])')
python_version_script.flush() python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name], p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
stdout, _ = p.communicate()
try: try:
python_version = p.stdout.read().decode('ascii') internal_python_version = list(map(int, stdout.decode('ascii', 'ignore').split()))
p.wait() if internal_python_version < [2, 6]:
finally:
p.stdout.close()
try:
python_version_number = list(map(int, python_version.split()))
except ValueError:
have_gdb = False have_gdb = False
finally: except ValueError:
python_version_script.close()
# Be Python 3 compatible
if (not have_gdb
or gdb_version_number < [7, 2]
or python_version_number < [2, 6]):
warnings.warn(
'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
have_gdb = False have_gdb = False
if not have_gdb:
warnings.warn('Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
return have_gdb return have_gdb
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment