Patchwork [1,of,7,v2] tests: make test-bdiff.py easier to maintain

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 15, 2016, 8:57 p.m.
Message ID <b7354208678098580f6e.1479243422@madski>
Download mbox | patch
Permalink /patch/17589/
State Accepted
Headers show

Comments

Mads Kiilerich - Nov. 15, 2016, 8:57 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1479243409 -3600
#      Tue Nov 15 21:56:49 2016 +0100
# Node ID b7354208678098580f6e5f975d734c1e8dd9d846
# Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
tests: make test-bdiff.py easier to maintain

Add more stdout logging to help navigate the .out file.

Patch

diff --git a/tests/test-bdiff.py b/tests/test-bdiff.py
--- a/tests/test-bdiff.py
+++ b/tests/test-bdiff.py
@@ -11,13 +11,12 @@  def test1(a, b):
     if d:
         c = mpatch.patches(a, [d])
     if c != b:
-        print("***", repr(a), repr(b))
-        print("bad:")
-        print(repr(c)[:200])
-        print(repr(d))
+        print("bad diff+patch result from\n  %r to\n  %r:" % (a, b))
+        print("bdiff: %r" % d)
+        print("patched: %r" % c[:200])
 
 def test(a, b):
-    print("***", repr(a), repr(b))
+    print("test", repr(a), repr(b))
     test1(a, b)
     test1(b, a)
 
@@ -43,13 +42,21 @@  test("a\nb", "a\nb")
 
 #issue1295
 def showdiff(a, b):
+    print('showdiff(\n  %r,\n  %r):' % (a, b))
     bin = bdiff.bdiff(a, b)
     pos = 0
+    q = 0
     while pos < len(bin):
         p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
         pos += 12
-        print(p1, p2, repr(bin[pos:pos + l]))
+        if p1:
+            print('', repr(a[q:p1]))
+        print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l]))
         pos += l
+        q = p2
+    if q < len(a):
+        print('', repr(a[q:]))
+
 showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n")
 showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n")
 # we should pick up abbbc. rather than bc.de as the longest match
diff --git a/tests/test-bdiff.py.out b/tests/test-bdiff.py.out
--- a/tests/test-bdiff.py.out
+++ b/tests/test-bdiff.py.out
@@ -1,27 +1,44 @@ 
-*** 'a\nc\n\n\n\n' 'a\nb\n\n\n'
-*** 'a\nb\nc\n' 'a\nc\n'
-*** '' ''
-*** 'a\nb\nc' 'a\nb\nc'
-*** 'a\nb\nc\nd\n' 'a\nd\n'
-*** 'a\nb\nc\nd\n' 'a\nc\ne\n'
-*** 'a\nb\nc\n' 'a\nc\n'
-*** 'a\n' 'c\na\nb\n'
-*** 'a\n' ''
-*** 'a\n' 'b\nc\n'
-*** 'a\n' 'c\na\n'
-*** '' 'adjfkjdjksdhfksj'
-*** '' 'ab'
-*** '' 'abc'
-*** 'a' 'a'
-*** 'ab' 'ab'
-*** 'abc' 'abc'
-*** 'a\n' 'a\n'
-*** 'a\nb' 'a\nb'
-6 6 'y\n\n'
-6 6 'y\n\n'
-9 9 'y\n\n'
-0 0 'a\nb\nb\n'
-12 12 'b\nc\n.\n'
-16 18 ''
+test 'a\nc\n\n\n\n' 'a\nb\n\n\n'
+test 'a\nb\nc\n' 'a\nc\n'
+test '' ''
+test 'a\nb\nc' 'a\nb\nc'
+test 'a\nb\nc\nd\n' 'a\nd\n'
+test 'a\nb\nc\nd\n' 'a\nc\ne\n'
+test 'a\nb\nc\n' 'a\nc\n'
+test 'a\n' 'c\na\nb\n'
+test 'a\n' ''
+test 'a\n' 'b\nc\n'
+test 'a\n' 'c\na\n'
+test '' 'adjfkjdjksdhfksj'
+test '' 'ab'
+test '' 'abc'
+test 'a' 'a'
+test 'ab' 'ab'
+test 'abc' 'abc'
+test 'a\n' 'a\n'
+test 'a\nb' 'a\nb'
+showdiff(
+  'x\n\nx\n\nx\n\nx\n\nz\n',
+  'x\n\nx\n\ny\n\nx\n\nx\n\nz\n'):
+ 'x\n\nx\n\n'
+ 6 6 '' -> 'y\n\n'
+ 'x\n\nx\n\nz\n'
+showdiff(
+  'x\n\nx\n\nx\n\nx\n\nz\n',
+  'x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n'):
+ 'x\n\nx\n\n'
+ 6 6 '' -> 'y\n\n'
+ 'x\n\n'
+ 9 9 '' -> 'y\n\n'
+ 'x\n\nz\n'
+showdiff(
+  'a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n',
+  'a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n'):
+ 0 0 '' -> 'a\nb\nb\n'
+ 'a\nb\nb\nb\nc\n.\n'
+ 12 12 '' -> 'b\nc\n.\n'
+ 'd\ne\n'
+ 16 18 '.\n' -> ''
+ 'f\n'
 done
 done