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

[PATCH 1/4] t7006 (pager): introduce helper for parameterized tests

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 26, 2010, 19:23 UTC
Message-ID
<20100626192302.GA20051@burratino>
In-Reply-To
<20100626192203.GA19973@burratino>

The current tests test pager configuration for ‘git log’, but other commands use a different setup procedure and should therefore be tested separately. Add a helper to make this easier.

This patch introduces the helper and changes some existing tests to use it. The only functional change should be the introduction of ‘git log - ’ to a few test descriptions.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t7006-pager.sh |   72 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 9a83241..b117ebb 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -172,58 +172,94 @@ then
 	test_set_prereq SIMPLEPAGER
 fi
 
-test_expect_success SIMPLEPAGER 'default pager is used by default' '
+# Use this helper to make it easy for the caller of your
+# terminal-using function to specify whether it should fail.
+# If you write
+#
+#	your_test() {
+#		parse_args "$@"
+#
+#		$test_expectation "$cmd - behaves well" "
+#			...
+#			$full_command &&
+#			...
+#		"
+#	}
+#
+# then your test can be used like this:
+#
+#	your_test expect_(success|failure) [test_must_fail] 'git foo'
+#
+parse_args() {
+	test_expectation="test_$1"
+	shift
+	if test "$1" = test_must_fail
+	then
+		full_command="test_must_fail test_terminal "
+		shift
+	else
+		full_command="test_terminal "
+	fi
+	cmd=$1
+	full_command="$full_command $1"
+}
+
+parse_args expect_success 'git log'
+$test_expectation SIMPLEPAGER "$cmd - default pager is used by default" "
 	unset PAGER GIT_PAGER;
 	test_might_fail git config --unset core.pager &&
 	rm -f default_pager_used ||
 	cleanup_fail &&
 
-	cat >$less <<-\EOF &&
+	cat >\$less <<-\EOF &&
 	#!/bin/sh
 	wc >default_pager_used
 	EOF
-	chmod +x $less &&
+	chmod +x \$less &&
 	(
-		PATH=.:$PATH &&
+		PATH=.:\$PATH &&
 		export PATH &&
-		test_terminal git log
+		$full_command
 	) &&
 	test -e default_pager_used
-'
+"
 
-test_expect_success TTY 'PAGER overrides default pager' '
+parse_args expect_success 'git log'
+$test_expectation TTY "$cmd - PAGER overrides default pager" "
 	unset GIT_PAGER;
 	test_might_fail git config --unset core.pager &&
 	rm -f PAGER_used ||
 	cleanup_fail &&
 
-	PAGER="wc >PAGER_used" &&
+	PAGER='wc >PAGER_used' &&
 	export PAGER &&
-	test_terminal git log &&
+	$full_command &&
 	test -e PAGER_used
-'
+"
 
-test_expect_success TTY 'core.pager overrides PAGER' '
+parse_args expect_success 'git log'
+$test_expectation TTY "$cmd - core.pager overrides PAGER" "
 	unset GIT_PAGER;
 	rm -f core.pager_used ||
 	cleanup_fail &&
 
 	PAGER=wc &&
 	export PAGER &&
-	git config core.pager "wc >core.pager_used" &&
-	test_terminal git log &&
+	git config core.pager 'wc >core.pager_used' &&
+	$full_command &&
 	test -e core.pager_used
-'
+"
 
-test_expect_success TTY 'GIT_PAGER overrides core.pager' '
+parse_args expect_success 'git log'
+$test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" "
 	rm -f GIT_PAGER_used ||
 	cleanup_fail &&
 
 	git config core.pager wc &&
-	GIT_PAGER="wc >GIT_PAGER_used" &&
+	GIT_PAGER='wc >GIT_PAGER_used' &&
 	export GIT_PAGER &&
-	test_terminal git log &&
+	$full_command &&
 	test -e GIT_PAGER_used
-'
+"
 
 test_done
-- 
1.7.1.579.ge2549
Previous: Jonathan NiederNext: Jonathan Nieder
Message 2 of 42 in “git --paginate: do not commit pager choice too early”
  1. 0/4 git --paginate: do not commit pager choice too earlyJonathan Nieder, Jun 26, 2010
  2. 1/4 t7006 (pager): introduce helper for parameterized testsJonathan Nieder, Jun 26, 2010
  3. 2/4 t7006: test pager configuration for several git commandsJonathan Nieder, Jun 26, 2010
  4. Jonathan NiederJun 26, 2010
  5. 3/4 tests: local config file should be honored from subdirs of toplevelJonathan Nieder, Jun 26, 2010
  6. 4/4 git --paginate: do not commit pager choice too earlyJonathan Nieder, Jun 26, 2010
  7. Jeff KingJun 28, 2010
  8. Jonathan NiederJun 28, 2010
  9. Jeff KingJun 28, 2010
  10. Nguyen Thai Ngoc DuyJun 28, 2010
  11. Junio C HamanoJun 29, 2010
  12. Junio C HamanoJul 14, 2010
  13. Jonathan NiederJul 14, 2010
  14. git --paginate: paginate external commands againJonathan Nieder, Jul 14, 2010
  15. Nguyen Thai Ngoc DuyJul 18, 2010
  16. 0/12 Re: git --paginate: do not commit pager choice too earlyJonathan Nieder, Aug 6, 2010
  17. 01/12 git wrapper: introduce startup_info structJonathan Nieder, Aug 6, 2010
  18. 02/12 setup: remember whether repository was foundJonathan Nieder, Aug 6, 2010
  19. 03/12 git wrapper: allow setup_git_directory_gently() be called earlierJonathan Nieder, Aug 6, 2010
  20. 04/12 shortlog: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  21. 05/12 grep: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  22. 06/12 apply: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  23. Ævar Arnfjörð BjarmasonAug 15, 2010
  24. Nguyen Thai Ngoc DuyAug 15, 2010
  25. Jonathan NiederAug 15, 2010
  26. 06/12 apply: run setup_git_directory_gently() soonerNguyễn Thái Ngọc Duy, Aug 16, 2010
  27. Junio C HamanoAug 16, 2010
  28. 07/12 bundle: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  29. Thomas RastAug 16, 2010
  30. Jonathan NiederAug 16, 2010
  31. 2/2 t7006 (pager): add missing TTY prerequisiteJonathan Nieder, Aug 16, 2010
  32. Junio C HamanoAug 16, 2010
  33. 08/12 config: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  34. 09/12 index-pack: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  35. 10/12 ls-remote: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  36. 11/12 var: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  37. 12/12 merge-file: run setup_git_directory_gently() soonerJonathan Nieder, Aug 6, 2010
  38. 0/2 fix "check-ref-format --branch" from subdir of toplevelJonathan Nieder, Aug 6, 2010
  39. 1/2 check-ref-format: handle subcommands in separate functionsJonathan Nieder, Aug 6, 2010
  40. 2/2 Allow "check-ref-format --branch" from subdirectoryJonathan Nieder, Aug 6, 2010
  41. Junio C HamanoAug 6, 2010
  42. Nguyen Thai Ngoc DuyAug 6, 2010

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.