Patchwork run-tests: improve diff intelligence [RFC]

login
register
mail settings
Submitter timeless
Date Feb. 20, 2017, 4:37 a.m.
Message ID <b04c501c22d75f368e69.1487565443@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/18680/
State Deferred, archived
Headers show

Comments

timeless - Feb. 20, 2017, 4:37 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1487565093 0
#      Mon Feb 20 04:31:33 2017 +0000
# Node ID b04c501c22d75f368e69b3b533f71e16c17ea8b6
# Parent  693a5bb478543a986808264e586073a3ceedc38f
# Available At https://bitbucket.org/timeless/mercurial-crew
#              hg pull https://bitbucket.org/timeless/mercurial-crew -r b04c501c22d7
run-tests: improve diff intelligence [RFC]

This doesn't work w/ py3 (we'd have to talk to the underlying
differ).

This is based on a problem smf hit recently, which I hit
periodically.

Patch

diff -r 693a5bb47854 -r b04c501c22d7 tests/run-tests.py
--- a/tests/run-tests.py	Mon Feb 13 17:03:14 2017 -0800
+++ b/tests/run-tests.py	Mon Feb 20 04:31:33 2017 +0000
@@ -485,6 +485,34 @@ 
 
     return servefail, lines
 
+if not PYTHON3:
+    def getmindiff(expected, output, ref, err):
+        servefail = False
+        stats = (len(expected) + len(output), 0, [])
+        for n in range(4):
+            lines = []
+            change = 0
+            neutral = 0
+            for line in _unified_diff(expected, output, ref, err, n=n):
+                if line.startswith(b'+++') or line.startswith(b'---'):
+                    line = line.replace(b'\\', b'/')
+                    if line.endswith(b' \n'):
+                        line = line[:-2] + b'\n'
+                elif line.startswith(b'+') or line.startswith(b'-'):
+                    change += 1
+                else:
+                    neutral += 1
+                lines.append(line)
+                if not servefail and line.startswith(
+                         b'+  abort: child process failed to start'):
+                    servefail = True
+        if change <= stats[0]:
+            stats = (change, neutral, lines)
+        lines = stats[-1]
+
+        return servefail, lines
+    getdiff = getmindiff
+
 verbose = False
 def vlog(*msg):
     """Log only when in verbose mode."""
diff -r 693a5bb47854 -r b04c501c22d7 tests/test-run-tests.t
--- a/tests/test-run-tests.t	Mon Feb 13 17:03:14 2017 -0800
+++ b/tests/test-run-tests.t	Mon Feb 20 04:31:33 2017 +0000
@@ -483,6 +483,35 @@ 
 (reinstall)
   $ mv backup test-failure.t
 
+#if no-py3k
+  $ cat > test-disparate-changes.t << EOF
+  >   $ echo 1
+  >   * (glob)
+  >   $ echo 1
+  >   1
+  >   $ echo 1
+  >   2
+  > EOF
+  $ echo n | rt -i test-disparate-changes.t
+  
+  --- $TESTTMP/test-disparate-changes.t
+  +++ $TESTTMP/test-disparate-changes.t.err
+  @@ -3,4 +3,4 @@
+     $ echo 1
+     1
+     $ echo 1
+  -  2
+  +  1
+  Accept this change? [n] 
+  ERROR: test-disparate-changes.t output changed
+  !
+  Failed test-disparate-changes.t: output changed
+  # Ran 1 tests, 0 skipped, 0 warned, 1 failed.
+  python hash seed: * (glob)
+  [1]
+  $ rm test-disparate-changes.t
+#endif
+
 No Diff
 ===============