{"thread":{"id":"14338","subject":"[StGit PATCH 1/2] Test for specific exit code","startedAt":"2008-07-08T04:03:04Z","lastAt":"2008-07-08T04:03:17Z","messageCount":3,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"82535","messageId":"20080708035750.23134.75833.stgit@yoghurt","threadId":"14338","inReplyTo":null,"subject":"[StGit PATCH 0/2] Test improvements","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-07-08T04:03:04Z","receivedAt":"2008-07-08T04:03:04Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"First, a change across all the tests to make sure that stg always\nexits with the correct exit code even when it's not zero. This lets us\ndetect the difference between a controlled failure and a crash.\n\nSecond, a rather comprehensive test fir \"stg edit\" -- we didn't test\nit at all. Which can be seen in the number of failures in this test.\n\nThey are available in kha/safe. The patches in kha/experimental have\nbeen rebased on top of these, resulting in a number of new test\nfailures that I've had to fix.\n\n---\n\nKarl Hasselström (2):\n      Test for \"stg edit\"\n      Test for specific exit code\n\n\n t/README                    |    6 +\n t/t0001-subdir-branches.sh  |   12 +--\n t/t0002-status.sh           |    2 \n t/t1000-branch-create.sh    |    8 +-\n t/t1001-branch-rename.sh    |    2 \n t/t1002-branch-clone.sh     |    2 \n t/t1200-push-modified.sh    |    2 \n t/t1202-push-undo.sh        |    4 -\n t/t1203-push-conflict.sh    |    4 -\n t/t1205-push-subdir.sh      |    4 -\n t/t1301-repair.sh           |    2 \n t/t1302-repair-interop.sh   |    4 -\n t/t1400-patch-history.sh    |    2 \n t/t1501-sink.sh             |    2 \n t/t1600-delete-one.sh       |    4 -\n t/t1601-delete-many.sh      |    2 \n t/t2000-sync.sh             |    4 -\n t/t2101-pull-policy-pull.sh |    2 \n t/t2200-rebase.sh           |    2 \n t/t2500-clean.sh            |    2 \n t/t2900-rename.sh           |    8 +-\n t/t3000-dirty-merge.sh      |    2 \n t/t3300-edit.sh             |  205 +++++++++++++++++++++++++++++++++++++++++++\n t/t4000-upgrade.sh          |    2 \n t/test-lib.sh               |   24 +++++\n 25 files changed, 271 insertions(+), 42 deletions(-)\n create mode 100755 t/t3300-edit.sh\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"82534","messageId":"20080708040311.23134.76097.stgit@yoghurt","threadId":"14338","inReplyTo":"20080708035750.23134.75833.stgit@yoghurt","subject":"[StGit PATCH 1/2] Test for specific exit code","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-07-08T04:03:11Z","receivedAt":"2008-07-08T04:03:11Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"When a command is supposed to fail in a test, test for the exact error\ncode we're expecting, not just that it's non-zero. This makes sure\ne.g. that a command that's supposed to fail doesn't do so with an\nunhandled exception.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n t/README                    |    6 +++---\n t/t0001-subdir-branches.sh  |   12 ++++++------\n t/t0002-status.sh           |    2 +-\n t/t1000-branch-create.sh    |    8 ++++----\n t/t1001-branch-rename.sh    |    2 +-\n t/t1002-branch-clone.sh     |    2 +-\n t/t1200-push-modified.sh    |    2 +-\n t/t1202-push-undo.sh        |    4 ++--\n t/t1203-push-conflict.sh    |    4 ++--\n t/t1205-push-subdir.sh      |    4 ++--\n t/t1301-repair.sh           |    2 +-\n t/t1302-repair-interop.sh   |    4 ++--\n t/t1400-patch-history.sh    |    2 +-\n t/t1501-sink.sh             |    2 +-\n t/t1600-delete-one.sh       |    4 ++--\n t/t1601-delete-many.sh      |    2 +-\n t/t2000-sync.sh             |    4 ++--\n t/t2101-pull-policy-pull.sh |    2 +-\n t/t2200-rebase.sh           |    2 +-\n t/t2500-clean.sh            |    2 +-\n t/t2900-rename.sh           |    8 ++++----\n t/t3000-dirty-merge.sh      |    2 +-\n t/t4000-upgrade.sh          |    2 +-\n t/test-lib.sh               |   24 ++++++++++++++++++++++++\n 24 files changed, 66 insertions(+), 42 deletions(-)\n\n\ndiff --git a/t/README b/t/README\nindex 77f0b6c..757f810 100644\n--- a/t/README\n+++ b/t/README\n@@ -163,9 +163,9 @@ library for your script to use.\n    yields success, test is considered a failure.\n \n    This should _not_ be used for tests that succeed when their\n-   commands fail -- use test_expect_success and shell negation (!) for\n-   that. test_expect_failure is for cases when a test is known to be\n-   broken.\n+   commands fail -- use test_expect_success and one of general_error,\n+   command_error, and conflict for that. test_expect_failure is for\n+   cases when a test is known to be broken.\n \n  - test_debug <script>\n \ndiff --git a/t/t0001-subdir-branches.sh b/t/t0001-subdir-branches.sh\nindex 0eed3a4..69c11a3 100755\n--- a/t/t0001-subdir-branches.sh\n+++ b/t/t0001-subdir-branches.sh\n@@ -39,9 +39,9 @@ test_expect_success 'Try new form of id with slashy branch' \\\n    stg id foo@x/y/z//top'\n \n test_expect_success 'Try old id with slashy branch' '\n-   ! stg id foo/ &&\n-   ! stg id foo/top &&\n-   ! stg id foo@x/y/z/top\n+   command_error stg id foo/ &&\n+   command_error stg id foo/top &&\n+   command_error stg id foo@x/y/z/top\n    '\n \n test_expect_success 'Create patch in slashy branch' \\\n@@ -51,11 +51,11 @@ test_expect_success 'Create patch in slashy branch' \\\n \n test_expect_success 'Rename branches' \\\n   'stg branch --rename master goo/gaa &&\n-   ! git show-ref --verify --quiet refs/heads/master &&\n+   must_fail git show-ref --verify --quiet refs/heads/master &&\n    stg branch --rename goo/gaa x1/x2/x3/x4 &&\n-   ! git show-ref --verify --quiet refs/heads/goo/gaa &&\n+   must_fail git show-ref --verify --quiet refs/heads/goo/gaa &&\n    stg branch --rename x1/x2/x3/x4 servant &&\n-   ! git show-ref --verify --quiet refs/heads/x1/x2/x3/x4\n+   must_fail git show-ref --verify --quiet refs/heads/x1/x2/x3/x4\n '\n \n test_done\ndiff --git a/t/t0002-status.sh b/t/t0002-status.sh\nindex 4364709..d9cb2cc 100755\n--- a/t/t0002-status.sh\n+++ b/t/t0002-status.sh\n@@ -114,7 +114,7 @@ A fie\n C foo/bar\n EOF\n test_expect_success 'Status after conflicting push' '\n-    ! stg push &&\n+    conflict_old stg push &&\n     stg status > output.txt &&\n     test_cmp expected.txt output.txt\n '\ndiff --git a/t/t1000-branch-create.sh b/t/t1000-branch-create.sh\nindex 5a097a4..3fff3ee 100755\n--- a/t/t1000-branch-create.sh\n+++ b/t/t1000-branch-create.sh\n@@ -26,7 +26,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Try to create an stgit branch with a spurious patches/ entry' '\n-    ! stg branch -c foo1\n+    command_error stg branch -c foo1\n '\n \n test_expect_success \\\n@@ -43,7 +43,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Try to create an stgit branch with an existing git branch by that name' '\n-    ! stg branch -c foo2\n+    command_error stg branch -c foo2\n '\n \n test_expect_success \\\n@@ -58,7 +58,7 @@ test_expect_success \\\n test_expect_success \\\n     'Create an invalid refs/heads/ entry' '\n     touch .git/refs/heads/foo3 &&\n-    ! stg branch -c foo3\n+    command_error stg branch -c foo3\n '\n \n test_expect_failure \\\n@@ -87,7 +87,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Create branch down the stack, behind the conflict caused by the generated file' '\n-    ! stg branch --create foo4 master^\n+    command_error stg branch --create foo4 master^\n '\n \n test_expect_success \\\ndiff --git a/t/t1001-branch-rename.sh b/t/t1001-branch-rename.sh\nindex dd12132..d5d3aef 100755\n--- a/t/t1001-branch-rename.sh\n+++ b/t/t1001-branch-rename.sh\n@@ -19,7 +19,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Rename the current stgit branch' \\\n-    '! stg branch -r foo bar\n+    'command_error stg branch -r foo bar\n '\n \n test_expect_success \\\ndiff --git a/t/t1002-branch-clone.sh b/t/t1002-branch-clone.sh\nindex b0087e9..19bdc45 100755\n--- a/t/t1002-branch-clone.sh\n+++ b/t/t1002-branch-clone.sh\n@@ -21,7 +21,7 @@ test_expect_success \\\n test_expect_success \\\n     'Try to create a patch in a GIT branch' \\\n     '\n-    ! stg new p0 -m \"p0\"\n+    command_error stg new p0 -m \"p0\"\n     '\n \n test_expect_success \\\ndiff --git a/t/t1200-push-modified.sh b/t/t1200-push-modified.sh\nindex ba4f70c..6ebd0a1 100755\n--- a/t/t1200-push-modified.sh\n+++ b/t/t1200-push-modified.sh\n@@ -49,7 +49,7 @@ test_expect_success \\\n \n test_expect_success \\\n     'Attempt to push the first of those patches without --merged' \\\n-    \"(cd bar && ! stg push\n+    \"(cd bar && conflict_old stg push\n      )\n \"\n \ndiff --git a/t/t1202-push-undo.sh b/t/t1202-push-undo.sh\nindex b602643..544fe8d 100755\n--- a/t/t1202-push-undo.sh\n+++ b/t/t1202-push-undo.sh\n@@ -43,7 +43,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Push the second patch with conflict' \\\n \t'\n-\t! stg push bar\n+\tconflict_old stg push bar\n \t'\n \n test_expect_success \\\n@@ -55,7 +55,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Check the push after undo fails as well' \\\n \t'\n-\t! stg push bar\n+\tconflict_old stg push bar\n \t'\n \n test_expect_success \\\ndiff --git a/t/t1203-push-conflict.sh b/t/t1203-push-conflict.sh\nindex 72bd49f..96fee15 100755\n--- a/t/t1203-push-conflict.sh\n+++ b/t/t1203-push-conflict.sh\n@@ -38,7 +38,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Push the first patch with conflict' \\\n \t'\n-\t! stg push foo\n+\tconflict_old stg push foo\n \t'\n \n test_expect_success \\\n@@ -56,7 +56,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Check that pop will fail while there are unmerged conflicts' \\\n \t'\n-\t! stg pop\n+\tcommand_error stg pop\n \t'\n \n test_expect_success \\\ndiff --git a/t/t1205-push-subdir.sh b/t/t1205-push-subdir.sh\nindex 175d36d..945eb74 100755\n--- a/t/t1205-push-subdir.sh\n+++ b/t/t1205-push-subdir.sh\n@@ -47,7 +47,7 @@ test_expect_success 'Conflicting push from subdir' '\n     [ \"$(echo $(cat x.txt))\" = \"x0\" ] &&\n     [ \"$(echo $(cat foo/y.txt))\" = \"y0\" ] &&\n     cd foo &&\n-    ! stg push p2 &&\n+    conflict_old stg push p2 &&\n     cd .. &&\n     [ \"$(echo $(stg status --conflict))\" = \"foo/y.txt x.txt\" ]\n '\n@@ -62,7 +62,7 @@ test_expect_success 'Conflicting add/unknown file in subdir' '\n     stg pop &&\n     mkdir -p d &&\n     echo bar > d/test &&\n-    ! stg push foo &&\n+    command_error stg push foo &&\n     [ $(stg top) != \"foo\" ]\n '\n \ndiff --git a/t/t1301-repair.sh b/t/t1301-repair.sh\nindex b555b93..33f8f6d 100755\n--- a/t/t1301-repair.sh\n+++ b/t/t1301-repair.sh\n@@ -5,7 +5,7 @@ test_description='Test the repair command.'\n \n test_expect_success \\\n     'Repair in a non-initialized repository' \\\n-    '! stg repair'\n+    'command_error stg repair'\n \n test_expect_success \\\n     'Initialize the StGIT repository' \\\ndiff --git a/t/t1302-repair-interop.sh b/t/t1302-repair-interop.sh\nindex 82c5ed2..3ea48e7 100755\n--- a/t/t1302-repair-interop.sh\n+++ b/t/t1302-repair-interop.sh\n@@ -27,7 +27,7 @@ test_expect_success 'Create five patches' '\n \n test_expect_success 'Pop two patches with git-reset' '\n     git reset --hard HEAD~2 &&\n-    ! stg refresh &&\n+    command_error stg refresh &&\n     stg repair &&\n     stg refresh &&\n     [ \"$(echo $(stg applied))\" = \"p0 p1 p2\" ] &&\n@@ -42,7 +42,7 @@ test_expect_success 'Create a new patch' '\n \n test_expect_success 'Go to an unapplied patch with with git-reset' '\n     git reset --hard $(stg id p3) &&\n-    ! stg refresh &&\n+    command_error stg refresh &&\n     stg repair &&\n     stg refresh &&\n     [ \"$(echo $(stg applied))\" = \"p0 p1 p2 p3\" ] &&\ndiff --git a/t/t1400-patch-history.sh b/t/t1400-patch-history.sh\nindex a693e75..13cd1e3 100755\n--- a/t/t1400-patch-history.sh\n+++ b/t/t1400-patch-history.sh\n@@ -82,7 +82,7 @@ test_expect_success \\\n \techo bar > test && stg refresh &&\n \tstg pop &&\n \techo foo > test && stg refresh &&\n-\t! stg push &&\n+\tconflict_old stg push &&\n \tstg log --full | grep -q -e \"^push(c) \"\n \t'\n \ndiff --git a/t/t1501-sink.sh b/t/t1501-sink.sh\nindex 6af45fe..ac9e25d 100755\n--- a/t/t1501-sink.sh\n+++ b/t/t1501-sink.sh\n@@ -17,7 +17,7 @@ test_expect_success 'Initialize StGit stack' '\n '\n \n test_expect_success 'sink without applied patches' '\n-    ! stg sink\n+    command_error stg sink\n '\n \n test_expect_success 'sink a specific patch without applied patches' '\ndiff --git a/t/t1600-delete-one.sh b/t/t1600-delete-one.sh\nindex c3451d8..b526a55 100755\n--- a/t/t1600-delete-one.sh\n+++ b/t/t1600-delete-one.sh\n@@ -20,7 +20,7 @@ test_expect_success \\\n     'Try to delete a non-existing patch' \\\n     '\n     [ $(stg applied | wc -l) -eq 1 ] &&\n-    ! stg delete bar &&\n+    command_error stg delete bar &&\n     [ $(stg applied | wc -l) -eq 1 ]\n     '\n \n@@ -29,7 +29,7 @@ test_expect_success \\\n     '\n     echo dirty >> foo.txt &&\n     [ $(stg applied | wc -l) -eq 1 ] &&\n-    ! stg delete foo &&\n+    command_error stg delete foo &&\n     [ $(stg applied | wc -l) -eq 1 ] &&\n     git reset --hard\n     '\ndiff --git a/t/t1601-delete-many.sh b/t/t1601-delete-many.sh\nindex 30b0a1d..bc5364f 100755\n--- a/t/t1601-delete-many.sh\n+++ b/t/t1601-delete-many.sh\n@@ -37,7 +37,7 @@ test_expect_success \\\n     '\n     [ \"$(echo $(stg applied))\" = \"p0 p1 p2\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"p5 p8 p9\" ] &&\n-    ! stg delete p7 p8 p2 p0 &&\n+    command_error stg delete p7 p8 p2 p0 &&\n     [ \"$(echo $(stg applied))\" = \"p0 p1 p2\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"p5 p8 p9\" ]\n     '\ndiff --git a/t/t2000-sync.sh b/t/t2000-sync.sh\nindex e489603..9852eb8 100755\n--- a/t/t2000-sync.sh\n+++ b/t/t2000-sync.sh\n@@ -109,7 +109,7 @@ test_expect_success \\\n test_expect_success \\\n     'Synchronise the first two patches with the master branch (to fail)' \\\n     '\n-    ! stg sync -B master -a\n+    conflict_old stg sync -B master -a\n     '\n \n test_expect_success \\\n@@ -127,7 +127,7 @@ test_expect_success \\\n test_expect_success \\\n     'Synchronise the third patch with the exported series (to fail)' \\\n     '\n-    ! stg sync -s patches-master/series p3\n+    conflict_old stg sync -s patches-master/series p3\n     '\n \n test_expect_success \\\ndiff --git a/t/t2101-pull-policy-pull.sh b/t/t2101-pull-policy-pull.sh\nindex ce4b5c8..777ccb5 100755\n--- a/t/t2101-pull-policy-pull.sh\n+++ b/t/t2101-pull-policy-pull.sh\n@@ -43,7 +43,7 @@ test_expect_success \\\n     'Rewind/rewrite upstream commit and pull it from clone, without --merged' \\\n     '\n     (cd upstream && echo b >> file2 && stg refresh) &&\n-    (cd clone && ! stg pull)\n+    (cd clone && conflict_old stg pull)\n     '\n \n test_expect_success \\\ndiff --git a/t/t2200-rebase.sh b/t/t2200-rebase.sh\nindex ec2a104..a6f43bc 100755\n--- a/t/t2200-rebase.sh\n+++ b/t/t2200-rebase.sh\n@@ -34,7 +34,7 @@ test_expect_success \\\n test_expect_success \\\n \t'Attempt rebase to non-existing commit' \\\n \t'\n-\t! stg rebase not-a-ref\n+\tcommand_error stg rebase not-a-ref\n \t'\n \n test_expect_success \\\ndiff --git a/t/t2500-clean.sh b/t/t2500-clean.sh\nindex ad8f892..abde9cf 100755\n--- a/t/t2500-clean.sh\n+++ b/t/t2500-clean.sh\n@@ -32,7 +32,7 @@ test_expect_success 'Create a conflict' '\n     stg new p2 -m p2\n     echo quux > foo.txt &&\n     stg refresh &&\n-    ! stg push\n+    conflict_old stg push\n '\n \n test_expect_success 'Make sure conflicting patches are preserved' '\ndiff --git a/t/t2900-rename.sh b/t/t2900-rename.sh\nindex 5f47f86..0e16d6e 100755\n--- a/t/t2900-rename.sh\n+++ b/t/t2900-rename.sh\n@@ -13,7 +13,7 @@ Tests some parts of the stg rename command.'\n stg init\n \n test_expect_success 'Rename in empty' '\n-   ! stg rename foo\n+   command_error stg rename foo\n '\n \n test_expect_success 'Rename single top-most' '\n@@ -23,7 +23,7 @@ test_expect_success 'Rename single top-most' '\n # bar\n \n test_expect_success 'Rename non-existing' '\n-   ! stg rename neithersuchpatch norsuchpatch\n+   command_error stg rename neithersuchpatch norsuchpatch\n '\n \n test_expect_success 'Rename with two arguments' '\n@@ -33,11 +33,11 @@ test_expect_success 'Rename with two arguments' '\n # foo,baz\n \n test_expect_success 'Rename to existing name' '\n-   ! stg rename foo baz\n+   command_error stg rename foo baz\n '\n \n test_expect_success 'Rename to same name' '\n-   ! stg rename foo foo\n+   command_error stg rename foo foo\n '\n \n test_expect_success 'Rename top-most when others exist' '\ndiff --git a/t/t3000-dirty-merge.sh b/t/t3000-dirty-merge.sh\nindex d87bba1..4dd6da3 100755\n--- a/t/t3000-dirty-merge.sh\n+++ b/t/t3000-dirty-merge.sh\n@@ -26,7 +26,7 @@ test_expect_success 'Push with dirty worktree' '\n     echo 4 > a &&\n     [ \"$(echo $(stg applied))\" = \"p1\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"p2\" ] &&\n-    ! stg goto p2 &&\n+    conflict stg goto p2 &&\n     [ \"$(echo $(stg applied))\" = \"p1\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"p2\" ] &&\n     [ \"$(echo $(cat a))\" = \"4\" ]\ndiff --git a/t/t4000-upgrade.sh b/t/t4000-upgrade.sh\nindex 8a308fb..ea9bf0b 100755\n--- a/t/t4000-upgrade.sh\n+++ b/t/t4000-upgrade.sh\n@@ -31,7 +31,7 @@ for ver in 0.12 0.8; do\n \n     test_expect_success \\\n         \"v$ver: Make sure the base ref is no longer there\" '\n-        ! git show-ref --verify --quiet refs/bases/master\n+        must_fail git show-ref --verify --quiet refs/bases/master\n     '\n \n     cd ..\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 95e322e..ad8da68 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -285,6 +285,30 @@ test_expect_code () {\n \techo >&3 \"\"\n }\n \n+# When running an StGit command that should exit with an error, use\n+# these instead of testing for any non-zero exit code with !.\n+exit_code () {\n+\texpected=$1\n+\tshift\n+\t\"$@\"\n+\ttest $? -eq $expected\n+}\n+general_error () { exit_code 1 \"$@\" ; }\n+command_error () { exit_code 2 \"$@\" ; }\n+conflict () { exit_code 3 \"$@\" ; }\n+\n+# Old-infrastructure commands don't exit with the proper value on\n+# conflicts. But we don't want half the tests to fail because of that,\n+# so use this instead of \"conflict\" for them.\n+conflict_old () { command_error \"$@\" ; }\n+\n+# Same thing, but for other commands that StGit where we just want to\n+# make sure that they fail instead of crashing.\n+must_fail () {\n+        \"$@\"\n+        test $? -gt 0 -a $? -le 129\n+}\n+\n # test_cmp is a helper function to compare actual and expected output.\n # You can use it like:\n #\n"},{"id":"82536","messageId":"20080708040317.23134.667.stgit@yoghurt","threadId":"14338","inReplyTo":"20080708035750.23134.75833.stgit@yoghurt","subject":"[StGit PATCH 2/2] Test for \"stg edit\"","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-07-08T04:03:17Z","receivedAt":"2008-07-08T04:03:17Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"We weren't testing this comaratively complicated command at all. (And\nnot surprisingly, some corner cases that should have worked didn't.)\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n t/t3300-edit.sh |  205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 205 insertions(+), 0 deletions(-)\n create mode 100755 t/t3300-edit.sh\n\n\ndiff --git a/t/t3300-edit.sh b/t/t3300-edit.sh\nnew file mode 100755\nindex 0000000..8304d9f\n--- /dev/null\n+++ b/t/t3300-edit.sh\n@@ -0,0 +1,205 @@\n+#!/bin/sh\n+test_description='Test \"stg edit\"'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'Setup' '\n+    printf \"000\\n111\\n222\\n\" >> foo &&\n+    git add foo &&\n+    git commit -m \"Initial commit\" &&\n+    sed -i \"s/000/000xx/\" foo &&\n+    git commit -a -m \"First change\" &&\n+    sed -i \"s/111/111yy/\" foo &&\n+    git commit -a -m \"Second change\" &&\n+    sed -i \"s/222/222zz/\" foo &&\n+    git commit -a -m \"Third change\" &&\n+    stg init &&\n+    stg uncommit -n 3 p &&\n+    stg pop\n+'\n+\n+# Commit parse functions.\n+msg () { git cat-file -p $1 | sed '1,/^$/d' | tr '\\n' / | sed 's,/*$,,' ; }\n+auth () { git log -n 1 --pretty=format:\"%an, %ae\" $1 ; }\n+date () { git log -n 1 --pretty=format:%ai $1 ; }\n+\n+test_expect_success 'Edit message of top patch' '\n+    test \"$(msg HEAD)\" = \"Second change\" &&\n+    stg edit p2 -m \"Second change 2\" &&\n+    test \"$(msg HEAD)\" = \"Second change 2\"\n+'\n+\n+test_expect_success 'Edit message of non-top patch' '\n+    test \"$(msg HEAD^)\" = \"First change\" &&\n+    stg edit p1 -m \"First change 2\" &&\n+    test \"$(msg HEAD^)\" = \"First change 2\"\n+'\n+\n+test_expect_success 'Edit message of unapplied patch' '\n+    test \"$(msg $(stg id p3))\" = \"Third change\" &&\n+    stg edit p3 -m \"Third change 2\" &&\n+    test \"$(msg $(stg id p3))\" = \"Third change 2\"\n+'\n+\n+test_expect_success 'Set patch message with --file <file>' '\n+    test \"$(msg HEAD)\" = \"Second change 2\" &&\n+    echo \"Pride or Prejudice\" > commitmsg &&\n+    stg edit p2 -f commitmsg &&\n+    test \"$(msg HEAD)\" = \"Pride or Prejudice\"\n+'\n+\n+test_expect_success 'Set patch message with --file -' '\n+    echo \"Pride and Prejudice\" | stg edit p2 -f - &&\n+    test \"$(msg HEAD)\" = \"Pride and Prejudice\"\n+'\n+\n+( printf 'From: A U Thor <author@example.com>\\nDate: <omitted>'\n+  printf '\\n\\nPride and Prejudice' ) > expected-tmpl\n+omit_date () { sed \"s/^Date:.*$/Date: <omitted>/\" ; }\n+\n+test_expect_success 'Save template to file' '\n+    stg edit --save-template saved-tmpl p2 &&\n+    omit_date < saved-tmpl > saved-tmpl-d &&\n+    test_cmp expected-tmpl saved-tmpl-d\n+'\n+\n+test_expect_success 'Save template to stdout' '\n+    stg edit --save-template - p2 > saved-tmpl2 &&\n+    omit_date < saved-tmpl2 > saved-tmpl2-d &&\n+    test_cmp expected-tmpl saved-tmpl2-d\n+'\n+\n+# Test the various ways of invoking the interactive editor. The\n+# preference order should be\n+#\n+#   1. GIT_EDITOR\n+#   2. stgit.editor (legacy)\n+#   3. core.editor\n+#   4. VISUAL\n+#   5. EDITOR\n+#   6. vi\n+\n+mkeditor ()\n+{\n+    cat > \"$1\" <<EOF\n+#!/bin/sh\n+printf \"\\n$1\\n\" >> \"\\$1\"\n+EOF\n+    chmod a+x \"$1\"\n+}\n+\n+mkeditor vi\n+test_expect_failure 'Edit commit message interactively (vi)' '\n+    m=$(msg HEAD) &&\n+    PATH=.:$PATH stg edit p2 &&\n+    test \"$(msg HEAD)\" = \"$m/vi\"\n+'\n+\n+mkeditor e1\n+test_expect_success 'Edit commit message interactively (EDITOR)' '\n+    m=$(msg HEAD) &&\n+    EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n+    echo $m && echo $(msg HEAD) &&\n+    test \"$(msg HEAD)\" = \"$m/e1\"\n+'\n+\n+mkeditor e2\n+test_expect_failure 'Edit commit message interactively (VISUAL)' '\n+    m=$(msg HEAD) &&\n+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n+    test \"$(msg HEAD)\" = \"$m/e2\"\n+'\n+\n+mkeditor e3\n+test_expect_failure 'Edit commit message interactively (core.editor)' '\n+    m=$(msg HEAD) &&\n+    git config core.editor e3 &&\n+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n+    test \"$(msg HEAD)\" = \"$m/e3\"\n+'\n+\n+mkeditor e4\n+test_expect_success 'Edit commit message interactively (stgit.editor)' '\n+    m=$(msg HEAD) &&\n+    git config stgit.editor e4 &&\n+    VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n+    test \"$(msg HEAD)\" = \"$m/e4\"\n+'\n+\n+mkeditor e5\n+test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '\n+    m=$(msg HEAD) &&\n+    GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n+    test \"$(msg HEAD)\" = \"$m/e5\"\n+'\n+\n+rm -f vi e1 e2 e3 e4 e5\n+git config --unset core.editor\n+git config --unset stgit.editor\n+\n+mkeditor twoliner\n+test_expect_failure 'Both noninterative and interactive editing' '\n+    EDITOR=./twoliner stg edit -e -m \"oneliner\" p2 &&\n+    test \"$(msg HEAD)\" = \"oneliner/twoliner\"\n+'\n+rm -f twoliner\n+\n+cat > diffedit <<EOF\n+#!/bin/sh\n+sed -i 's/111yy/111YY/' \"\\$1\"\n+EOF\n+chmod a+x diffedit\n+test_expect_success 'Edit patch diff' '\n+    EDITOR=./diffedit stg edit -d p2 &&\n+    test \"$(grep 111 foo)\" = \"111YY\"\n+'\n+rm -f diffedit\n+\n+test_expect_success 'Sign a patch' '\n+    m=$(msg HEAD) &&\n+    stg edit --sign p2 &&\n+    test \"$(msg HEAD)\" = \"$m//Signed-off-by: C O Mitter <committer@example.com>\"\n+'\n+\n+test_expect_success 'Acknowledge a patch' '\n+    m=$(msg HEAD^) &&\n+    stg edit --ack p1 &&\n+    test \"$(msg HEAD^)\" = \"$m//Acked-by: C O Mitter <committer@example.com>\"\n+'\n+\n+test_expect_success 'Set author' '\n+    stg edit p2 --author \"Jane Austin <jaustin@example.com>\" &&\n+    test \"$(auth HEAD)\" = \"Jane Austin, jaustin@example.com\"\n+'\n+\n+test_expect_success 'Fail to set broken author' '\n+    command_error stg edit p2 --author \"No Mail Address\" &&\n+    test \"$(auth HEAD)\" = \"Jane Austin, jaustin@example.com\"\n+'\n+\n+test_expect_success 'Set author name' '\n+    stg edit p2 --authname \"Jane Austen\" &&\n+    test \"$(auth HEAD)\" = \"Jane Austen, jaustin@example.com\"\n+'\n+\n+test_expect_success 'Set author email' '\n+    stg edit p2 --authemail \"jausten@example.com\" &&\n+    test \"$(auth HEAD)\" = \"Jane Austen, jausten@example.com\"\n+'\n+\n+test_expect_failure 'Set author date (RFC2822 format)' '\n+    stg edit p2 --authdate \"Wed, 10 Jul 2013 23:39:00 pm -0300\" &&\n+    test \"$(date HEAD)\" = \"2013-07-10 23:39:00 -0300\"\n+'\n+\n+test_expect_failure 'Set author date (ISO 8601 format)' '\n+    stg edit p2 --authdate \"2013-01-28 22:30:00 -0300\" &&\n+    test \"$(date HEAD)\" = \"2013-01-28 22:30:00 -0300\"\n+'\n+\n+test_expect_failure 'Fail to set invalid author date' '\n+    command_error stg edit p2 --authdate \"28 Jan 1813\" &&\n+    test \"$(date HEAD)\" = \"2013-01-28 22:30:00 -0300\"\n+'\n+\n+test_done\n"}]}