Patchwork [1,of,1,V2] test-pathencode: actually compare our current pathencoding implementations

login
register
mail settings
Submitter Adrian Buehlmann
Date Dec. 19, 2012, 9:23 a.m.
Message ID <77ba937bfaa5a33adb73.1355909023@kork>
Download mbox | patch
Permalink /patch/188/
State Accepted
Commit 8ceabb34f1cb5469b7dd6b2d7b1ce4727d719e65
Headers show

Comments

Adrian Buehlmann - Dec. 19, 2012, 9:23 a.m.
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1355907763 -3600
# Node ID 77ba937bfaa5a33adb738f4858ef0bd5aab3c283
# Parent  9c76da468a19a0cf9551b8a667d2913b0b0ee7be
test-pathencode: actually compare our current pathencoding implementations

We already have two implementations of the pathencoding (C and Python) and this
test can perfectly well be used to probabilistically test them instead of
just wasting CPU cycles and test time.
Bryan O'Sullivan - Dec. 19, 2012, 5:52 p.m.
On Wed, Dec 19, 2012 at 1:23 AM, Adrian Buehlmann <adrian at cadifra.com>wrote:

> test-pathencode: actually compare our current pathencoding implementations
>

Pushed to crew, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20121219/da405d8e/attachment.html>

Patch

diff --git a/tests/test-pathencode.py b/tests/test-pathencode.py
--- a/tests/test-pathencode.py
+++ b/tests/test-pathencode.py
@@ -13,9 +13,6 @@ 
 if sys.version_info[:2] < (2, 6):
     sys.exit(0)
 
-def hybridencode(path):
-    return store._hybridencode(path, True)
-
 validchars = set(map(chr, range(0, 256)))
 alphanum = range(ord('A'), ord('Z'))
 
@@ -157,7 +154,15 @@ 
 def runtests(rng, seed, count):
     nerrs = 0
     for p in genpath(rng, count):
-        hybridencode(p)
+        h = store._dothybridencode(p)    # uses C implementation, if available
+        r = store._hybridencode(p, True) # reference implementation in Python
+        if h != r:
+            if nerrs == 0:
+                print >> sys.stderr, 'seed:', hex(seed)[:-1]
+            print >> sys.stderr, "\np: '%s'" % p.encode("string_escape")
+            print >> sys.stderr, "h: '%s'" % h.encode("string_escape")
+            print >> sys.stderr, "r: '%s'" % r.encode("string_escape")
+            nerrs += 1
     return nerrs
 
 def main():