diff tests/test-filelog @ 11540:2370e270a29a stable

filelog: test behaviour for data starting with "\1\n" Because "\1\n" is a separator for metadata, data starting with "\1\n" is handled specifically. It was not tested. size() call return incorrect data if original data had been "\1\n-escaped". There's no obvious way to fix it for now, just flag the error in the code and add an "expected failure" kind of test.
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 05 Jul 2010 18:43:46 +0900
parents
children 2de1244361aa
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-filelog	Mon Jul 05 18:43:46 2010 +0900
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+"""
+Tests the behaviour of filelog w.r.t. data starting with '\1\n'
+"""
+from mercurial import ui, hg
+from mercurial.node import nullid, hex
+
+myui = ui.ui()
+repo = hg.repository(myui, path='.', create=True)
+
+fl = repo.file('foobar')
+
+def addrev(text, renamed=False):
+    if renamed:
+        # data doesnt matter. Just make sure filelog.renamed() returns True
+        meta = dict(copyrev=hex(nullid), copy='bar')
+    else:
+        meta = {}
+
+    t = repo.transaction('commit')
+    try:
+        node = fl.add(text, meta, t, 0, nullid, nullid)
+        return node
+    finally:
+        t.close()
+
+def error(text):
+    print 'ERROR: ' + text
+
+textwith = '\1\nfoo'
+without = 'foo'
+
+node = addrev(textwith)
+if not textwith == fl.read(node):
+    error('filelog.read for data starting with \\1\\n')
+if fl.cmp(node, textwith) or not fl.cmp(node, without):
+    error('filelog.cmp for data starting with \\1\\n')
+if fl.size(0) != len(textwith):
+    error('FIXME: This is a known failure of filelog.size for data starting '
+        'with \\1\\n')
+
+node = addrev(textwith, renamed=True)
+if not textwith == fl.read(node):
+    error('filelog.read for a renaming + data starting with \\1\\n')
+if fl.cmp(node, textwith) or not fl.cmp(node, without):
+    error('filelog.cmp for a renaming + data starting with \\1\\n')
+if fl.size(1) != len(textwith):
+    error('filelog.size for a renaming + data starting with \\1\\n')
+
+print 'OK.'