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

[PATCH 20/23] test: git test cleanups.

From
Jon Seymour <jon.seymour@gmail.com>
Date
Apr 23, 2011, 07:22 UTC
Message-ID
<1303543372-77843-21-git-send-email-jon.seymour@gmail.com>
In-Reply-To
<1303543372-77843-1-git-send-email-jon.seymour@gmail.com>
---
 Documentation/git-test.txt |   48 +++++++++++++++++++++---------------------
 git-conditions-lib.sh      |    4 +-
 git-test-lib.sh            |   11 +++++----
 t/t1520-test.sh            |   50 ++++++++++++++++++++++----------------------
 4 files changed, 57 insertions(+), 56 deletions(-)
diff --git a/Documentation/git-test.txt b/Documentation/git-test.txt
index b7c3161..4fa765b 100644
--- a/Documentation/git-test.txt
+++ b/Documentation/git-test.txt
@@ -7,7 +7,7 @@ git-test - evaluates one or more conditions about the state of the git working t
 
 SYNOPSIS
 --------
-The git test API is available in the form of a command and also as a shell library. 
+The git test API is available in the form of a command and also as a shell library.
 
 COMMAND SYNOPSIS
 ----------------
@@ -27,28 +27,28 @@ DESCRIPTION
 `git test` provides a uniform, extensible API for evaluating various conditions that
 pertain to the state of a git working tree, index and repository.
 
-Specified conditions are evaluated from left to right. If any condition evaluates to false, 
-the command conditionally prints a diagnostic message to stderr and sets a 
-non-zero status code. Otherwise, sets a status code of zero. 
+Specified conditions are evaluated from left to right. If any condition evaluates to false,
+the command conditionally prints a diagnostic message to stderr and sets a
+non-zero status code. Otherwise, sets a status code of zero.
 
 The message used to report a assertion failure may be overidden by specifying the --message option.
 
-Diagnostic output resulting from an assertion failure may be suppressed with the -q option. 
-Note that the -q option does not suppress diagnostic output that results from the failure to 
+Diagnostic output resulting from an assertion failure may be suppressed with the -q option.
+Note that the -q option does not suppress diagnostic output that results from the failure to
 successfully parse the arguments that configure the test API.
 
-The `assert` and `test_condition` functions differ according to how they handle failing conditions. 
+The `assert` and `test_condition` functions differ according to how they handle failing conditions.
 
-The `assert` function behaves like the test command but assertion failures will cause 
+The `assert` function behaves like the test command but assertion failures will cause
 the current shell to exit with a non-zero status code. To prevent this occurring, invoke
 the `assert` function within a subshell or use the `test_condition` function instead.
 
 The `test_condition` function will not exit the current shell in the event that an assertion failure
-is detected nor will it generate diagnostic relating to an assertion failure to stderr. 
+is detected nor will it generate diagnostic relating to an assertion failure to stderr.
 
-Note, however, that `test_condition` may still exit the current shell with a non-zero status code 
-if it is unable to successfully parse the arguments presented to it. Callers who need to protect 
-against this possibility either guarantee that the required arguments are available or 
+Note, however, that `test_condition` may still exit the current shell with a non-zero status code
+if it is unable to successfully parse the arguments presented to it. Callers who need to protect
+against this possibility either guarantee that the required arguments are available or
 imbed calls to `test_condition` within a subshell.
 
 The `require_condition_libs` function may be used to include any condition libs listed
@@ -77,7 +77,7 @@ CONDITIONS
 '--detached'|'--not-detached'::
 	Tests if the head is (not) detached.
 '--branch-exists'|'--not-branch-exists branch'::
-        Tests if the specified branch does (not) exist.				    
+	Tests if the specified branch does (not) exist.
 '--tag-exists'|'--not-tag-exists tag'::
         Tests if the specified tag does (not) exist.
 '--ref-exists'|'--not-ref-exists tag'::
@@ -95,15 +95,15 @@ CONDITIONS
 
 EXTENDING THE CONDITION LIBRARY
 -------------------------------
-The library of conditions that the assert API can process may be extended by 
-adding functions of the form check_\{dehyphenated_condition_name\}_N to the 
-shell environment, where \{dehyphenated_condition_name\} is the result of 
-replacing any occurrence of \'-\' in the condition name with \'_\' and 
+The library of conditions that the assert API can process may be extended by
+adding functions of the form check_\{dehyphenated_condition_name\}_N to the
+shell environment, where \{dehyphenated_condition_name\} is the result of
+replacing any occurrence of \'-\' in the condition name with \'_\' and
 N is the number of arguments that need to be passed to the function.
 
-For example, suppose you are writing a script, foo.sh, that includes the git test library 
-and that you want to add a new, 1-argument, condition, foo-X to the library of 
-conditions that can be tested by the git testion framework. 
+For example, suppose you are writing a script, foo.sh, that includes the git test library
+and that you want to add a new, 1-argument, condition, foo-X to the library of
+conditions that can be tested by the git testion framework.
 
 ---------
 #/bin/sh
@@ -133,8 +133,8 @@ executes without generating any output on stdout. The resulting
 state will then be interpreted as condition evaluation failure
 rather than an assertion failure.
 
-To make such conditions available to the git test command line, put the 
-function in a file called ~/foo-lib,sh add a reference 
+To make such conditions available to the git test command line, put the
+function in a file called ~/foo-lib,sh add a reference
 to the library to the git configuration, like so:
 
 ---------
@@ -163,9 +163,9 @@ git test --not-staged --not-unstaged && git reset --hard another-commit
 -----------
 . $(git --exec-path)/git-test-lib
 assert --not-staged   	      	                              # die if there are any staged files
-assert --message "there are staged files" --not-staged	      # die with an alternative message 
+assert --message "there are staged files" --not-staged	      # die with an alternative message
                                                               # if there are any staged files
-test_condition --not-staged || echo "there are staged files"  # check whether there are staged files, 
+test_condition --not-staged || echo "there are staged files"  # check whether there are staged files,
                                                               # but do not die if there are
 -----------
 
diff --git a/git-conditions-lib.sh b/git-conditions-lib.sh
index ec9b516..8933321 100644
--- a/git-conditions-lib.sh
+++ b/git-conditions-lib.sh
@@ -141,13 +141,13 @@ check_reachable_2()
 	first=$(git rev-parse --quiet --verify "$1" 2>/dev/null) || die "'$1' is not a commit"
 	second=$(git rev-parse --quiet --verify "$2" 2>/dev/null) || die "'$2' is not a commit"
 	if test "$first" = "$second" \
-                -o -z "$(git rev-list -n1 "$first" ^"$second")" 
+	    -o -z "$(git rev-list -n1 "$first" ^"$second")"
 	then
 		echo "'$1' is reachable from '$2'."
 	else
 		echo "'$1' is not reachable from '$2'."
 		false
-	fi     
+	fi
 }
 
 check_tree_same_2()
diff --git a/git-test-lib.sh b/git-test-lib.sh
index 159cea6..e0395eb 100644
--- a/git-test-lib.sh
+++ b/git-test-lib.sh
@@ -34,7 +34,7 @@ require_lib()
 require_condition_libs() {
 	eval $(
 		git config --get-all condition.lib | while read lib
-		do 
+		do
 			echo "require_lib \"$lib\" \;"
 		done	
 	)
@@ -42,7 +42,7 @@ require_condition_libs() {
 
 assertion_failed() {
 	rc=$1
-	shift 
+	shift
 	message="${MESSAGE:-$*}"
 	if ! ${QUIET:-false}
 	then
@@ -98,6 +98,7 @@ impl() {
 		shift
 		case $word in
 			--message)
+			test $# -gt 0 || die "--message requires the following argument to be a message"
 			MESSAGE=$1
 			shift
 			continue
@@ -106,7 +107,7 @@ impl() {
 				test $# -gt 0 || die "can't shift 1 argument for --include option"
 				test -f "$1" || die "'$1' must be a file"
 				require_lib "$1"
-				shift 
+				shift
 				continue
 			;;
 			-q)
@@ -143,7 +144,7 @@ impl() {
 
 		exprs="${exprs}${exprs:+ }${negation}${negation:+ }$word $try check_${dehyphenated}_$try $args"
 
-	done 
+	done
 
 	set -- $exprs
 	while test $# -gt 0
@@ -158,7 +159,7 @@ impl() {
 		word=$1
 		nargs=$2
 		shift 2
-		message=$(eval $negation "$@") 
+		message=$(eval $negation "$@")
 		rc=$?
 		if test $rc -ne 0
 		then
diff --git a/t/t1520-test.sh b/t/t1520-test.sh
index 1db3598..3e0571b 100755
--- a/t/t1520-test.sh
+++ b/t/t1520-test.sh
@@ -46,7 +46,7 @@ test_expect_assertion_failure()
 {
 	test=$1
 	message=$2
-	shift 
+	shift
 	test_expect_success $1 \
 "
 	! actual_message=$(git test "$@" 1>&2) &&
@@ -62,11 +62,11 @@ test_expect_assertion_failure()
 
 test_expect_success 'setup' \
 '
-	git add test-assertions-lib.sh empty-assertions-lib.sh && 
+	git add test-assertions-lib.sh empty-assertions-lib.sh &&
 	test_commit base &&
 	test_commit A &&
 	git checkout A^1 &&
-	test_commit B && 
+	test_commit B &&
 	git checkout master &&
 	test_merge M B &&
 	echo C >> B.t &&
@@ -85,7 +85,7 @@ test_expect_success 'setup' \
 	git checkout A^0 -- &&
 	test_commit G &&
 	git checkout master &&
-	git reset --hard D     
+	git reset --hard D
 '
 
 test_expect_success 'git test # no arguments' \
@@ -194,7 +194,7 @@ test_expect_success 'git test --not-unstaged' \
 
 test_expect_success 'git test --unstaged # when there are unstaged files' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_UNSTAGED &&
 	git test --unstaged
@@ -202,7 +202,7 @@ test_expect_success 'git test --unstaged # when there are unstaged files' \
 
 test_expect_success 'git test --not-unstaged # when there are unstaged files - should fail' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_UNSTAGED &&
 	test_must_fail git test --not-unstaged
@@ -210,7 +210,7 @@ test_expect_success 'git test --not-unstaged # when there are unstaged files - s
 
 test_expect_success 'git test --unstaged # when there are only staged files' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_STAGED &&
 	git test --not-unstaged
@@ -228,7 +228,7 @@ test_expect_success 'git test --not-staged' \
 
 test_expect_success 'git test --staged # when there are staged files' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_STAGED &&
 	git test --staged
@@ -236,7 +236,7 @@ test_expect_success 'git test --staged # when there are staged files' \
 
 test_expect_success 'git test --not-staged # when there are staged files - should fail' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_STAGED &&
 	test_must_fail git test --not-staged
@@ -244,7 +244,7 @@ test_expect_success 'git test --not-staged # when there are staged files - shoul
 
 test_expect_success 'git test --staged # when there are only unstaged files' \
 '
-	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	test_when_finished "git reset --hard HEAD && git checkout master" &&
 	git checkout -f M^0 &&
 	git stash apply --index STASH_UNSTAGED &&
 	git test --not-staged
@@ -262,14 +262,14 @@ test_expect_success 'git test --not-untracked' \
 
 test_expect_success 'git test --untracked # when there are untracked files' \
 '
-	test_when_finished "git clean -fd" && 
+	test_when_finished "git clean -fd" &&
 	:> untracked &&
 	git test --untracked
 '
 
 test_expect_success 'git test --not-untracked # when there are untracked files - should fail' \
 '
-	test_when_finished "git clean -fd" && 
+	test_when_finished "git clean -fd" &&
 	:> untracked &&
 	test_must_fail git test --not-untracked
 '
@@ -286,14 +286,14 @@ test_expect_success 'git test --detached # should fail' \
 
 test_expect_success 'git test --not-detached # when detached, should fail' \
 '
-	test_when_finished "git checkout -f master" && 
+	test_when_finished "git checkout -f master" &&
 	git checkout HEAD^0 &&
 	test_must_fail git test --not-detached
 '
 
 test_expect_success 'git test --detached # when detached' \
 '
-	test_when_finished "git checkout -f master" && 
+	test_when_finished "git checkout -f master" &&
 	git checkout HEAD^0 &&
 	git test --detached
 '
@@ -413,7 +413,7 @@ test_expect_success 'same' \
    git test \
       --same master HEAD \
       --not-same D D1 \
-      --not-same C D 
+      --not-same C D
 '
 
 test_expect_success 'clean' \
@@ -424,7 +424,7 @@ test_expect_success 'clean' \
        --not-detached \
        --not-untracked \
        --not-rebasing \
-       --not-conflicted 
+       --not-conflicted
 '
 
 test_expect_success 'existence' \
@@ -439,7 +439,7 @@ test_expect_success 'existence' \
        --tag-exists D \
        --not-tag-exists N \
        --not-tag-exists master \
-       --not-branch-exists A 
+       --not-branch-exists A
 '
 
 test_expect_success 'git test --conflicted # should fail' \
@@ -454,17 +454,17 @@ test_expect_success 'git test --not-conflicted' \
 
 test_expect_success 'git test --conflicted' \
 '
-	test_when_finished "git reset --hard HEAD" && 
+	test_when_finished "git reset --hard HEAD" &&
         ! git merge F &&
-	git test --conflicted 
+	git test --conflicted
 	
 '
 
 test_expect_success 'git test --not-conflicted # should fail when there are conflcted files' \
 '
-	test_when_finished "git reset --hard HEAD" && 
+	test_when_finished "git reset --hard HEAD" &&
         ! git merge F &&
-	test_must_fail git test --not-conflicted 
+	test_must_fail git test --not-conflicted
 	
 '
 
@@ -482,12 +482,12 @@ test_expect_success 'git test --rebasing' \
 '
 	test_when_finished "
 		git reset --hard HEAD &&
-		git checkout -f master && 
+		git checkout -f master &&
 		git branch -D rebase
-	" && 
+	" &&
         git branch rebase F &&
         ! git rebase --onto D F~1 F
-	git test --rebasing 
+	git test --rebasing
 	
 '
 
@@ -497,7 +497,7 @@ test_expect_success 'git test --not-rebasing' \
 		git reset --hard HEAD &&
 		git checkout -f master &&
 		git branch -D rebase
-	" && 
+	" &&
         git branch rebase F &&
         ! git rebase --onto D F~1 F
 	test_must_fail git test --not-rebasing
-- 
1.7.5.rc1.23.g7f622
Previous: Jon SeymourNext: Jon Seymour
Message 22 of 29 in “RFC: Introducing git-test, git-atomic, git-base and git-work”
  1. 00/23 RFC: Introducing git-test, git-atomic, git-base and git-workJon Seymour, Apr 23, 2011
  2. 01/23 Introduce git-test.sh and git-test-lib.shJon Seymour, Apr 23, 2011
  3. Drew NorthupApr 27, 2011
  4. 02/23 Introduce --unstaged.Jon Seymour, Apr 23, 2011
  5. 03/23 Introduce --stagedJon Seymour, Apr 23, 2011
  6. 04/23 Introduce --untracked.Jon Seymour, Apr 23, 2011
  7. 05/23 Introduce --conflictedJon Seymour, Apr 23, 2011
  8. 06/23 Introduce --rebasingJon Seymour, Apr 23, 2011
  9. 07/23 Introduce --detachedJon Seymour, Apr 23, 2011
  10. 08/23 Introduce --branch-existsJon Seymour, Apr 23, 2011
  11. 09/23 Introduce --tag-existsJon Seymour, Apr 23, 2011
  12. 10/23 Introduce --ref-existsJon Seymour, Apr 23, 2011
  13. 11/23 Introduce --commit-exists.Jon Seymour, Apr 23, 2011
  14. 12/23 Introduce --checked-outJon Seymour, Apr 23, 2011
  15. 13/23 Introduce --reachableJon Seymour, Apr 23, 2011
  16. 14/23 Introduce --tree-same.Jon Seymour, Apr 23, 2011
  17. 15/23 Introduce --sameJon Seymour, Apr 23, 2011
  18. 16/23 miscJon Seymour, Apr 23, 2011
  19. 17/23 whitespace fix.Jon Seymour, Apr 23, 2011
  20. 18/23 tests --conflicted.Jon Seymour, Apr 23, 2011
  21. 19/23 rebasing: add testsJon Seymour, Apr 23, 2011
  22. 20/23 test: git test cleanups.Jon Seymour, Apr 23, 2011
  23. 21/23 Introduce git-atomic.Jon Seymour, Apr 23, 2011
  24. 22/23 Introduce git base.Jon Seymour, Apr 23, 2011
  25. 23/23 Introduce support for the git-work command.Jon Seymour, Apr 23, 2011
  26. Peter BaumannApr 23, 2011
  27. Jon SeymourApr 23, 2011
  28. Jon SeymourApr 23, 2011
  29. Jon SeymourApr 24, 2011

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.