To show the drawbacks of the current setup, and how it should be done
cleanly, like in git-remote-hg.
test/test_basic.t | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
create mode 100755 test/test_basic.t
diff --git a/test/test_basic.t b/test/test_basic.t
new file mode 100755
index 0000000..71ce31c
--- /dev/null
+++ b/test/test_basic.t
@@ -0,0 +1,121 @@
+#!/bin/sh
+
+test_description='Basic tests'
+
+. ./test-lib.sh
+
+setup () {
+ (
+ echo "[ui]"
+ echo "username = $HG_USER"
+ ) >> "$HOME"/.hgrc
+ unset HGRCPATH # it cannot conflict with extensions, because we need to enable them first
+}
+
+setup
+
+new_make_hg_repo () {
+ (
+ hg init hg_repo &&
+ cd hg_repo &&
+ echo "a" >> test_file &&
+ hg add test_file &&
+ hg commit -m "a"
+ )
+}
+
+new_clone_repo () {
+ git clone "testgitifyhg::hg_repo" git_clone
+}
+
+new_make_hg_commit() {
+ if test $# -eq 3; then
+ user_arg="--user=$3"
+ fi
+ echo "$1" >> $2 &&
+ hg add $2 &&
+ hg commit -m "$1" "${user_arg:-}"
+}
+
+new_make_git_commit() {
+ echo "$1" >> "$2" &&
+ git add "$2" &&
+ git commit -m "$1"
+}
+
+check_cleanup () {
+ test_expect_${2:-success} "$1" '
+ dir="$SHARNESS_TRASH_DIRECTORY" &&
+ ! test -d "$dir"/hg_repo &&
+ ! test -d "$dir"/git_clone &&
+ test "$PWD" == "$dir"
+ '
+}
+
+test_expect_failure 'good test' '
+ test_when_finished "rm -rf hg_repo" &&
+
+ (
+ make_hg_repo &&
+ false
+ )
+'
+
+check_cleanup 'check good test'
+
+test_expect_failure 'bad test' '
+ test_when_finished "rm -rf hg_repo" &&
+
+ make_hg_repo &&
+ false &&
+ cd ..
+'
+
+check_cleanup 'check bad test' failure
+
+test_expect_success 'reset' '
+ cd "$SHARNESS_TRASH_DIRECTORY" &&
+ rm -rf hg_repo &&
+ test "$PWD" == "$SHARNESS_TRASH_DIRECTORY"
+'
+
+cat > expected <<EOF
+Git User <
git....@example.com> d
+A U Thor <
aut...@example.com> c
+Hg User <
hg....@example.com> b
+Hg User <
hg....@example.com> a
+EOF
+
+test_expect_success 'old setup' '
+ test_when_finished "rm -rf hg_repo git_clone" &&
+
+ (
+ make_hg_repo &&
+ make_hg_commit b test_file &&
+ make_hg_commit c test_file "A U Thor <
aut...@example.com>" &&
+ clone_repo &&
+ make_git_commit d test_file &&
+ git log --format="%an <%ae> %s" > actual &&
+ test_cmp ../expected actual
+ )
+'
+
+test_expect_success 'new setup' '
+ test_when_finished "rm -rf hg_repo git_clone" &&
+
+ (
+ new_make_hg_repo &&
+ cd hg_repo &&
+ new_make_hg_commit b test_file &&
+ new_make_hg_commit c test_file "A U Thor <
aut...@example.com>"
+ ) &&
+ (
+ new_clone_repo &&
+ cd git_clone &&
+ new_make_git_commit d test_file
+ ) &&
+ git --git-dir=git_clone/.git log --format="%an <%ae> %s" > actual &&
+ test_cmp expected actual
+'
+
+test_done
--
1.8.3.rc1.555.gd13b5a0