git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 05/10] tests: indent and add hook setup to "test_expect_success"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 7, 2022, 12:43 UTC
Message-ID
<patch-v2-05.10-19db5b2d7c2-20220307T123909Z-avarab@gmail.com>
In-Reply-To
<cover-v2-00.10-00000000000-20220307T123909Z-avarab@gmail.com>

Indent various hook setup code in the test suite that's using a manual "cat && chmod" pattern.

These should also consistently use "#!$SHELL_PATH" instead of "#!/bin/sh", i.e. "test_script". Let's fix that in a subsequent commit, which will be easier to review after this smaller change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t3412-rebase-root.sh       | 16 ++++----
 t/t3413-rebase-hook.sh       | 16 ++++----
 t/t5401-update-hooks.sh      | 76 ++++++++++++++++++------------------
 t/t5407-post-rewrite-hook.sh | 16 ++++----
 t/t5541-http-push-smart.sh   | 24 ++++++------
 5 files changed, 75 insertions(+), 73 deletions(-)
diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh
index 1e9f7833dd6..239a9343d34 100755
--- a/t/t3412-rebase-root.sh
+++ b/t/t3412-rebase-root.sh
@@ -32,10 +32,10 @@ test_expect_success 'rebase --root fails with too many args' '
 
 test_expect_success 'setup pre-rebase hook' '
 	mkdir -p .git/hooks &&
-	cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-echo "\$1,\$2" >.git/PRE-REBASE-INPUT
-EOF
+	cat >.git/hooks/pre-rebase <<-EOF &&
+	#!$SHELL_PATH
+	echo "\$1,\$2" >.git/PRE-REBASE-INPUT
+	EOF
 	chmod +x .git/hooks/pre-rebase
 '
 cat > expect <<EOF
@@ -142,10 +142,10 @@ EOF
 
 test_expect_success 'setup pre-rebase hook that fails' '
 	mkdir -p .git/hooks &&
-	cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-false
-EOF
+	cat >.git/hooks/pre-rebase <<-EOF &&
+	#!$SHELL_PATH
+	false
+	EOF
 	chmod +x .git/hooks/pre-rebase
 '
 
diff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh
index b4acb3be5cf..bb241b26b2e 100755
--- a/t/t3413-rebase-hook.sh
+++ b/t/t3413-rebase-hook.sh
@@ -42,10 +42,10 @@ test_expect_success 'rebase -i' '
 
 test_expect_success 'setup pre-rebase hook' '
 	mkdir -p .git/hooks &&
-	cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-echo "\$1,\$2" >.git/PRE-REBASE-INPUT
-EOF
+	cat >.git/hooks/pre-rebase <<-EOF &&
+	#!$SHELL_PATH
+	echo "\$1,\$2" >.git/PRE-REBASE-INPUT
+	EOF
 	chmod +x .git/hooks/pre-rebase
 '
 
@@ -103,10 +103,10 @@ test_expect_success 'pre-rebase hook gets correct input (6)' '
 
 test_expect_success 'setup pre-rebase hook that fails' '
 	mkdir -p .git/hooks &&
-	cat >.git/hooks/pre-rebase <<EOF &&
-#!$SHELL_PATH
-false
-EOF
+	cat >.git/hooks/pre-rebase <<-EOF &&
+	#!$SHELL_PATH
+	false
+	EOF
 	chmod +x .git/hooks/pre-rebase
 '
 
diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh
index 6012cc8172a..6392f71795d 100755
--- a/t/t5401-update-hooks.sh
+++ b/t/t5401-update-hooks.sh
@@ -20,46 +20,46 @@ test_expect_success setup '
 	git clone --bare ./. victim.git &&
 	GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 &&
 	git update-ref refs/heads/main $commit1 &&
-	git update-ref refs/heads/tofail $commit0
+	git update-ref refs/heads/tofail $commit0 &&
+
+	cat >victim.git/hooks/pre-receive <<-\EOF &&
+	#!/bin/sh
+	printf %s "$@" >>$GIT_DIR/pre-receive.args
+	cat - >$GIT_DIR/pre-receive.stdin
+	echo STDOUT pre-receive
+	echo STDERR pre-receive >&2
+	EOF
+	chmod u+x victim.git/hooks/pre-receive &&
+
+	cat >victim.git/hooks/update <<-\EOF &&
+	#!/bin/sh
+	echo "$@" >>$GIT_DIR/update.args
+	read x; printf %s "$x" >$GIT_DIR/update.stdin
+	echo STDOUT update $1
+	echo STDERR update $1 >&2
+	test "$1" = refs/heads/main || exit
+	EOF
+	chmod u+x victim.git/hooks/update &&
+
+	cat >victim.git/hooks/post-receive <<-\EOF &&
+	#!/bin/sh
+	printf %s "$@" >>$GIT_DIR/post-receive.args
+	cat - >$GIT_DIR/post-receive.stdin
+	echo STDOUT post-receive
+	echo STDERR post-receive >&2
+	EOF
+	chmod u+x victim.git/hooks/post-receive &&
+
+	cat >victim.git/hooks/post-update <<-\EOF &&
+	#!/bin/sh
+	echo "$@" >>$GIT_DIR/post-update.args
+	read x; printf %s "$x" >$GIT_DIR/post-update.stdin
+	echo STDOUT post-update
+	echo STDERR post-update >&2
+	EOF
+	chmod u+x victim.git/hooks/post-update
 '
 
-cat >victim.git/hooks/pre-receive <<'EOF'
-#!/bin/sh
-printf %s "$@" >>$GIT_DIR/pre-receive.args
-cat - >$GIT_DIR/pre-receive.stdin
-echo STDOUT pre-receive
-echo STDERR pre-receive >&2
-EOF
-chmod u+x victim.git/hooks/pre-receive
-
-cat >victim.git/hooks/update <<'EOF'
-#!/bin/sh
-echo "$@" >>$GIT_DIR/update.args
-read x; printf %s "$x" >$GIT_DIR/update.stdin
-echo STDOUT update $1
-echo STDERR update $1 >&2
-test "$1" = refs/heads/main || exit
-EOF
-chmod u+x victim.git/hooks/update
-
-cat >victim.git/hooks/post-receive <<'EOF'
-#!/bin/sh
-printf %s "$@" >>$GIT_DIR/post-receive.args
-cat - >$GIT_DIR/post-receive.stdin
-echo STDOUT post-receive
-echo STDERR post-receive >&2
-EOF
-chmod u+x victim.git/hooks/post-receive
-
-cat >victim.git/hooks/post-update <<'EOF'
-#!/bin/sh
-echo "$@" >>$GIT_DIR/post-update.args
-read x; printf %s "$x" >$GIT_DIR/post-update.stdin
-echo STDOUT post-update
-echo STDERR post-update >&2
-EOF
-chmod u+x victim.git/hooks/post-update
-
 test_expect_success push '
 	test_must_fail git send-pack --force ./victim.git \
 		main tofail >send.out 2>send.err
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 6da8d760e28..64f40ff7776 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -17,15 +17,15 @@ test_expect_success 'setup' '
 	git checkout A^0 &&
 	test_commit E bar E &&
 	test_commit F foo F &&
-	git checkout main
-'
+	git checkout main &&
 
-cat >.git/hooks/post-rewrite <<EOF
-#!/bin/sh
-echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
-cat > "$TRASH_DIRECTORY"/post-rewrite.data
-EOF
-chmod u+x .git/hooks/post-rewrite
+	cat >.git/hooks/post-rewrite <<-EOF &&
+	#!/bin/sh
+	echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
+	cat > "$TRASH_DIRECTORY"/post-rewrite.data
+	EOF
+	chmod u+x .git/hooks/post-rewrite
+'
 
 clear_hook_input () {
 	rm -f post-rewrite.args post-rewrite.data
diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh
index 8ca50f8b18c..0043b718f08 100755
--- a/t/t5541-http-push-smart.sh
+++ b/t/t5541-http-push-smart.sh
@@ -96,18 +96,20 @@ test_expect_success 'create and delete remote branch' '
 	test_must_fail git show-ref --verify refs/remotes/origin/dev
 '
 
-cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
-#!/bin/sh
-exit 1
-EOF
-chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
+test_expect_success 'setup rejected update hook' '
+	cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<-EOF &&
+	#!/bin/sh
+	exit 1
+	EOF
+	chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" &&
 
-cat >exp <<EOF
-remote: error: hook declined to update refs/heads/dev2
-To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
- ! [remote rejected] dev2 -> dev2 (hook declined)
-error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
-EOF
+	cat >exp <<-EOF
+	remote: error: hook declined to update refs/heads/dev2
+	To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
+	 ! [remote rejected] dev2 -> dev2 (hook declined)
+	error: failed to push some refs to '\''http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'\''
+	EOF
+'
 
 test_expect_success 'rejected update prints status' '
 	cd "$ROOT_PATH"/test_repo_clone &&
-- 
2.35.1.1242.gfeba0eae32b
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 28 of 51 in “tests: add and use a "test_hook" wrapper + hook fixes”
  1. 00/10 tests: add and use a "test_hook" wrapper + hook fixesÆvar Arnfjörð Bjarmason, Mar 2, 2022
  2. 02/10 t5540: don't rely on "hook/post-update.sample"Ævar Arnfjörð Bjarmason, Mar 2, 2022
  3. Junio C HamanoMar 2, 2022
  4. 01/10 hook tests: turn exit code assertions into a loopÆvar Arnfjörð Bjarmason, Mar 2, 2022
  5. Junio C HamanoMar 2, 2022
  6. 03/10 tests: assume the hooks are disabled by defaultÆvar Arnfjörð Bjarmason, Mar 2, 2022
  7. Junio C HamanoMar 2, 2022
  8. 04/10 bugreport tests: tighten up "git bugreport -s hooks" testÆvar Arnfjörð Bjarmason, Mar 2, 2022
  9. Junio C HamanoMar 2, 2022
  10. 05/10 tests: indent and add hook setup to "test_expect_success"Ævar Arnfjörð Bjarmason, Mar 2, 2022
  11. Junio C HamanoMar 2, 2022
  12. 06/10 hook tests: get rid of unnecessary sub-shellsÆvar Arnfjörð Bjarmason, Mar 2, 2022
  13. Junio C HamanoMar 2, 2022
  14. 07/10 fetch+push tests: have tests clean up their own messÆvar Arnfjörð Bjarmason, Mar 2, 2022
  15. Junio C HamanoMar 2, 2022
  16. 10/10 tests: change "cat && chmod +x" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 2, 2022
  17. Eric SunshineMar 3, 2022
  18. 08/10 test-lib-functions: add and use a "test_hook" wrapperÆvar Arnfjörð Bjarmason, Mar 2, 2022
  19. Junio C HamanoMar 2, 2022
  20. 09/10 tests: change "mkdir -p && write_script" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 2, 2022
  21. Junio C HamanoMar 2, 2022
  22. Junio C HamanoMar 2, 2022
  23. 00/10 tests: add and use a "test_hook" wrapper + hook fixesÆvar Arnfjörð Bjarmason, Mar 7, 2022
  24. 01/10 hook tests: turn exit code assertions into a loopÆvar Arnfjörð Bjarmason, Mar 7, 2022
  25. 02/10 t5540: don't rely on "hook/post-update.sample"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  26. 03/10 tests: assume the hooks are disabled by defaultÆvar Arnfjörð Bjarmason, Mar 7, 2022
  27. 04/10 bugreport tests: tighten up "git bugreport -s hooks" testÆvar Arnfjörð Bjarmason, Mar 7, 2022
  28. 05/10 tests: indent and add hook setup to "test_expect_success"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  29. 06/10 hook tests: get rid of unnecessary sub-shellsÆvar Arnfjörð Bjarmason, Mar 7, 2022
  30. 08/10 test-lib-functions: add and use a "test_hook" wrapperÆvar Arnfjörð Bjarmason, Mar 7, 2022
  31. 07/10 fetch+push tests: have tests clean up their own messÆvar Arnfjörð Bjarmason, Mar 7, 2022
  32. 10/10 tests: change "cat && chmod +x" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  33. 09/10 tests: change "mkdir -p && write_script" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  34. Junio C HamanoMar 7, 2022
  35. 00/13 tests: add and use a "test_hook" wrapper + hook fixesÆvar Arnfjörð Bjarmason, Mar 17, 2022
  36. 01/13 test-lib-functions: add and use a "test_hook" wrapperÆvar Arnfjörð Bjarmason, Mar 17, 2022
  37. 03/13 http tests: don't rely on "hook/post-update.sample"Ævar Arnfjörð Bjarmason, Mar 17, 2022
  38. 02/13 hook tests: turn exit code assertions into a loopÆvar Arnfjörð Bjarmason, Mar 17, 2022
  39. 04/13 tests: assume the hooks are disabled by defaultÆvar Arnfjörð Bjarmason, Mar 17, 2022
  40. 05/13 bugreport tests: tighten up "git bugreport -s hooks" testÆvar Arnfjörð Bjarmason, Mar 17, 2022
  41. 06/13 fetch+push tests: use "test_hook" and "test_when_finished" patternÆvar Arnfjörð Bjarmason, Mar 17, 2022
  42. 08/13 tests: change "cat && chmod +x" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 17, 2022
  43. 10/13 tests: use "test_hook" for misc "mkdir -p" and "chmod" casesÆvar Arnfjörð Bjarmason, Mar 17, 2022
  44. 07/13 gc + p4 tests: use "test_hook", remove sub-shellsÆvar Arnfjörð Bjarmason, Mar 17, 2022
  45. 09/13 tests: change "mkdir -p && write_script" to use "test_hook"Ævar Arnfjörð Bjarmason, Mar 17, 2022
  46. 11/13 tests: extend "test_hook" for "rm" and "chmod -x", convert "$HOOK"Ævar Arnfjörð Bjarmason, Mar 17, 2022
  47. 13/13 http tests: use "test_hook" for "smart" and "dumb" http testsÆvar Arnfjörð Bjarmason, Mar 17, 2022
  48. 12/13 proc-receive hook tests: use "test_hook" instead of "write_script"Ævar Arnfjörð Bjarmason, Mar 17, 2022
  49. Junio C HamanoMar 17, 2022
  50. Ævar Arnfjörð BjarmasonMar 17, 2022
  51. Junio C HamanoMar 17, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.