git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: jon.seymour@gmail.com
Subject: [PATCH 1/3] Add test cases for git-commit-script.
Date: Thu, 16 Jun 2005 00:38:08 +1000	[thread overview]
Message-ID: <20050615143808.27230.qmail@blackcubes.dyndns.org> (raw)


Adds some tests to show that git-commit-script behaves properly under a number
of different conditions.

The git-commit-script (f88a51a43ce2a3660fa82c13e502df429678d168) at Linus' HEAD
passes these tests.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---

 t/t1200-commit-script.sh |  153 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 insertions(+), 0 deletions(-)

diff --git a/t/t1200-commit-script.sh b/t/t1200-commit-script.sh
new file mode 100644
--- /dev/null
+++ b/t/t1200-commit-script.sh
@@ -0,0 +1,153 @@
+#!/bin/sh
+#
+# Copyright (C) 2005 Rene Scharfe
+# Copyright (C) 2005 Jon Seymour [ adapted to git-commit-script ]
+#
+
+test_description='git-commit-script
+
+This test checks that git-commit-script works as expected.
+'
+
+. ./test-lib.sh
+
+one_line()
+{
+echo "this is a commit test"
+}
+
+expected_commit ()
+{
+	tree=$1
+	shift 1
+cat <<EOF
+tree $tree
+EOF
+
+	for p in $*
+	do
+cat <<EOF
+parent $p
+EOF
+	done
+
+cat <<EOF
+author Author Name <author@email> 1117148400 +0000
+committer Committer Name <committer@email> 1117150200 +0000
+
+$(one_line)
+EOF
+}
+
+cat >add_one_line_editor <<EOF
+#!/bin/sh
+file=\$1
+echo "$(one_line)" >> \$file
+EOF
+
+cat >do_nothing_editor <<EOF
+#!/bin/sh
+:
+EOF
+
+cat >delete_sentinel_editor <<EOF
+#!/bin/sh
+file=\$1
+mv \$file \$file.\$\$
+sed "/^#SENTINEL/d" < \$file.\$\$ >\$file
+EOF
+
+chmod u+x add_one_line_editor
+chmod u+x do_nothing_editor
+chmod u+x delete_sentinel_editor
+
+: > foo
+: > bar
+
+run_with_vars()
+{
+     GIT_AUTHOR_NAME="Author Name" \
+     GIT_AUTHOR_EMAIL="author@email" \
+     GIT_AUTHOR_DATE="2005-05-26 23:00" \
+     GIT_COMMITTER_NAME="Committer Name" \
+     GIT_COMMITTER_EMAIL="committer@email" \
+     GIT_COMMITTER_DATE="2005-05-26 23:30" \
+     TZ= "$@" 2>/dev/null
+}
+
+test_phase1()
+{
+     condition=$1
+     editor=$2
+
+     test_expect_success \
+     "$condition - test preparation: add a file" \
+     'git-update-cache --add foo && git-write-tree > treeid'
+
+     test_expect_failure \
+     "$condition - Do not edit the commit message" \
+     "EDITOR=$editor run_with_vars git-commit-script"
+
+     test_expect_failure \
+     "$condition - No HEAD created when commit fails" \
+     '[ -f .git/HEAD ]'
+}
+
+test_phase2()
+{
+    condition=$1
+    editor=$2
+    test_expect_success \
+    "$condition - Single line message works" \
+    "EDITOR=$editor run_with_vars git-commit-script"
+
+    test_expect_success "$condition - HEAD created" '[ -f .git/HEAD ]'
+
+    test_expect_success \
+    "$condition - read commit 1" \
+    'git-cat-file commit HEAD >commit'
+
+    test_expect_success \
+    "$condition - compare commit" \
+    'expected_commit $(cat treeid) > expected && diff expected commit'
+
+    head=$(cat .git/HEAD)
+    test_expect_success \
+    "$condition - create a merge head" \
+    'merge_head=$(git-commit-tree $(cat treeid) -p HEAD < /dev/null)'
+
+    echo $merge_head > .git/MERGE_HEAD
+
+    test_expect_success \
+    "$condition - test preparation: write tree containing" \
+    'git-update-cache --add bar && git-write-tree > treeid.bar'
+
+}
+
+test_phase3()
+{
+    condition=$1
+    editor=$2
+
+    test_expect_success \
+    "$condition - write a tree with one merge head" \
+    "EDITOR=$editor run_with_vars git-commit-script"
+    
+    test_expect_success "$condition - MERGE_HEAD removed" '[ -f .git/HEAD ]'
+    test_expect_success "$condition - MERGE_HEAD removed by successful commit" '! [ -f .git/MERGE_HEAD ]'
+
+    test_expect_success \
+    "$condition - read commit 2" \
+    'git-cat-file commit HEAD >commit'
+
+    test_expect_success \
+    "$condition - compare commit 2" \
+    "expected_commit $(cat treeid.bar) ${head} ${merge_head} > expected && diff expected commit"
+
+}
+
+test_phase1 "simulated user" ./do_nothing_editor
+test_phase2 "simulated user" ./add_one_line_editor
+test_phase3 "simulated used" ./add_one_line_editor
+
+test_done
------------

                 reply	other threads:[~2005-06-15 14:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050615143808.27230.qmail@blackcubes.dyndns.org \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).