All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 2/2] Test for "stg edit"
Date: Tue, 08 Jul 2008 06:03:17 +0200	[thread overview]
Message-ID: <20080708040317.23134.667.stgit@yoghurt> (raw)
In-Reply-To: <20080708035750.23134.75833.stgit@yoghurt>

We weren't testing this comaratively complicated command at all. (And
not surprisingly, some corner cases that should have worked didn't.)

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 t/t3300-edit.sh |  205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)
 create mode 100755 t/t3300-edit.sh


diff --git a/t/t3300-edit.sh b/t/t3300-edit.sh
new file mode 100755
index 0000000..8304d9f
--- /dev/null
+++ b/t/t3300-edit.sh
@@ -0,0 +1,205 @@
+#!/bin/sh
+test_description='Test "stg edit"'
+
+. ./test-lib.sh
+
+test_expect_success 'Setup' '
+    printf "000\n111\n222\n" >> foo &&
+    git add foo &&
+    git commit -m "Initial commit" &&
+    sed -i "s/000/000xx/" foo &&
+    git commit -a -m "First change" &&
+    sed -i "s/111/111yy/" foo &&
+    git commit -a -m "Second change" &&
+    sed -i "s/222/222zz/" foo &&
+    git commit -a -m "Third change" &&
+    stg init &&
+    stg uncommit -n 3 p &&
+    stg pop
+'
+
+# Commit parse functions.
+msg () { git cat-file -p $1 | sed '1,/^$/d' | tr '\n' / | sed 's,/*$,,' ; }
+auth () { git log -n 1 --pretty=format:"%an, %ae" $1 ; }
+date () { git log -n 1 --pretty=format:%ai $1 ; }
+
+test_expect_success 'Edit message of top patch' '
+    test "$(msg HEAD)" = "Second change" &&
+    stg edit p2 -m "Second change 2" &&
+    test "$(msg HEAD)" = "Second change 2"
+'
+
+test_expect_success 'Edit message of non-top patch' '
+    test "$(msg HEAD^)" = "First change" &&
+    stg edit p1 -m "First change 2" &&
+    test "$(msg HEAD^)" = "First change 2"
+'
+
+test_expect_success 'Edit message of unapplied patch' '
+    test "$(msg $(stg id p3))" = "Third change" &&
+    stg edit p3 -m "Third change 2" &&
+    test "$(msg $(stg id p3))" = "Third change 2"
+'
+
+test_expect_success 'Set patch message with --file <file>' '
+    test "$(msg HEAD)" = "Second change 2" &&
+    echo "Pride or Prejudice" > commitmsg &&
+    stg edit p2 -f commitmsg &&
+    test "$(msg HEAD)" = "Pride or Prejudice"
+'
+
+test_expect_success 'Set patch message with --file -' '
+    echo "Pride and Prejudice" | stg edit p2 -f - &&
+    test "$(msg HEAD)" = "Pride and Prejudice"
+'
+
+( printf 'From: A U Thor <author@example.com>\nDate: <omitted>'
+  printf '\n\nPride and Prejudice' ) > expected-tmpl
+omit_date () { sed "s/^Date:.*$/Date: <omitted>/" ; }
+
+test_expect_success 'Save template to file' '
+    stg edit --save-template saved-tmpl p2 &&
+    omit_date < saved-tmpl > saved-tmpl-d &&
+    test_cmp expected-tmpl saved-tmpl-d
+'
+
+test_expect_success 'Save template to stdout' '
+    stg edit --save-template - p2 > saved-tmpl2 &&
+    omit_date < saved-tmpl2 > saved-tmpl2-d &&
+    test_cmp expected-tmpl saved-tmpl2-d
+'
+
+# Test the various ways of invoking the interactive editor. The
+# preference order should be
+#
+#   1. GIT_EDITOR
+#   2. stgit.editor (legacy)
+#   3. core.editor
+#   4. VISUAL
+#   5. EDITOR
+#   6. vi
+
+mkeditor ()
+{
+    cat > "$1" <<EOF
+#!/bin/sh
+printf "\n$1\n" >> "\$1"
+EOF
+    chmod a+x "$1"
+}
+
+mkeditor vi
+test_expect_failure 'Edit commit message interactively (vi)' '
+    m=$(msg HEAD) &&
+    PATH=.:$PATH stg edit p2 &&
+    test "$(msg HEAD)" = "$m/vi"
+'
+
+mkeditor e1
+test_expect_success 'Edit commit message interactively (EDITOR)' '
+    m=$(msg HEAD) &&
+    EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
+    echo $m && echo $(msg HEAD) &&
+    test "$(msg HEAD)" = "$m/e1"
+'
+
+mkeditor e2
+test_expect_failure 'Edit commit message interactively (VISUAL)' '
+    m=$(msg HEAD) &&
+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
+    test "$(msg HEAD)" = "$m/e2"
+'
+
+mkeditor e3
+test_expect_failure 'Edit commit message interactively (core.editor)' '
+    m=$(msg HEAD) &&
+    git config core.editor e3 &&
+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
+    test "$(msg HEAD)" = "$m/e3"
+'
+
+mkeditor e4
+test_expect_success 'Edit commit message interactively (stgit.editor)' '
+    m=$(msg HEAD) &&
+    git config stgit.editor e4 &&
+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
+    test "$(msg HEAD)" = "$m/e4"
+'
+
+mkeditor e5
+test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '
+    m=$(msg HEAD) &&
+    GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
+    test "$(msg HEAD)" = "$m/e5"
+'
+
+rm -f vi e1 e2 e3 e4 e5
+git config --unset core.editor
+git config --unset stgit.editor
+
+mkeditor twoliner
+test_expect_failure 'Both noninterative and interactive editing' '
+    EDITOR=./twoliner stg edit -e -m "oneliner" p2 &&
+    test "$(msg HEAD)" = "oneliner/twoliner"
+'
+rm -f twoliner
+
+cat > diffedit <<EOF
+#!/bin/sh
+sed -i 's/111yy/111YY/' "\$1"
+EOF
+chmod a+x diffedit
+test_expect_success 'Edit patch diff' '
+    EDITOR=./diffedit stg edit -d p2 &&
+    test "$(grep 111 foo)" = "111YY"
+'
+rm -f diffedit
+
+test_expect_success 'Sign a patch' '
+    m=$(msg HEAD) &&
+    stg edit --sign p2 &&
+    test "$(msg HEAD)" = "$m//Signed-off-by: C O Mitter <committer@example.com>"
+'
+
+test_expect_success 'Acknowledge a patch' '
+    m=$(msg HEAD^) &&
+    stg edit --ack p1 &&
+    test "$(msg HEAD^)" = "$m//Acked-by: C O Mitter <committer@example.com>"
+'
+
+test_expect_success 'Set author' '
+    stg edit p2 --author "Jane Austin <jaustin@example.com>" &&
+    test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
+'
+
+test_expect_success 'Fail to set broken author' '
+    command_error stg edit p2 --author "No Mail Address" &&
+    test "$(auth HEAD)" = "Jane Austin, jaustin@example.com"
+'
+
+test_expect_success 'Set author name' '
+    stg edit p2 --authname "Jane Austen" &&
+    test "$(auth HEAD)" = "Jane Austen, jaustin@example.com"
+'
+
+test_expect_success 'Set author email' '
+    stg edit p2 --authemail "jausten@example.com" &&
+    test "$(auth HEAD)" = "Jane Austen, jausten@example.com"
+'
+
+test_expect_failure 'Set author date (RFC2822 format)' '
+    stg edit p2 --authdate "Wed, 10 Jul 2013 23:39:00 pm -0300" &&
+    test "$(date HEAD)" = "2013-07-10 23:39:00 -0300"
+'
+
+test_expect_failure 'Set author date (ISO 8601 format)' '
+    stg edit p2 --authdate "2013-01-28 22:30:00 -0300" &&
+    test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"
+'
+
+test_expect_failure 'Fail to set invalid author date' '
+    command_error stg edit p2 --authdate "28 Jan 1813" &&
+    test "$(date HEAD)" = "2013-01-28 22:30:00 -0300"
+'
+
+test_done

      parent reply	other threads:[~2008-07-08  4:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08  4:03 [StGit PATCH 0/2] Test improvements Karl Hasselström
2008-07-08  4:03 ` [StGit PATCH 1/2] Test for specific exit code Karl Hasselström
2008-07-08  4:03 ` Karl Hasselström [this message]

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=20080708040317.23134.667.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.