tests: add glob matching for unified tests
This adds a " (glob)" marker that works like a simpler version of
(re): "*" is converted to ".*", and "?" is converted to ".".
Both special characters can be escaped using "\", and the backslash
itself can be escaped as well.
Other glob-style syntax, like "**", "[chars]", or "[!chars]", isn't
supported.
[ original upstream message ]
--- a/tests/run-tests.py Wed Sep 22 16:06:00 2010 -0500
+++ b/tests/run-tests.py Wed Sep 22 16:06:02 2010 -0500
@@ -509,6 +509,25 @@
# el is an invalid regex
return False
+ def globmatch(el, l):
+ # The only supported special characters are * and ?. Escaping is
+ # supported.
+ i, n = 0, len(el)
+ res = ''
+ while i < n:
+ c = el[i]
+ i += 1
+ if c == '\\' and el[i] in '*?\\':
+ res += el[i-1:i+1]
+ i += 1
+ elif c == '*':
+ res += '.*'
+ elif c == '?':
+ res += '.'
+ else:
+ res += re.escape(c)
+ return rematch(res, l)
+
pos = -1
postout = []
ret = 0
@@ -528,8 +547,10 @@
if el == l: # perfect match (fast)
postout.append(" " + l)
- elif el and el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l):
- postout.append(" " + el) # fallback regex match
+ elif (el and
+ (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
+ el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))):
+ postout.append(" " + el) # fallback regex/glob match
else:
postout.append(" " + l) # let diff deal with it
--- a/tests/test-keyword.t Wed Sep 22 16:06:00 2010 -0500
+++ b/tests/test-keyword.t Wed Sep 22 16:06:02 2010 -0500
@@ -27,13 +27,13 @@
Revision = {node|short}
Source = {root}/{file},v
$Author: test $
- \$Date: ..../../.. ..:..:.. \$ (re)
- \$Header: .*/demo\.txt,v ............ ..../../.. ..:..:.. test \$ (re)
- \$Id: demo\.txt,v ............ ..../../.. ..:..:.. test \$ (re)
+ $Date: ????/??/?? ??:??:?? $ (glob)
+ $Header: */demo.txt,v ???????????? ????/??/?? ??:??:?? test $ (glob)
+ $Id: demo.txt,v ???????????? ????/??/?? ??:??:?? test $ (glob)
$RCSFile: demo.txt,v $
$RCSfile: demo.txt,v $
- \$Revision: ............ \$ (re)
- \$Source: .*/demo.txt,v \$ (re)
+ $Revision: ???????????? $ (glob)
+ $Source: */demo.txt,v $ (glob)
$ hg --quiet kwdemo "Branch = {branches}"
[extensions]
@@ -71,7 +71,7 @@
hg bundle --base null ../test-keyword.hg
$ hg pull -u "$TESTDIR"/test-keyword.hg
- pulling from .*test-keyword\.hg (re)
+ pulling from *test-keyword.hg (glob)
requesting all changes
adding changesets
adding manifests
@@ -150,7 +150,7 @@
do not process $Id:
xxx $
ignore $Id$
- a.* (re)
+ a* (glob)
Test hook execution
@@ -195,15 +195,15 @@
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
- Date: .* (re)
- Subject: changeset in .* (re)
+ Date: * (glob)
+ Subject: changeset in * (glob)
From: mercurial
X-Hg-Notification: changeset a2392c293916
- Message-Id: <hg\.a2392c293916.*> (re)
+ Message-Id: <hg.a2392c293916*> (glob)
To: Test
- changeset a2392c293916 in .* (re)
- details: .*\?cmd=changeset;node=a2392c293916 (re)
+ changeset a2392c293916 in * (glob)
+ details: *cmd=changeset;node=a2392c293916 (glob)
description:
addsym
@@ -218,15 +218,15 @@
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
- Date:.* (re)
- Subject: changeset in.* (re)
+ Date:* (glob)
+ Subject: changeset in* (glob)
From: User Name <user@example.com>
X-Hg-Notification: changeset ef63ca68695b
- Message-Id: <hg\.ef63ca68695b.*> (re)
+ Message-Id: <hg.ef63ca68695b*> (glob)
To: Test
- changeset ef63ca68695b in .* (re)
- details: .*\?cmd=changeset;node=ef63ca68695b (re)
+ changeset ef63ca68695b in * (glob)
+ details: *cmd=changeset;node=ef63ca68695b (glob)
description:
absym
@@ -335,7 +335,7 @@
$ hg diff
diff -r d17e03c92c97 a
--- a/a Wed Dec 31 23:59:51 1969 -0000
- \+\+\+ b/a .* (re)
+ +++ b/a * (glob)
@@ -2,3 +2,4 @@
foo
do not process $Id:
@@ -479,7 +479,7 @@
$ hg diff --rev 1
diff -r ef63ca68695b c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
- \+\+\+ b/c .* (re)
+ +++ b/c * (glob)
@@ -0,0 +1,3 @@
+expand $Id$
+do not process $Id:
@@ -527,7 +527,7 @@
do not process $Id:
xxx $
ignore $Id$
- a.* (re)
+ a* (glob)
Write custom keyword and prepare multiline commit message
@@ -577,7 +577,7 @@
xxx $
$Xinfo: User Name <user@example.com>: firstline $
ignore $Id$
- a.* (re)
+ a* (glob)
annotate
@@ -648,7 +648,7 @@
> default = ../Test
> EOF
$ hg incoming
- comparing with .*test-keyword\.t/Test (re)
+ comparing with *test-keyword.t/Test (glob)
searching for changes
changeset: 2:bb948857c743
tag: tip
@@ -718,7 +718,7 @@
kwexpand nonexistent
$ hg kwexpand nonexistent
- nonexistent:.* (re)
+ nonexistent:* (glob)
hg serve
@@ -907,7 +907,7 @@
xxx $
$Xinfo: User Name <user@example.com>: firstline $
ignore $Id$
- a.* (re)
+ a* (glob)
Now disable keyword expansion
@@ -924,4 +924,4 @@
xxx $
$Xinfo$
ignore $Id$
- a.* (re)
+ a* (glob)