[diffoscope] 04/05: Ignore line numbers because different llvm-dis versions output extra metadata

Ximin Luo infinity0 at debian.org
Sat Aug 13 03:05:03 CEST 2016


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

infinity0 pushed a commit to branch master
in repository diffoscope.

commit a034a335665a4f9ae26ab6e9b92b1e7114eae223
Author: Ximin Luo <infinity0 at debian.org>
Date:   Sat Aug 13 02:51:23 2016 +0200

    Ignore line numbers because different llvm-dis versions output extra metadata
---
 diffoscope/comparators/utils.py | 7 +++++++
 tests/comparators/test_rlib.py  | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index e365144..7e9968a 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -23,6 +23,7 @@ from io import BytesIO
 from itertools import starmap
 # The following would be shutil.which in Python 3.3
 import os
+import re
 from stat import S_ISCHR, S_ISBLK
 import subprocess
 from threading import Thread
@@ -142,6 +143,12 @@ def get_compressed_content_name(path, expected_extension):
     return name
 
 
+DIFF_LINE_NUMBERS_RE = re.compile(r"(^|\n)@@ -(\d+),(\d+) \+(\d+),(\d+) @@(?=\n|$)")
+
+def diff_ignore_line_numbers(diff):
+    return DIFF_LINE_NUMBERS_RE.sub(r"\1@@ -XX,XX +XX,XX @@", diff)
+
+
 NO_COMMENT = None
 
 
diff --git a/tests/comparators/test_rlib.py b/tests/comparators/test_rlib.py
index 5ef7032..bfba4a1 100644
--- a/tests/comparators/test_rlib.py
+++ b/tests/comparators/test_rlib.py
@@ -26,6 +26,7 @@ from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
 from diffoscope.comparators.ar import ArFile
 from diffoscope.comparators.llvm import LlvmBitCodeFile
 from diffoscope.comparators.rust import RustObjectFile
+from diffoscope.comparators.utils import diff_ignore_line_numbers
 from diffoscope.config import Config
 
 TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.rlib')
@@ -64,7 +65,8 @@ def test_item2_deflate_llvm_bitcode(differences):
     assert differences[2].source1 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
     assert differences[2].source2 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
     expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_llvm_dis_expected_diff')).read()
-    assert differences[2].details[0].details[1].unified_diff == expected_diff
+    actual_diff = differences[2].details[0].details[1].unified_diff
+    assert diff_ignore_line_numbers(actual_diff) == diff_ignore_line_numbers(expected_diff)
 
 def test_compare_non_existing(monkeypatch, rlib1):
     monkeypatch.setattr(Config.general, 'new_file', True)

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


More information about the diffoscope mailing list