diff tests/lib-test-kwarchive.sh @ 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
children b8fc7f0990e7
line wrap: on
line diff
--- /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 ..
+}