[PATCH 2 of 2] keyword (contrib): add test

Christian Ebert blacktrash at gmx.net
Sun Jul 22 08:54:11 CDT 2007


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1185112025 -7200
# Node ID 7155894f402b5fe3c3cd22660a7f929304ec1a81
# Parent  341a71fb11dccec8ca59e9926c66cfb0a85fe89d
keyword (contrib): add test

diff --git a/tests/test-keyword b/tests/test-keyword
new file mode 100755
--- /dev/null
+++ b/tests/test-keyword
@@ -0,0 +1,140 @@
+#!/bin/sh
+
+cat <<EOF >> $HGRCPATH
+[extensions]
+keyword = ${TESTDIR}/../contrib/keyword.py
+[keyword]
+* =
+b = ignore
+EOF
+
+echo % help
+hg help keyword
+
+echo % hg kwdemo
+hg --quiet kwdemo --default \
+| sed -e 's!^keyword =.*contrib/keyword.py$!keyword = ../contrib/keyword.py!' \
+ -e 's![^ ][^ ]*demo.txt,v!/TMP/demo.txt,v!' \
+ -e 's/,v [a-z0-9][a-z0-9]* /,v xxxxxxxxxxxx /' \
+ -e '/[$]Revision/ s/: [a-z0-9][a-z0-9]* /: xxxxxxxxxxxx /' \
+ -e 's! 20[0-9][0-9]/[01][0-9]/[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]! 2000/00/00 00:00:00!'
+
+hg init Test
+cd Test
+
+echo % kwshrink should abort in empty/invalid repo
+hg kwshrink
+
+echo 'expand $Id$' > a
+echo 'ignore $Id$' > b
+ln -s a sym
+echo % cat
+cat sym a b
+
+echo % default keyword expansion
+echo % commit
+hg --debug commit -A -mabsym -d '0 0' -u 'User Name <user at example.com>'
+echo % status
+hg status
+echo % identify
+hg --quiet identify
+echo % cat
+cat sym a b
+echo % hg cat
+hg cat sym a b
+
+echo
+echo % touch
+touch a b
+echo % status
+hg status
+
+rm sym a b
+echo % update
+hg update
+echo % cat
+cat sym a b
+
+echo % copy
+hg cp a c
+echo % commit
+hg --debug commit -ma2c -d '1 0' -u 'User Name <user at example.com>'
+echo % cat a c
+cat a c
+echo % touch copied c
+touch c
+echo % status
+
+echo % rollback
+hg rollback
+echo % status
+hg status
+echo % update -C
+hg update --clean
+
+echo % custom keyword expansion
+echo % try with kwdemo
+hg --quiet kwdemo "Xinfo = {author}: {desc}" \
+| sed -e 's!^keyword =.*contrib/keyword.py$!keyword = ../contrib/keyword.py!'
+
+cat <<EOF >>$HGRCPATH
+[keywordmaps]
+Id = {file} {node|short} {date|rfc822date} {author|user}
+Xinfo = {author}: {desc}
+EOF
+
+echo % cat
+cat sym a b
+echo % hg cat
+hg cat sym a b
+
+echo
+echo '$Xinfo$' >> a
+cat <<EOF >> log
+firstline
+secondline
+EOF
+
+echo % interrupted commit
+HGEDITOR=false hg commit
+echo % status
+hg status
+
+echo % commit
+hg --debug commit -l log -d '2 0' -u 'User Name <user at example.com>'
+rm log
+echo % status
+hg status
+
+echo % cat
+cat sym a b
+echo % hg cat
+hg cat sym a b
+
+echo
+cd ..
+hg clone -r0 Test Test-a
+cd Test-a
+cat <<EOF >> .hg/hgrc
+[paths]
+default = ../Test
+EOF
+echo % incoming
+# remove path to temp dir
+hg incoming | sed -e 's/^\(comparing with \).*\(test-keyword.*\)/\1\2/'
+
+echo % switch off expansion
+cd ../Test
+echo % kwshrink
+hg --debug kwshrink
+echo % cat
+cat sym a b
+echo % hg cat
+hg cat sym a b
+echo
+rm $HGRCPATH
+echo % cat
+cat sym a b
+echo % hg cat
+hg cat sym a b
+echo
diff --git a/tests/test-keyword.out b/tests/test-keyword.out
new file mode 100644
--- /dev/null
+++ b/tests/test-keyword.out
@@ -0,0 +1,200 @@
+% help
+keyword extension - keyword expansion in local repositories
+
+This extension expands RCS/CVS-like or self-customized $Keywords$
+in tracked text files selected by your configuration.
+
+Keywords are only expanded in local repositories and not stored in
+the change history. The mechanism can be regarded as a convenience
+for the current user or for archive distribution.
+
+Configuration is done in the [keyword] and [keywordmaps] sections
+of hgrc files.
+
+Example:
+
+    [keyword]
+    # expand keywords in every python file except those matching "x*"
+    **.py =
+    x*    = ignore
+
+Note: the more specific you are in your filename patterns
+      the less you lose speed in huge repos.
+
+For [keywordmaps] template mapping and expansion demonstration and
+control run "hg kwdemo".
+
+An additional date template filter {date|utcdate} is provided.
+
+The default template mappings (view with "hg kwdemo -d") can be replaced
+with customized keywords and templates.
+Again, run "hg kwdemo" to control the results of your config changes.
+
+Before changing/disabling active keywords, run "hg kwshrink" to avoid
+the risk of inadvertedly storing expanded keywords in the change history.
+
+Expansions spanning more than one line and incremental expansions,
+like CVS' $Log$, are not supported. A keyword template map
+"Log = {desc}" expands to the first line of the changeset description.
+
+Caveat: "hg import" fails if the patch context contains an active
+        keyword. In that case run "hg kwshrink", reimport, and then
+        "hg kwexpand".
+        Or, better, use bundle/unbundle to share changes.
+
+list of commands:
+
+ kwdemo     print [keywordmaps] configuration and an expansion example
+ kwexpand   expand keywords in working directory
+ kwshrink   revert expanded keywords in working directory
+
+use "hg -v help keyword" to show aliases and global options
+% hg kwdemo
+[extensions]
+keyword = ../contrib/keyword.py
+[keyword]
+demo.txt =
+[keywordmaps]
+RCSFile = {file|basename},v
+Author = {author|user}
+Header = {root}/{file},v {node|short} {date|utcdate} {author|user}
+Source = {root}/{file},v
+Date = {date|utcdate}
+Id = {file|basename},v {node|short} {date|utcdate} {author|user}
+Revision = {node|short}
+$RCSFile: demo.txt,v $
+$Author: test $
+$Header: /TMP/demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $
+$Source: /TMP/demo.txt,v $
+$Date: 2000/00/00 00:00:00 $
+$Id: demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $
+$Revision: xxxxxxxxxxxx $
+% kwshrink should abort in empty/invalid repo
+abort: no revision checked out!
+% cat
+expand $Id$
+expand $Id$
+ignore $Id$
+% default keyword expansion
+% commit
+adding a
+adding b
+adding sym
+a
+b
+sym
+overwriting a expanding keywords
+% status
+% identify
+126ec311add6
+% cat
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+ignore $Id$
+% hg cat
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+ignore $Id$
+a
+% touch
+% status
+% update
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% cat
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+ignore $Id$
+% copy
+% commit
+c
+ c: copy a:e6cc15c9eb5fd3c09ec691b667cf6ccd6dfb936e
+overwriting c expanding keywords
+% cat a c
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+expand $Id: c,v dbdaa3155171 1970/01/01 00:00:01 user $
+% touch copied c
+% status
+% rollback
+rolling back last transaction
+% status
+A c
+% update -C
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+% custom keyword expansion
+% try with kwdemo
+[extensions]
+keyword = ../contrib/keyword.py
+[keyword]
+demo.txt =
+[keywordmaps]
+Xinfo = {author}: {desc}
+$Xinfo: test: hg keyword config and expansion example $
+% cat
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+expand $Id: a,v 126ec311add6 1970/01/01 00:00:00 user $
+ignore $Id$
+% hg cat
+expand $Id: a 126ec311add6 Thu, 01 Jan 1970 00:00:00 +0000 user $
+ignore $Id$
+a
+% interrupted commit
+transaction abort!
+rollback completed
+abort: edit failed: false exited with status 1
+% status
+M a
+? log
+% commit
+a
+overwriting a expanding keywords
+% status
+% cat
+expand $Id: a 838d2ecf723e Thu, 01 Jan 1970 00:00:02 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+expand $Id: a 838d2ecf723e Thu, 01 Jan 1970 00:00:02 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+ignore $Id$
+% hg cat
+expand $Id: a 838d2ecf723e Thu, 01 Jan 1970 00:00:02 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+ignore $Id$
+a
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 3 changes to 3 files
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% incoming
+comparing with test-keyword/Test-a/../Test
+searching for changes
+changeset:   1:838d2ecf723e
+tag:         tip
+user:        User Name <user at example.com>
+date:        Thu Jan 01 00:00:02 1970 +0000
+summary:     firstline
+
+% switch off expansion
+% kwshrink
+overwriting a shrinking keywords
+% cat
+expand $Id$
+$Xinfo$
+expand $Id$
+$Xinfo$
+ignore $Id$
+% hg cat
+expand $Id: a 838d2ecf723e Thu, 01 Jan 1970 00:00:02 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+ignore $Id$
+a
+% cat
+expand $Id$
+$Xinfo$
+expand $Id$
+$Xinfo$
+ignore $Id$
+% hg cat
+expand $Id$
+$Xinfo$
+ignore $Id$
+a


More information about the Mercurial-devel mailing list