[PATCH 2 of 2] keyword: add test

Christian Ebert blacktrash at gmx.net
Wed Mar 7 06:31:02 CST 2007


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1173270606 -3600
# Node ID b60a9df1ade1af5c69ff775a6e08406832a20461
# Parent  0598006557611817c31d000e0b76f7c8870b80b4
keyword: add test

diff -r 059800655761 -r b60a9df1ade1 tests/test-keyword
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-keyword	Wed Mar 07 13:30:06 2007 +0100
@@ -0,0 +1,106 @@
+#!/bin/sh
+
+cat <<EOF >> $HGRCPATH
+[extensions]
+keyword=${TESTDIR}/../contrib/keyword.py
+[keyword]
+a =
+b = ignore
+c = archive
+EOF
+
+echo % help
+hg help keyword
+
+hg init Test
+cd Test
+echo 'expand $Id$' > a
+echo 'ignore $Id$' > b
+echo 'archive $Id$' > c
+ln -s a sym
+echo % cat
+cat a b c sym
+
+echo % default keyword expansion
+echo % commit
+hg --debug commit -A -mabcsym -d '0 0' -u 'User Name <user at example.com>'
+echo % status
+hg status
+
+echo % cat
+cat a b c sym
+echo % hg cat
+hg cat a b c sym
+
+echo
+rm a b c sym
+echo % update
+hg update
+echo % cat
+cat a b c sym
+
+echo % archive
+hg archive ../Archive
+cd ../Archive
+echo % cat
+cat a b c sym
+echo
+cd -
+
+echo % custom keyword expansion
+cat <<EOF >>$HGRCPATH
+[keywordmaps]
+Id = {file} {node|short} {date|rfc822date} {author|user}
+Xinfo = {author}: {desc}
+EOF
+
+echo % cat
+cat a b c sym
+echo % hg cat
+hg cat a b c sym
+
+echo
+echo '$Xinfo$' >> a
+cat <<EOF >> log
+firstline
+secondline
+EOF
+
+echo % commit
+hg --debug commit -l log -d '1 0' -u 'User Name <user at example.com>'
+rm log
+echo % status
+hg status
+
+echo % cat
+cat a b c sym
+echo % hg cat
+hg cat a b c sym
+
+echo
+cd ..
+hg clone -r0 Test Test-a
+cd Test-a
+cat <<EOF >> .hg/hgrc
+[paths]
+default = ../Test
+EOF
+echo % incoming
+hg incoming
+
+echo % switch off expansion
+rm $HGRCPATH
+
+cd ../Test
+echo % cat
+cat a b c sym
+echo % hg cat
+hg cat a b c sym
+
+echo
+echo % update
+rm a b c sym
+hg update
+
+echo % cat
+cat a b c sym
diff -r 059800655761 -r b60a9df1ade1 tests/test-keyword.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-keyword.out	Wed Mar 07 13:30:06 2007 +0100
@@ -0,0 +1,156 @@
+% help
+keyword extension - keyword expansion in local repositories
+
+This extension expands RCS/CVS-like or self-customized keywords in
+the text files selected by your configuration.
+
+Keywords are only expanded in local repositories and not logged by
+Mercurial internally. The mechanism can be regarded as a convenience
+for the current user and may be turned off anytime.
+
+The exansion works in 2 modes:
+    1) working mode: substitution takes place on every commit and
+       update of the working repository.
+    2) archive mode: substitution is only triggered by "hg archive".
+
+Caveat: "hg import" might fail if the patches were exported from a
+repo with a different/no keyword setup, whereas "hg unbundle" is
+safe.
+
+Configuration is done in the [keyword] and [keywordmaps] sections of
+hgrc files.
+
+Example:
+     [keyword]
+     # filename patterns for expansion are configured in this section
+     **.py =          ## expand keywords in all python files
+     x* = ignore      ## but ignore files matching "x*"
+     ** = archive     ## keywords in all textfiles are expanded
+                      ## when creating a distribution
+     y* = noarchive   ## keywords in files matching "y*" are not expanded
+                      ## on archive creation
+     ...
+     [keywordmaps]
+     # custom hg template maps _replace_ the CVS-like default ones
+     HGdate = {date|rfc822date}
+     lastlog = {desc} ## same as {desc|firstline} in this context
+     checked in by = {author}
+     ...
+
+If no [keywordmaps] are configured the extension falls back on the
+following defaults:
+
+     Revision: changeset id
+     Author: username
+     Date: %Y/%m/%d %H:%M:%S      ## [UTC]
+     RCSFile: basename,v
+     Source: /path/to/basename,v
+     Id: basename,v csetid %Y/%m/%d %H:%M:%S username
+     Header: /path/to/basename,v csetid %Y/%m/%d %H:%M:%S username
+
+no commands defined
+% cat
+expand $Id$
+ignore $Id$
+archive $Id$
+expand $Id$
+% default keyword expansion
+% commit
+adding a
+adding b
+adding c
+adding sym
+a
+b
+c
+sym
+overwriting a expanding keywords
+% status
+% cat
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+ignore $Id$
+archive $Id$
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+% hg cat
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+archive $Id$
+ignore $Id$
+a
+% update
+4 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% cat
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+ignore $Id$
+archive $Id$
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+% archive
+% cat
+expand $Id$
+ignore $Id$
+archive $Id: c,v 99e97605039e 1970/01/01 00:00:00 user $
+a
+% custom keyword expansion
+% cat
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+ignore $Id$
+archive $Id$
+expand $Id: a,v 99e97605039e 1970/01/01 00:00:00 user $
+% hg cat
+expand $Id: a 99e97605039e Thu, 01 Jan 1970 00:00:00 +0000 user $
+archive $Id$
+ignore $Id$
+a
+% commit
+a
+overwriting a expanding keywords
+% status
+% cat
+expand $Id: a 001dbcdc5258 Thu, 01 Jan 1970 00:00:01 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+ignore $Id$
+archive $Id$
+expand $Id: a 001dbcdc5258 Thu, 01 Jan 1970 00:00:01 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+% hg cat
+expand $Id: a 001dbcdc5258 Thu, 01 Jan 1970 00:00:01 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+archive $Id$
+ignore $Id$
+a
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 1 changesets with 4 changes to 4 files
+4 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% incoming
+searching for changes
+changeset:   1:001dbcdc5258
+tag:         tip
+user:        User Name <user at example.com>
+date:        Thu Jan 01 00:00:01 1970 +0000
+summary:     firstline
+
+% switch off expansion
+% cat
+expand $Id: a 001dbcdc5258 Thu, 01 Jan 1970 00:00:01 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+ignore $Id$
+archive $Id$
+expand $Id: a 001dbcdc5258 Thu, 01 Jan 1970 00:00:01 +0000 user $
+$Xinfo: User Name <user at example.com>: firstline $
+% hg cat
+expand $Id$
+$Xinfo$
+archive $Id$
+ignore $Id$
+a
+% update
+4 files updated, 0 files merged, 0 files removed, 0 files unresolved
+% cat
+expand $Id$
+$Xinfo$
+ignore $Id$
+archive $Id$
+expand $Id$
+$Xinfo$


More information about the Mercurial-devel mailing list