test-filelog.py
65 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-filelog.py
|
r46434 | #!/usr/bin/env python3 | ||
|
r16498 | """ | ||
|
r26098 | Tests the behavior of filelog w.r.t. data starting with '\1\n' | ||
|
r16498 | """ | ||
|
r28744 | from __future__ import absolute_import, print_function | ||
|
r29205 | |||
|
r47771 | from mercurial.node import hex | ||
|
r28743 | from mercurial import ( | ||
hg, | ||||
|
r28805 | ui as uimod, | ||
|
r28743 | ) | ||
|
r16498 | |||
|
r30559 | myui = uimod.ui.load() | ||
|
r37952 | repo = hg.repository(myui, path=b'.', create=True) | ||
|
r16498 | |||
|
r37952 | fl = repo.file(b'foobar') | ||
|
r16498 | |||
|
r43346 | |||
|
r16498 | def addrev(text, renamed=False): | ||
if renamed: | ||||
|
r17486 | # data doesn't matter. Just make sure filelog.renamed() returns True | ||
|
r47771 | meta = {b'copyrev': hex(repo.nullid), b'copy': b'bar'} | ||
|
r16498 | else: | ||
meta = {} | ||||
lock = t = None | ||||
try: | ||||
lock = repo.lock() | ||||
|
r37952 | t = repo.transaction(b'commit') | ||
|
r47771 | node = fl.add(text, meta, t, 0, repo.nullid, repo.nullid) | ||
|
r16498 | return node | ||
finally: | ||||
if t: | ||||
t.close() | ||||
if lock: | ||||
lock.release() | ||||
|
r43346 | |||
|
r16498 | def error(text): | ||
|
r28744 | print('ERROR: ' + text) | ||
|
r16498 | |||
|
r43346 | |||
|
r37952 | textwith = b'\1\nfoo' | ||
without = b'foo' | ||||
|
r16498 | |||
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): | ||||
|
r43346 | error( | ||
'FIXME: This is a known failure of filelog.size for data starting ' | ||||
'with \\1\\n' | ||||
) | ||||
|
r16498 | |||
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') | ||||
|
r28744 | print('OK.') | ||