[PATCH 0/4] test: cleanups and suggestions

5 views
Skip to first unread message

Felipe Contreras

unread,
May 10, 2013, 1:37:36 AM5/10/13
to giti...@googlegroups.com, Max Horn, Dusty Phillips, Felipe Contreras
Hi,

I took a look at the new shareness tests, and I found some rather significant
issues and areas of improvement.

Rather than trying to explain why they are a problem, I wrote a simple test to
exemplify why

make_hg_repo &&
clone_repo &&
cd ..

is not a good idea.

Also proposals for make_hg_repo(), clone_repo(), make_hg_commit(), and
make_git_commit() that should do the same thing, albeit more cleanly.

Cheers.

Felipe Contreras (4):
test: trivial whitespace cleanups
test: trivial simplifications
test: turn on debugging only when it can be used
test: add basic test

test/test-lib.sh | 15 +++----
test/test_basic.t | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+), 7 deletions(-)
create mode 100755 test/test_basic.t

--
1.8.3.rc1.555.gd13b5a0

Felipe Contreras

unread,
May 10, 2013, 1:37:37 AM5/10/13
to giti...@googlegroups.com, Max Horn, Dusty Phillips, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
test/test-lib.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 856f198..0666e44 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -45,6 +45,7 @@ make_hg_commit() {
hg add $2 &&
hg commit -m "$1" --user="$user"
}
+
make_git_commit() {
echo "$1" >> "$2" &&
git add "$2" &&
@@ -84,6 +85,7 @@ assert_git_author() {
fi
test "`git show -s --format='%an <%ae>' $ref`" = "$1"
}
+
assert_git_count() {
if test $# -eq 2 ; then
ref=$2
@@ -92,6 +94,7 @@ assert_git_count() {
fi
test `git rev-list $ref --count` -eq $1
}
+
assert_hg_count() {
if test $# -eq 2 ; then
rev=$2
@@ -101,10 +104,10 @@ assert_hg_count() {
test `hg log -q -r 0:$rev | wc -l` -eq $1

}
+
assert_git_notes() {
git notes --ref=hg merge $(basename $(ls .git/refs/notes/hg-*)) &&
git log --pretty="format:%N" --notes='hg' | grep -v '^$'
echo $1
test "`git log --pretty="format:%N" --notes='hg' | grep -v '^$'`" = "$1"
-
-}
\ No newline at end of file
+}
--
1.8.3.rc1.555.gd13b5a0

Felipe Contreras

unread,
May 10, 2013, 1:37:38 AM5/10/13
to giti...@googlegroups.com, Max Horn, Dusty Phillips, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
test/test-lib.sh | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 0666e44..4112e94 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -9,13 +9,11 @@ export HG_USER="Hg User <hg....@example.com>"
export DEBUG_GITIFYHG=on
export GIT_PAGER=cat
export HGRCPATH='' # So extensions like pager don't interfere
-export NL='
-'
+export NL=$'\n'

make_hg_repo() {
- mkdir hg_repo &&
+ hg init hg_repo &&
cd hg_repo &&
- hg init &&
echo 'a\n' >> test_file &&
hg add test_file &&
hg commit --message="a" --user="$HG_USER"
--
1.8.3.rc1.555.gd13b5a0

Felipe Contreras

unread,
May 10, 2013, 1:37:39 AM5/10/13
to giti...@googlegroups.com, Max Horn, Dusty Phillips, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
test/test-lib.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 4112e94..cfd980a 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -6,7 +6,7 @@ export GIT_AUTHOR_EMAIL=git....@example.com
export GIT_AUTHOR_NAME='Git User'
export GIT_USER="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
export HG_USER="Hg User <hg....@example.com>"
-export DEBUG_GITIFYHG=on
+export DEBUG_GITIFYHG=$debug
export GIT_PAGER=cat
export HGRCPATH='' # So extensions like pager don't interfere
export NL=$'\n'
--
1.8.3.rc1.555.gd13b5a0

Felipe Contreras

unread,
May 10, 2013, 1:37:40 AM5/10/13
to giti...@googlegroups.com, Max Horn, Dusty Phillips, Felipe Contreras
To show the drawbacks of the current setup, and how it should be done
cleanly, like in git-remote-hg.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
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

Reply all
Reply to author
Forward
0 new messages