{"thread":{"id":"11212","subject":"[PATCH] Interactive editor tests for commit-msg hook","startedAt":"2007-12-09T12:52:11Z","lastAt":"2007-12-10T07:33:26Z","messageCount":4,"participants":["Wincent Colaiuta","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"62482","messageId":"1197204731-19553-1-git-send-email-win@wincent.com","threadId":"11212","inReplyTo":null,"subject":"[PATCH] Interactive editor tests for commit-msg hook","fromName":"Wincent Colaiuta","fromEmail":"win@wincent.com","sentAt":"2007-12-09T12:52:11Z","receivedAt":"2007-12-09T12:52:11Z","isPatch":true,"sender":{"key":"greg@hurrell.net","avatar":"https://avatars.githubusercontent.com/u/7074?v=4"},"body":"Supplement the existing tests for the commit-msg hook (which all use\n\"git commit -m\") with tests which use an interactive editor (no -m\nswitch) to ensure that all code paths get tested.\n\nSigned-off-by: Wincent Colaiuta <win@wincent.com>\n---\n\nI didn't add similar tests for the pre-commit hook because I don't\nthink that's an interesting code path; we don't care about the commit\nmessage in that case, only whether the commit is allowed to proceed or\nnot.\n\n t/t7504-commit-msg-hook.sh |   72 ++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 72 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh\nindex 17aad7c..e154bab 100755\n--- a/t/t7504-commit-msg-hook.sh\n+++ b/t/t7504-commit-msg-hook.sh\n@@ -9,11 +9,33 @@ test_expect_success \"with no hook\" \\\n \t git add file &&\n \t git commit -m 'first'\"\n \n+# set up fake editor for interactive editing\n+cat > fake-editor <<'EOF'\n+#!/bin/sh\n+cp FAKE_MSG \"$1\"\n+exit 0\n+EOF\n+chmod +x fake-editor\n+FAKE_EDITOR=\"$(pwd)/fake-editor\"\n+export FAKE_EDITOR\n+\n+test_expect_success \"with no hook (editor)\" \\\n+\t\"echo 'more foo' >> file &&\n+\t git add file &&\n+\t echo 'more foo' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit\"\n+\n test_expect_success \"--no-verify with no hook\" \\\n \t\"echo 'bar' > file &&\n \t git add file &&\n \t git commit --no-verify -m 'bar'\"\n \n+test_expect_success \"--no-verify with no hook (editor)\" \\\n+\t\"echo 'more bar' > file &&\n+\t git add file &&\n+\t echo 'more bar' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\"\n+\n # now install hook that always succeeds\n HOOKDIR=\"$(git rev-parse --git-dir)/hooks\"\n HOOK=\"$HOOKDIR/commit-msg\"\n@@ -29,11 +51,23 @@ test_expect_success \"with succeeding hook\" \\\n \t git add file &&\n \t git commit -m 'more'\"\n \n+test_expect_success \"with succeeding hook (editor)\" \\\n+\t\"echo 'more more' >> file &&\n+\t git add file &&\n+\t echo 'more more' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit\"\n+\n test_expect_success \"--no-verify with succeeding hook\" \\\n \t\"echo 'even more' >> file &&\n \t git add file &&\n \t git commit --no-verify -m 'even more'\"\n \n+test_expect_success \"--no-verify with succeeding hook (editor)\" \\\n+\t\"echo 'even more more' >> file &&\n+\t git add file &&\n+\t echo 'even more more' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\"\n+\n # now a hook that fails\n cat > \"$HOOK\" <<EOF\n #!/bin/sh\n@@ -45,22 +79,46 @@ test_expect_failure \"with failing hook\" \\\n \t git add file &&\n \t git commit -m 'another'\"\n \n+test_expect_failure \"with failing hook (editor)\" \\\n+\t\"echo 'more another' >> file &&\n+\t git add file &&\n+\t echo 'more another' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit\"\n+\n test_expect_success \"--no-verify with failing hook\" \\\n \t\"echo 'stuff' >> file &&\n \t git add file &&\n \t git commit --no-verify -m 'stuff'\"\n \n+test_expect_success \"--no-verify with failing hook (editor)\" \\\n+\t\"echo 'more stuff' >> file &&\n+\t git add file &&\n+\t echo 'more stuff' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\"\n+\n chmod -x \"$HOOK\"\n test_expect_success \"with non-executable hook\" \\\n \t\"echo 'content' >> file &&\n \t git add file &&\n \t git commit -m 'content'\"\n \n+test_expect_success \"with non-executable hook (editor)\" \\\n+\t\"echo 'content again' >> file &&\n+\t git add file &&\n+\t echo 'content again' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit -m 'content again'\"\n+\n test_expect_success \"--no-verify with non-executable hook\" \\\n \t\"echo 'more content' >> file &&\n \t git add file &&\n \t git commit --no-verify -m 'more content'\"\n \n+test_expect_success \"--no-verify with non-executable hook (editor)\" \\\n+\t\"echo 'even more content' >> file &&\n+\t git add file &&\n+\t echo 'even more content' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\"\n+\n # now a hook that edits the commit message\n cat > \"$HOOK\" <<'EOF'\n #!/bin/sh\n@@ -79,10 +137,24 @@ test_expect_success \"hook edits commit message\" \\\n \t git commit -m 'additional' &&\n \t commit_msg_is 'new message'\"\n \n+test_expect_success \"hook edits commit message (editor)\" \\\n+\t\"echo 'additional content' >> file &&\n+\t git add file &&\n+\t echo 'additional content' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit &&\n+\t commit_msg_is 'new message'\"\n+\n test_expect_success \"hook doesn't edit commit message\" \\\n \t\"echo 'plus' >> file &&\n \t git add file &&\n \t git commit --no-verify -m 'plus' &&\n \t commit_msg_is 'plus'\"\n \n+test_expect_success \"hook doesn't edit commit message (editor)\" \\\n+\t\"echo 'more plus' >> file &&\n+\t git add file &&\n+\t echo 'more plus' > FAKE_MSG &&\n+\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify &&\n+\t commit_msg_is 'more plus'\"\n+\n test_done\n-- \n1.5.3.7.1116.gf11de\n"},{"id":"62534","messageId":"7vwsrnmczu.fsf@gitster.siamese.dyndns.org","threadId":"11212","inReplyTo":"1197204731-19553-1-git-send-email-win@wincent.com","subject":"Re: [PATCH] Interactive editor tests for commit-msg hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-10T03:42:45Z","receivedAt":"2007-12-10T03:42:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wincent Colaiuta <win@wincent.com> writes:\n\n> I didn't add similar tests for the pre-commit hook because I don't\n> think that's an interesting code path; we don't care about the commit\n> message in that case, only whether the commit is allowed to proceed or\n> not.\n\nSensible.\n\n> +# set up fake editor for interactive editing\n> +cat > fake-editor <<'EOF'\n> +#!/bin/sh\n> +cp FAKE_MSG \"$1\"\n> +exit 0\n> +EOF\n> +chmod +x fake-editor\n> +FAKE_EDITOR=\"$(pwd)/fake-editor\"\n> +export FAKE_EDITOR\n\nHmm.  Why \"export\"?\n\n> +test_expect_success \"with no hook (editor)\" \\\n> +\t\"echo 'more foo' >> file &&\n> +\t git add file &&\n> +\t echo 'more foo' > FAKE_MSG &&\n> +\t GIT_EDITOR=\"$FAKE_EDITOR\" git commit\"\n> +\n\nI initially was going to say \"this is just a style thing\", but I really\nwant our tests to read uniformly like this:\n\n        test_expect_success 'without hook (editor)' '\n\n                echo more foo >>file &&\n                git add file &&\n                echo more foo >FAKE_MSG &&\n                GIT_EDITOR=\"$FAKE_EDITOR\" git commit\n\n        '\n\n * Use single quotes around test unless there is a compelling reason not\n   to;\n\n * The opening single quote of the test body on the same line as\n   expect-success; the end quote at column 1 on a line on its own.\n\nNotice a bug in your version?  Dq around $FAKE_EDITOR is stripped away\nand it is harder to spot it because the script does not follow that\nstyle.\n"},{"id":"62549","messageId":"704CE0C4-FD30-424B-86DF-2625E39707B7@wincent.com","threadId":"11212","inReplyTo":"7vwsrnmczu.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Interactive editor tests for commit-msg hook","fromName":"Wincent Colaiuta","fromEmail":"win@wincent.com","sentAt":"2007-12-10T07:32:43Z","receivedAt":"2007-12-10T07:32:43Z","isPatch":true,"sender":{"key":"greg@hurrell.net","avatar":"https://avatars.githubusercontent.com/u/7074?v=4"},"body":"El 10/12/2007, a las 4:42, Junio C Hamano escribió:\n\n>> +# set up fake editor for interactive editing\n>> +cat > fake-editor <<'EOF'\n>> +#!/bin/sh\n>> +cp FAKE_MSG \"$1\"\n>> +exit 0\n>> +EOF\n>> +chmod +x fake-editor\n>> +FAKE_EDITOR=\"$(pwd)/fake-editor\"\n>> +export FAKE_EDITOR\n>\n> Hmm.  Why \"export\"?\n\nBecause I'd seen it in other tests (eg. t3404-rebase-interactive.sh),  \nso I just copied the style. If it's not necessary though we can lose it.\n\n> I initially was going to say \"this is just a style thing\", but I  \n> really\n> want our tests to read uniformly like this:\n\nOk, fixed up version will follow in a couple of minutes.\n\nCheers,\nWincent\n"},{"id":"62550","messageId":"1197272006-5364-1-git-send-email-win@wincent.com","threadId":"11212","inReplyTo":"7vwsrnmczu.fsf@gitster.siamese.dyndns.org","subject":"[PATCH 7/7] Interactive editor tests for commit-msg hook","fromName":"Wincent Colaiuta","fromEmail":"win@wincent.com","sentAt":"2007-12-10T07:33:26Z","receivedAt":"2007-12-10T07:33:26Z","isPatch":true,"sender":{"key":"greg@hurrell.net","avatar":"https://avatars.githubusercontent.com/u/7074?v=4"},"body":"Supplement the existing tests for the commit-msg hook (which all use\n\"git commit -m\") with tests which use an interactive editor (no -m\nswitch) to ensure that all code paths get tested.\n\nAt the same time the quoting of some of the existing tests is changed\nto conform to Junio's recommendations for test style (single quotes\nused around the test unless there is a compelling reason not to, and\nthe opening quote on the same line as the test_expect and the closing\nquote in column 1).\n\nSigned-off-by: Wincent Colaiuta <win@wincent.com>\n---\n t/t7504-commit-msg-hook.sh |  218 +++++++++++++++++++++++++++++++++++---------\n 1 files changed, 175 insertions(+), 43 deletions(-)\n\ndiff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh\nindex 17aad7c..751b113 100755\n--- a/t/t7504-commit-msg-hook.sh\n+++ b/t/t7504-commit-msg-hook.sh\n@@ -4,15 +4,49 @@ test_description='commit-msg hook'\n \n . ./test-lib.sh\n \n-test_expect_success \"with no hook\" \\\n-\t\"echo 'foo' > file &&\n-\t git add file &&\n-\t git commit -m 'first'\"\n+test_expect_success 'with no hook' '\n \n-test_expect_success \"--no-verify with no hook\" \\\n-\t\"echo 'bar' > file &&\n-\t git add file &&\n-\t git commit --no-verify -m 'bar'\"\n+\techo \"foo\" > file &&\n+\tgit add file &&\n+\tgit commit -m \"first\"\n+\n+'\n+\n+# set up fake editor for interactive editing\n+cat > fake-editor <<'EOF'\n+#!/bin/sh\n+cp FAKE_MSG \"$1\"\n+exit 0\n+EOF\n+chmod +x fake-editor\n+FAKE_EDITOR=\"$(pwd)/fake-editor\"\n+export FAKE_EDITOR\n+\n+test_expect_success 'with no hook (editor)' '\n+\n+\techo \"more foo\" >> file &&\n+\tgit add file &&\n+\techo \"more foo\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit\n+\n+'\n+\n+test_expect_success '--no-verify with no hook' '\n+\n+\techo \"bar\" > file &&\n+\tgit add file &&\n+\tgit commit --no-verify -m \"bar\"\n+\n+'\n+\n+test_expect_success '--no-verify with no hook (editor)' '\n+\n+\techo \"more bar\" > file &&\n+\tgit add file &&\n+\techo \"more bar\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\n+\n+'\n \n # now install hook that always succeeds\n HOOKDIR=\"$(git rev-parse --git-dir)/hooks\"\n@@ -24,15 +58,39 @@ exit 0\n EOF\n chmod +x \"$HOOK\"\n \n-test_expect_success \"with succeeding hook\" \\\n-\t\"echo 'more' >> file &&\n-\t git add file &&\n-\t git commit -m 'more'\"\n+test_expect_success 'with succeeding hook' '\n \n-test_expect_success \"--no-verify with succeeding hook\" \\\n-\t\"echo 'even more' >> file &&\n-\t git add file &&\n-\t git commit --no-verify -m 'even more'\"\n+\techo \"more\" >> file &&\n+\tgit add file &&\n+\tgit commit -m \"more\"\n+\n+'\n+\n+test_expect_success 'with succeeding hook (editor)' '\n+\n+\techo \"more more\" >> file &&\n+\tgit add file &&\n+\techo \"more more\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit\n+\n+'\n+\n+test_expect_success '--no-verify with succeeding hook' '\n+\n+\techo \"even more\" >> file &&\n+\tgit add file &&\n+\tgit commit --no-verify -m \"even more\"\n+\n+'\n+\n+test_expect_success '--no-verify with succeeding hook (editor)' '\n+\n+\techo \"even more more\" >> file &&\n+\tgit add file &&\n+\techo \"even more more\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\n+\n+'\n \n # now a hook that fails\n cat > \"$HOOK\" <<EOF\n@@ -40,26 +98,74 @@ cat > \"$HOOK\" <<EOF\n exit 1\n EOF\n \n-test_expect_failure \"with failing hook\" \\\n-\t\"echo 'another' >> file &&\n-\t git add file &&\n-\t git commit -m 'another'\"\n+test_expect_failure 'with failing hook' '\n+\n+\techo \"another\" >> file &&\n+\tgit add file &&\n+\tgit commit -m \"another\"\n+\n+'\n+\n+test_expect_failure 'with failing hook (editor)' '\n+\n+\techo \"more another\" >> file &&\n+\tgit add file &&\n+\techo \"more another\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit\n \n-test_expect_success \"--no-verify with failing hook\" \\\n-\t\"echo 'stuff' >> file &&\n-\t git add file &&\n-\t git commit --no-verify -m 'stuff'\"\n+'\n+\n+test_expect_success '--no-verify with failing hook' '\n+\n+\techo \"stuff\" >> file &&\n+\tgit add file &&\n+\tgit commit --no-verify -m \"stuff\"\n+\n+'\n+\n+test_expect_success '--no-verify with failing hook (editor)' '\n+\n+\techo \"more stuff\" >> file &&\n+\tgit add file &&\n+\techo \"more stuff\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\n+\n+'\n \n chmod -x \"$HOOK\"\n-test_expect_success \"with non-executable hook\" \\\n-\t\"echo 'content' >> file &&\n-\t git add file &&\n-\t git commit -m 'content'\"\n+test_expect_success 'with non-executable hook' '\n+\n+\techo \"content\" >> file &&\n+\tgit add file &&\n+\tgit commit -m \"content\"\n+\n+'\n+\n+test_expect_success 'with non-executable hook (editor)' '\n+\n+\techo \"content again\" >> file &&\n+\tgit add file &&\n+\techo \"content again\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit -m \"content again\"\n+\n+'\n+\n+test_expect_success '--no-verify with non-executable hook' '\n+\n+\techo \"more content\" >> file &&\n+\tgit add file &&\n+\tgit commit --no-verify -m \"more content\"\n+\n+'\n \n-test_expect_success \"--no-verify with non-executable hook\" \\\n-\t\"echo 'more content' >> file &&\n-\t git add file &&\n-\t git commit --no-verify -m 'more content'\"\n+test_expect_success '--no-verify with non-executable hook (editor)' '\n+\n+\techo \"even more content\" >> file &&\n+\tgit add file &&\n+\techo \"even more content\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify\n+\n+'\n \n # now a hook that edits the commit message\n cat > \"$HOOK\" <<'EOF'\n@@ -73,16 +179,42 @@ commit_msg_is () {\n \ttest \"`git log --pretty=format:%s%b -1`\" = \"$1\"\n }\n \n-test_expect_success \"hook edits commit message\" \\\n-\t\"echo 'additional' >> file &&\n-\t git add file &&\n-\t git commit -m 'additional' &&\n-\t commit_msg_is 'new message'\"\n-\n-test_expect_success \"hook doesn't edit commit message\" \\\n-\t\"echo 'plus' >> file &&\n-\t git add file &&\n-\t git commit --no-verify -m 'plus' &&\n-\t commit_msg_is 'plus'\"\n+test_expect_success 'hook edits commit message' '\n+\n+\techo \"additional\" >> file &&\n+\tgit add file &&\n+\tgit commit -m \"additional\" &&\n+\tcommit_msg_is \"new message\"\n+\n+'\n+\n+test_expect_success 'hook edits commit message (editor)' '\n+\n+\techo \"additional content\" >> file &&\n+\tgit add file &&\n+\techo \"additional content\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit &&\n+\tcommit_msg_is \"new message\"\n+\n+'\n+\n+test_expect_success \"hook doesn't edit commit message\" '\n+\n+\techo \"plus\" >> file &&\n+\tgit add file &&\n+\tgit commit --no-verify -m \"plus\" &&\n+\tcommit_msg_is \"plus\"\n+\n+'\n+\n+test_expect_success \"hook doesn't edit commit message (editor)\" '\n+\n+\techo \"more plus\" >> file &&\n+\tgit add file &&\n+\techo \"more plus\" > FAKE_MSG &&\n+\tGIT_EDITOR=\"$FAKE_EDITOR\" git commit --no-verify &&\n+\tcommit_msg_is \"more plus\"\n+\n+'\n \n test_done\n-- \n1.5.3.7.1116.gf11de\n"}]}