tests/test-minifileset.py
author Martin von Zweigbergk <martinvonz@google.com>
Wed, 25 Apr 2018 09:24:07 -0700
branchstable
changeset 37819 ee3d58b4a47f
parent 35741 73432eee0ac4
child 37877 2cdae2582d8a
permissions -rw-r--r--
revlog: make pure version of _partialmatch() support 40-byte hex nodeids Without this patch, test-histedit-arguments.t would fail when run with --pure. It turned out to be because the pure version of _partialmatch() does not support full 40-byte hex nodeids. When histedit's instructions include things like "pick tip", it resolves the "tip" revision early to a full nodeid (but plain hex nodeid prefixes are not resolved to full nodeids). Then the nodeid (full or not) is looked up using to a full nodeid later. This step is what fails in pure mode. It has been failing since my c4131138eadb (histedit: look up partial nodeid as partial nodeid, 2018-04-06). I haven't verified, but I suspect histedit instructions like "pick <full hex nodeid>" would have been failing before my commit too, though. The fix is trivial: change a "< 40" to "<= 40". Differential Revision: https://phab.mercurial-scm.org/D3428

from __future__ import absolute_import
from __future__ import print_function

import os
import sys

# make it runnable directly without run-tests.py
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]

from mercurial import minifileset

def check(text, truecases, falsecases):
    f = minifileset.compile(text)
    for args in truecases:
        if not f(*args):
            print('unexpected: %r should include %r' % (text, args))
    for args in falsecases:
        if f(*args):
            print('unexpected: %r should exclude %r' % (text, args))

check('all()', [('a.php', 123), ('b.txt', 0)], [])
check('none()', [], [('a.php', 123), ('b.txt', 0)])
check('!!!!((!(!!all())))', [], [('a.php', 123), ('b.txt', 0)])

check('"path:a" & (**.b | **.c)', [('a/b.b', 0), ('a/c.c', 0)], [('b/c.c', 0)])
check('(path:a & **.b) | **.c',
      [('a/b.b', 0), ('a/c.c', 0), ('b/c.c', 0)], [])

check('**.bin - size("<20B")', [('b.bin', 21)], [('a.bin', 11), ('b.txt', 21)])

check('!!**.bin or size(">20B") + "path:bin" or !size(">10")',
      [('a.bin', 11), ('b.txt', 21), ('bin/abc', 11)],
      [('a.notbin', 11), ('b.txt', 11), ('bin2/abc', 11)])

check('(**.php and size(">10KB")) | **.zip | ("path:bin" & !"path:bin/README") '
      ' | size(">1M")',
      [('a.php', 15000), ('a.zip', 0), ('bin/a', 0), ('bin/README', 1e7)],
      [('a.php', 5000), ('b.zip2', 0), ('t/bin/a', 0), ('bin/README', 1)])