changeset 331:55f63f3b6a54

Add a simple testing framework -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Add a simple testing framework manifest hash: 9eeea72f2f33438040998a190183958764232ece -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCr0wKywK+sNU5EO8RAl9FAJ4o1QUA/YE2hCSlUPngR8h30hT1xQCgoEhu um2QkJOc2Rz7i6xTGPxuqzU= =YyUM -----END PGP SIGNATURE-----
author mpm@selenic.com
date Tue, 14 Jun 2005 13:28:42 -0800
parents 27d08c0c2a7e
children 6c869059beb4
files tests/README tests/run-tests tests/test-basic tests/test-basic.out tests/test-help tests/test-help.out tests/test-simple-update tests/test-simple-update.out tests/test-up-local-change tests/test-up-local-change.out
diffstat 12 files changed, 331 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/README	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,27 @@
+A simple testing framework
+
+This finds all scripts in the test directory named test-* and executes
+them. The scripts can be either shell scripts or Python. Each test is
+run in a temporary directory that is removed when the test is complete.
+
+A test-<x> succeeds if the script returns success and its output
+matches test-<x>.out. If the new output doesn't match, it is stored in
+test-<x>.err.
+
+There are some tricky points here that you should be aware of when
+writing tests:
+
+- hg commit and hg up -m want user interaction
+
+  for commit use -t "text"
+  for hg up -m, set HGMERGE to something noninteractive (like true or merge)
+
+- changeset hashes will change based on user and date which make
+  things like hg history output change
+
+  use commit -t "test" -u test -d "0 0"
+
+- diff will show the current time
+
+  use hg diff | sed "s/\(\(---\|+++\).*\)\t.*/\1/" to strip dates
+
--- a/tests/manifest-bug	Mon Jun 13 18:36:40 2005 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-#!/bin/sh -x
-
-set +e
-
-BASE=foo.base
-BR1=foo.br1
-BR2=foo.br2
-BR2_1=foo.br2_1
-
-mkdir $BASE
-cd $BASE
-hg init
-echo test > file
-hg add file
-EDITOR="echo 'initial commit' > " hg commit
-cd ..
-
-mkdir $BR1
-cd $BR1
-hg branch ../$BASE
-hg checkout
-echo test > file1
-hg addremove
-EDITOR="echo side commit >" hg commit
-cd ..
-
-mkdir $BR2
-cd $BR2
-hg branch ../$BASE
-hg checkout
-echo yet more >> file2
-hg addremove
-EDITOR="echo second update >" hg commit
-cd ..
-
-mkdir $BR2_1
-cd $BR2_1
-hg branch ../$BR2
-hg checkout
-EDITOR="echo commit merge >" hg merge ../$BR1
-
-hg checkout
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/run-tests	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+set -e
+
+tests=0
+failed=0
+H=$PWD
+
+for f in `ls test-* | grep -Ev "\.|~"` ; do
+    echo -n "."
+    D=`mktemp -d`
+    if [ "$D" == "" ] ; then
+	echo mktemp failed!
+    fi
+
+    cd $D
+    fail=0
+    if ! $H/$f > .out 2>&1 ; then
+	echo $f failed with error code $?
+	fail=1
+    fi
+    if [ -s .out -a ! -r $H/$f.out ] ; then
+	echo $f generated unexpected output:
+	cat .out
+	cp .out $H/$f.err
+	fail=1
+    elif ! diff -u $H/$f.out .out > /dev/null ; then
+	echo $f output changed:
+	diff -u $H/$f.out .out && true
+	cp .out $H/$f.err
+    fi
+
+    cd $H
+    rm -r $D
+
+    failed=$[$failed + $fail]
+    tests=$[$tests + 1]
+done
+
+echo
+echo Ran $tests tests, $failed failed
+
+if [ $failed -gt 0 ] ; then
+    exit 1
+fi
+
--- a/tests/simple-merge	Mon Jun 13 18:36:40 2005 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-set -ex
-export EDITOR=true
-rm -rf test branch
-
-mkdir test
-cd test
-echo foo>foo
-hg init
-hg addremove
-hg commit
-hg verify
-cd ..
-
-cp -a test branch
-cd branch
-echo bar>>foo
-hg commit
-
-cd ../test
-hg merge ../branch
-hg verify
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-basic	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -x
+mkdir t
+cd t
+hg init
+echo a > a
+hg add a
+hg commit -t "test" -u test -d "0 0"
+hg history
+hg manifest
+hg cat a
+hg verify
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-basic.out	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,22 @@
++ mkdir t
++ cd t
++ hg init
++ echo a
++ hg add a
++ hg commit -t test -u test -d '0 0'
++ hg history
+changeset:   0:acb14030fe0a21b60322c440ad2d20cf7685a376
+user:        test
+date:        Wed Dec 31 16:00:00 1969
+summary:     test
+
++ hg manifest
+b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 644 a
++ hg cat a
+a
++ hg verify
+checking changesets
+checking manifests
+crosschecking files in changesets and manifests
+checking files
+1 files, 1 changesets, 1 total revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-help	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+set -x
+
+hg help
+hg add -h
+hg help diff
+hg help foo
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-help.out	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,45 @@
++ hg help
+hg commands:
+
+ add         add the specified files on the next commit
+ addremove   add all new files, delete all missing files
+ annotate    show changeset information per file line
+ cat         output the latest or given revision of a file
+ commit      commit the specified files or all outstanding changes
+ diff        diff working directory (or selected files)
+ export      dump the changeset header and diffs for a revision
+ forget      don't add the specified files on the next commit
+ heads       show current repository heads
+ help        show help for a given command or all commands
+ history     show the changelog history
+ init        create a new repository or copy an existing one
+ log         show the revision history of a single file
+ manifest    output the latest or given revision of the project manifest
+ parents     show the parents of the current working dir
+ patch       import an ordered set of patches
+ pull        pull changes from the specified source
+ push        push changes to the specified destination
+ rawcommit   raw commit interface
+ recover     roll back an interrupted transaction
+ remove      remove the specified files on the next commit
+ serve       export the repository via HTTP
+ status      show changed files in the working directory
+ tags        list repository tags
+ tip         show the tip revision
+ undo        undo the last transaction
+ update      update or merge working directory
+ verify      verify the integrity of the repository
++ hg add -h
+hg add: option -h not recognized
+hg add [files]
+
+add the specified files on the next commit
++ hg help diff
+hg diff [-r A] [-r B] [files]
+
+ -r --rev 
+   revision
+
+diff working directory (or selected files)
++ hg help foo
+hg: unknown command foo
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-simple-update	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+set -ex
+
+mkdir test
+cd test
+echo foo>foo
+hg init
+hg addremove
+hg commit -t "1"
+hg verify
+cd ..
+
+mkdir branch
+cd branch
+hg init ../test
+hg co
+echo bar>>foo
+hg commit -t "2"
+
+cd ../test
+hg pull ../branch
+hg verify
+hg co
+cat foo
+hg manifest
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-simple-update.out	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,38 @@
++ mkdir test
++ cd test
++ echo foo
++ hg init
++ hg addremove
++ hg commit -t 1
++ hg verify
+checking changesets
+checking manifests
+crosschecking files in changesets and manifests
+checking files
+1 files, 1 changesets, 1 total revisions
++ cd ..
++ mkdir branch
++ cd branch
++ hg init ../test
++ hg co
++ echo bar
++ hg commit -t 2
++ cd ../test
++ hg pull ../branch
+searching for changes
+adding changesets
+adding manifests
+adding file revisions
+modified 1 files, added 1 changesets and 1 new revisions
++ hg verify
+checking changesets
+checking manifests
+crosschecking files in changesets and manifests
+checking files
+1 files, 2 changesets, 2 total revisions
++ hg co
++ cat foo
+foo
+bar
++ hg manifest
+6f4310b00b9a147241b071a60c28a650827fb03d 644 foo
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-up-local-change	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+export HGMERGE=true
+
+set -ex
+mkdir r1
+cd r1
+hg init
+echo a > a
+hg addremove
+hg commit -t "1" -u test -d "0 0"
+
+cd ..
+mkdir r2
+cd r2
+hg init ../r1
+hg up
+echo abc > a
+hg diff | sed "s/\(\(---\|+++\).*\)\t.*/\1/"
+
+cd ../r1
+echo b > b
+echo a2 > a
+hg addremove
+hg commit -t "2" -u test -d "0 0"
+
+cd ../r2
+hg -q pull ../r1
+hg status
+hg -d up
+hg -d up -m
+hg parents
+hg -v history
+hg diff | sed "s/\(\(---\|+++\).*\)\t.*/\1/"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-up-local-change.out	Tue Jun 14 13:28:42 2005 -0800
@@ -0,0 +1,70 @@
++ mkdir r1
++ cd r1
++ hg init
++ echo a
++ hg addremove
++ hg commit -t 1 -u test -d '0 0'
++ cd ..
++ mkdir r2
++ cd r2
++ hg init ../r1
++ hg up
++ echo abc
++ hg diff
++ sed 's/\(\(---\|+++\).*\)\t.*/\1/'
+--- a/a
++++ b/a
+@@ -1,1 +1,1 @@
+-a
++abc
++ cd ../r1
++ echo b
++ echo a2
++ hg addremove
++ hg commit -t 2 -u test -d '0 0'
++ cd ../r2
++ hg -q pull ../r1
++ hg status
+C a
++ hg -d up
+resolving manifests
+ ancestor a0c8bcbb local a0c8bcbb remote 1165e8bd
+ a versions differ, resolve
+remote created b
+getting b
+merging a
+resolving a
+file a: other d730145a ancestor b789fdd9
++ hg -d up -m
+resolving manifests
+ ancestor 1165e8bd local 1165e8bd remote 1165e8bd
++ hg parents
+changeset:   1:1e71731e6fbb5b35fae293120dea6964371c13c6
+user:        test
+date:        Wed Dec 31 16:00:00 1969
+summary:     2
+
++ hg -v history
+changeset:   1:1e71731e6fbb5b35fae293120dea6964371c13c6
+manifest:    1:1165e8bd193e17ad7d321d846fcf27ff3f412758
+user:        test
+date:        Wed Dec 31 16:00:00 1969
+files:       a b
+description:
+2
+
+changeset:   0:c19d34741b0a4ced8e4ba74bb834597d5193851e
+manifest:    0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0
+user:        test
+date:        Wed Dec 31 16:00:00 1969
+files:       a
+description:
+1
+
++ hg diff
++ sed 's/\(\(---\|+++\).*\)\t.*/\1/'
+--- a/a
++++ b/a
+@@ -1,1 +1,1 @@
+-a2
++abc