Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 250:9a3dacfc3be6
Mercurial unit-tests for the "kwarchive" extension
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sun, 06 Jan 2019 18:23:12 +0100 |
| parents | e97f6f6ed7c5 |
| children | e19782e7b21c |
| files | .hgignore tests/lib-test-kwarchive.sh tests/test-kwarchive.t |
| diffstat | 3 files changed, 412 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Jan 06 17:27:17 2019 +0100 +++ b/.hgignore Sun Jan 06 18:23:12 2019 +0100 @@ -2,3 +2,5 @@ *.pyc *.pyo +tests/.testtimes +_tmp/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/lib-test-kwarchive.sh Sun Jan 06 18:23:12 2019 +0100 @@ -0,0 +1,139 @@ +#!/bin/sh + +# +# Preconditions for a manual setup: +# +# - cd tests +# - . ./lib-test-kwarchive.sh +# - TESTDIR=`pwd`; export TESTDIR +# + +# +# Prepare a "canonical" repository for testing the kwarchive extension +# +# prepare_repo REPO +# +prepare_repo() { + if [ -z "$TESTDIR" ]; then + echo "TESTDIR is not set" + return 1 + else + if [ ! -f "$TESTDIR/../extensions/kwarchive.py" ]; then + echo "Wrong TESTDIR setup" + return 1 + fi + LOCAL_TESTDIR="$TESTDIR" + fi + if [ -z "$HGRCPATH" ]; then + # + # Check whether we are running in the context of Mercurial's + # run-tests.py + # + if [ "$TESTTMP" = "$HOME" ]; then + echo "HGRCPATH is not set" + return 1 + else + # Path after changing wd into $1 + LOCAL_HGRCPATH=".hg/hgrc" + fi + else + LOCAL_HGRCPATH="$HGRCPATH" + fi + hg init "$1" + cd "$1" + cat >.hgkwarchive <<EOF +[patterns] +src/**.py = RCS, reST +path:VERSION = reST +path:README = RCS, reST +path:test2.txt = RCS, reST + +[keywords] +JustDate = +HGheader = +HGnodeid = +Date = +Revision = +HGrevision = +Author = + +MyFullRevision = HGrevision + +MySubstKeyword = replace:: This is a custom replacement +EOF + cat >>$LOCAL_HGRCPATH <<EOF +[extensions] +kwarchive=$LOCAL_TESTDIR/../extensions/kwarchive.py +[ui] +username=First Second <first.second@example.com> +[paths] +default=https://theuser:thepass@hg.example.com:4443/repo.hg +EOF + unset HGUSER + unset EMAIL + hg add .hgkwarchive + hg commit -m 'Activate kwarchive' + + cat >>VERSION <<\EOF +0.0.dev1 +|VCSMyFullRevision| +EOF + cat >>README <<\EOF +.. -*- coding: utf-8 -*- + + +Testing the kwarchive extension +=============================== + +:Author: Franz Glasner +:When: $Date$ +:Date: |VCSJustDate| +:ID: @(#) $HGheader$ + +EOF + cat >>test2.txt <<\EOF +This is a file with some replacement tests + +$HGheader$ +$HGnodeid$ +$Date$ +$JustDate$ +$HGrevision$ +$Revision$ +$Author$ + +$MySubstKeyword$ +|VCSMySubstKeyword| +EOF + # not to be expanded + cp test2.txt test2-not-expanded.txt + mkdir src + cat >>src/f1.py <<\EOF +# -*- coding: utf-8 -*- +# f1.py +# @(#) $HGheader$ +# $HGnodeid$ +# +__revision__ = "$Revision$" +__author__ = "Franz Glasner" + +EOF + cp src/f1.py src/f1.txt + cat >>src/f2.py <<\EOF +# -*- coding: utf-8 -*- +# f2.py +# @(#) $HGheader$ +# $HGnodeid$ +# +__revision__ = "$Revision$" +__author__ = "Franz Glasner" + +EOF + cp src/f2.py src/f2.txt + hg add VERSION README test2.txt test2-not-expanded.txt + hg ci -m 'First part of files: VERSION, README, test2.txt' + hg add --quiet src/ + hg ci -m 'All files in src' + + cd .. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-kwarchive.t Sun Jan 06 18:23:12 2019 +0100 @@ -0,0 +1,271 @@ + +Setup + + $ . $TESTDIR/lib-test-kwarchive.sh + $ prepare_repo "repo1" + $ cd "repo1" + +kwprint (defaults -- nopwd/user) + + $ hg kwprint --path=. + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: file://$TESTTMP/repo1 $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: file://$TESTTMP/repo1/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + +kwprint full + + $ hg kwprint --path=. --path-filter=full --user-filter=full + $Author: First+Second+<first.second@example.com> $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: file://$TESTTMP/repo1 $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + $HGid: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: file://$TESTTMP/repo1/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + $Source: dir1/dir2/test.file $ + +kwprint last/person + + $ hg kwprint --path=. --user-filter=person --path-filter=last + $Author: First+Second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: .../repo1 $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: .../repo1/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 First+Second draft $ + $HGid: .../repo1/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: .../repo1/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 First+Second draft $ + $Source: dir1/dir2/test.file $ + +kwprint short/email + + $ hg kwprint --path=. --user-filter=email --path-filter=short + $Author: first.second@example.com $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: file://$TESTTMP/repo1 $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second@example.com draft $ + $HGid: file://$TESTTMP/repo1/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second@example.com draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: file://$TESTTMP/repo1/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second@example.com draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second@example.com draft $ + $Source: dir1/dir2/test.file $ + +kwprint with default path (short) + + $ hg kwprint + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: hg+https://hg/repo.hg $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: hg+https://hg/repo.hg/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: hg+https://hg/repo.hg/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: hg+https://hg/repo.hg/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + + +kwprint with full default path + + $ hg kwprint --path-filter=full + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: https://theuser:thepass@hg.example.com:4443/repo.hg $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: https://theuser:thepass@hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: https://theuser:thepass@hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: https://theuser:thepass@hg.example.com:4443/repo.hg/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + +kwprint with nopwd default path + + $ hg kwprint --path-filter=nopwd + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: https://theuser:***@hg.example.com:4443/repo.hg $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: https://theuser:***@hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: https://theuser:***@hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: https://theuser:***@hg.example.com:4443/repo.hg/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + +kwprint with nouser default path + + $ hg kwprint --path-filter=nouser + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: https://hg.example.com:4443/repo.hg $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: https://hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: https://hg.example.com:4443/repo.hg/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: https://hg.example.com:4443/repo.hg/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + +kwprint with "last" path + + $ hg kwprint --path-filter=last + $Author: first.second $ + $Date: 1970-01-01 00:00:00 +0000 $ + $HGbookmarks: $ + $HGbranch: default $ + $HGpath: .../repo.hg $ + $HGrevision: 8c27876b79524a660c64a133b3d72361cdc947e4 $ + $HGshortdate: 1970-01-01 $ + $HGtags: $ + $JustDate: 1970-01-01 $ + $Revision: 8c27876b7952 $ + $State: draft $ + (?) + $File: test.file $ + $HGheader: .../repo.hg/dir1/dir2/test.file 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 first.second draft $ + $HGid: .../repo.hg/dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $ + $HGsource: .../repo.hg/dir1/dir2/test.file $ + $Header: dir1/dir2/test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Id: test.file 8c27876b7952 1970-01-01 00:00:00 +0000 first.second draft $ + $Source: dir1/dir2/test.file $ + + +Archiving ... + + $ hg kwarchive --path-filter=full --user-filter=full _archive + +... check not expanded files for identity + + $ cmp .hgkwarchive _archive/.hgkwarchive + $ cmp test2-not-expanded.txt _archive/test2-not-expanded.txt + $ cmp src/f1.txt _archive/src/f1.txt + $ cmp src/f2.txt _archive/src/f2.txt + +.. check expanded files + + $ cat _archive/VERSION + 0.0.dev1 + 8c27876b79524a660c64a133b3d72361cdc947e4 + $ cat _archive/README + .. -*- coding: utf-8 -*- + (?) + (?) + Testing the kwarchive extension + =============================== + (?) + :Author: Franz Glasner + :When: $Date: 1970-01-01 00:00:00 +0000 $ + :Date: 1970-01-01 + :ID: @(#) $HGheader: https://theuser:thepass@hg.example.com:4443/repo.hg/README 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + (?) + $ cat _archive/src/f1.py + # -*- coding: utf-8 -*- + # f1.py + # @(#) $HGheader: https://theuser:thepass@hg.example.com:4443/repo.hg/src/f1.py 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + # $HGnodeid: d1aadfd82662afe0cb942b8ff3bc39112c5bb2cd $ + # + __revision__ = "$Revision: 8c27876b7952 $" + __author__ = "Franz Glasner" + (?) + $ cat _archive/src/f2.py + # -*- coding: utf-8 -*- + # f2.py + # @(#) $HGheader: https://theuser:thepass@hg.example.com:4443/repo.hg/src/f2.py 8c27876b79524a660c64a133b3d72361cdc947e4 1970-01-01 00:00:00 +0000 First+Second+<first.second@example.com> draft $ + # $HGnodeid: 8cee1e6f9d9a53eb720ab3b1dddd025db992bc76 $ + # + __revision__ = "$Revision: 8c27876b7952 $" + __author__ = "Franz Glasner" + (?)
