[diffoscope] 01/01: tests.comparators.test_elf: Return "unknown" if we can't parse the readelf version number eg. for FreeBSD. We don't skip those tests; as they should still run. (Closes: #886963)

Chris Lamb chris at chris-lamb.co.uk
Fri Jan 12 04:33:10 CET 2018


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 304660a54a433ff65ce0cef986b22b3d76793ab0
Author: Chris Lamb <lamby at debian.org>
Date:   Fri Jan 12 09:02:49 2018 +0530

    tests.comparators.test_elf: Return "unknown" if we can't parse the readelf version number eg. for FreeBSD. We don't skip those tests; as they should still run. (Closes: #886963)
---
 tests/comparators/test_elf.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index c64305d..c9e25d9 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
+import re
 import pytest
 import os.path
 import subprocess
@@ -43,7 +44,17 @@ def readelf_version():
         out = subprocess.check_output(['readelf', '--version'])
     except subprocess.CalledProcessError as e:
         out = e.output
-    return out.decode('UTF-8').splitlines()[0].split()[-1].strip()
+
+    # Only match GNU readelf; we only need to match some versions
+    m = re.match(
+        r'^GNU readelf .* (?P<version>[\d.]+)\n',
+        out.decode('utf-8'),
+    )
+
+    if m is None:
+        return 'unknown'
+
+    return m.group('version')
 
 
 def test_obj_identification(obj1):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list