Re: [PATCH en/cascade-tests] tests: add missing &&

16 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH en/cascade-tests] tests: add missing &&

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:57

Jonathan Nieder [off-list ref] writes:
quoted hunk
@@ -27,7 +27,7 @@ test_expect_success 'see what we expect' '
 	>junk/"$auml" &&
 	case "$(cd junk && echo *)" in
 	"$aumlcdiar")
-		test_unicode=test_expect_failure
+		test_unicode=test_expect_failure &&
 		unibad=t
 		;;
 	*)	;;
This seems to prepare for a case where a simple variable assignment fails
for whategver reason, which is not too bad, but ...
quoted hunk
@@ -36,7 +36,7 @@ test_expect_success 'see what we expect' '
 	{
 		ln -s x y 2> /dev/null &&
 		test -h y 2> /dev/null ||
-		no_symlinks=1
+		no_symlinks=1 &&
 		rm -f y
... if you allowed such a simple assignment failure, no_symlinks=1 may
fail, and we end up not running "rm -f y" to clean up, which might be
somewhat undesirable ;-)

Looked up to but not including t5302 and all looked Ok.

[PATCH/RFC 00/10] Re: [PATCH en/cascade-tests] tests: add missing &&

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Junio C Hamano wrote:
Jonathan Nieder [off-list ref] writes:
quoted
@@ -36,7 +36,7 @@ test_expect_success 'see what we expect' '
 	{
 		ln -s x y 2> /dev/null &&
 		test -h y 2> /dev/null ||
-		no_symlinks=1
+		no_symlinks=1 &&
 		rm -f y
... if you allowed such a simple assignment failure, no_symlinks=1 may
fail, and we end up not running "rm -f y" to clean up, which might be
somewhat undesirable ;-)
Thanks.  Will undo that bit in my local version.

Actually I don't see why the "rm -f y" is needed in the first place,
but that is a question for another day.

Here's another batch of patches in the same &&-adding vein.  I'm only
sending 10 to the list for now; I can mete the rest out at whatever
rate is useful to people.

Jonathan Nieder (27):
  tests: more missing &&
  test-lib: introduce test_line_count to measure files
  t6022 (renaming merge): chain test commands with &&
  t1502 (rev-parse --parseopt): test exit code from "-h"
  t1400 (update-ref): use test_must_fail
  t3301 (notes): use test_expect_code for clarity
  t3404 (rebase -i): unroll test_commit loops
  t3404 (rebase -i): move comment to description
  t3404 (rebase -i): introduce helper to check position of HEAD
  t4124 (apply --whitespace): use test_might_fail
  t5701 (clone -l): use test_must_fail
  ttt03, t6032: use test_might_fail
  t6032 (merge): give body of rename tests its own function
  t7001 (mv): introduce test_grep function and use it
  t7004 (tag): use test_must_fail
  t9146 (git svn): check exit status from svn in loop
  t9146 (git svn): use test_path_is_dir/missing helpers
  t8007 (textconv): use test_must_fail
  t7502 (commit): use test_must_fail
  t0005 (signals): hide test-sigchain invocation from &&-chaining
    checker
  t0020 (convert): improve error checking in loops
  t0020 (convert): use diff-index --exit-code
  t0020 (convert): remove "Huh?" noise
  t0040 (parse-options): use test_expect_code
  t7300 (clean): use test_cmp instead of test "$foo" = bar
  t1501 (rev-parse): use sane_unset
  t4022 (diff -B): simplify using test_grep

 t/README                      |    9 ++
 t/t0005-signals.sh            |   16 ++-
 t/t0020-crlf.sh               |  247 +++++++++---------------------------
 t/t0040-parse-options.sh      |   12 +-
 t/t1400-update-ref.sh         |   25 ++--
 t/t1501-worktree.sh           |    4 +-
 t/t1502-rev-parse-parseopt.sh |    2 +-
 t/t3301-notes.sh              |    8 +-
 t/t3404-rebase-interactive.sh |   88 ++++++-------
 t/t4022-diff-rewrite.sh       |    9 +-
 t/t4124-apply-ws-rule.sh      |   11 +-
 t/t5503-tagfollow.sh          |   10 +-
 t/t5701-clone-local.sh        |   22 +---
 t/t6022-merge-rename.sh       |  282 +++++++++++++---------------------------
 t/t6032-merge-large-rename.sh |   36 ++++--
 t/t7001-mv.sh                 |    8 +-
 t/t7004-tag.sh                |   36 +++---
 t/t7300-clean.sh              |   25 ++--
 t/t7502-commit.sh             |    4 +-
 t/t7700-repack.sh             |    6 +-
 t/t8007-cat-file-textconv.sh  |    2 +-
 t/t9146-git-svn-empty-dirs.sh |   64 ++++------
 t/test-lib.sh                 |   57 ++++++++
 23 files changed, 395 insertions(+), 588 deletions(-)

-- 
1.7.2.3.557.gab647.dirty

[PATCH 01/10] tests: add missing &&, batch 2

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Same rules as before: this patch only adds " &&" to the end of
some lines in the test suite.

Intended to be applied on top of or squashed with the last
batch if they look okay.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t0020-crlf.sh               |    2 +-
 t/t1400-update-ref.sh         |   20 ++++++++++----------
 t/t3301-notes.sh              |    6 +++---
 t/t3404-rebase-interactive.sh |    6 +++---
 t/t4124-apply-ws-rule.sh      |    6 +++---
 t/t5503-tagfollow.sh          |    6 +++---
 t/t5701-clone-local.sh        |    6 +++---
 t/t7001-mv.sh                 |    2 +-
 t/t7004-tag.sh                |   30 +++++++++++++++---------------
 t/t7300-clean.sh              |    2 +-
 t/t7502-commit.sh             |    2 +-
 t/t7700-repack.sh             |    6 +++---
 t/t9146-git-svn-empty-dirs.sh |    2 +-
 13 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh
index 234a94f..1a8f44c 100755
--- a/t/t0020-crlf.sh
+++ b/t/t0020-crlf.sh
@@ -439,7 +439,7 @@ test_expect_success 'checkout when deleting .gitattributes' '
 	git rm .gitattributes &&
 	echo "contentsQ" | q_to_cr > .file2 &&
 	git add .file2 &&
-	git commit -m third
+	git commit -m third &&
 
 	git checkout master~1 &&
 	git checkout master &&
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index 54ba3df..d17551e 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -185,55 +185,55 @@ gd="Thu, 26 May 2005 18:33:00 -0500"
 ld="Thu, 26 May 2005 18:43:00 -0500"
 test_expect_success \
 	'Query "master@{May 25 2005}" (before history)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
 	 test '"$C"' = $(cat o) &&
 	 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
 test_expect_success \
 	"Query master@{2005-05-25} (before history)" \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify master@{2005-05-25} >o 2>e &&
 	 test '"$C"' = $(cat o) &&
 	 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
 test_expect_success \
 	'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
 	 test '"$C"' = $(cat o) &&
 	 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
 test_expect_success \
 	'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
 	 test '"$C"' = $(cat o) &&
 	 test "" = "$(cat e)"'
 test_expect_success \
 	'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
 	 test '"$A"' = $(cat o) &&
 	 test "" = "$(cat e)"'
 test_expect_success \
 	'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
 	 test '"$B"' = $(cat o) &&
 	 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
 test_expect_success \
 	'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
 	 test '"$Z"' = $(cat o) &&
 	 test "" = "$(cat e)"'
 test_expect_success \
 	'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
 	 test '"$E"' = $(cat o) &&
 	 test "" = "$(cat e)"'
 test_expect_success \
 	'Query "master@{2005-05-28}" (past end of history)' \
-	'rm -f o e
+	'rm -f o e &&
 	 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
 	 test '"$D"' = $(cat o) &&
 	 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
@@ -247,7 +247,7 @@ test_expect_success \
      git add F &&
 	 GIT_AUTHOR_DATE="2005-05-26 23:30" \
 	 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
-	 h_TEST=$(git rev-parse --verify HEAD)
+	 h_TEST=$(git rev-parse --verify HEAD) &&
 	 echo The other day this did not work. >M &&
 	 echo And then Bob told me how to fix it. >>M &&
 	 echo OTHER >F &&
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index a2b79a0..6931171 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -627,16 +627,16 @@ test_expect_success '--show-notes=ref accumulates' '
 
 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 	git config core.notesRef refs/notes/other &&
-	echo "Note on a tree" > expect
+	echo "Note on a tree" > expect &&
 	git notes add -m "Note on a tree" HEAD: &&
 	git notes show HEAD: > actual &&
 	test_cmp expect actual &&
-	echo "Note on a blob" > expect
+	echo "Note on a blob" > expect &&
 	filename=$(git ls-tree --name-only HEAD | head -n1) &&
 	git notes add -m "Note on a blob" HEAD:$filename &&
 	git notes show HEAD:$filename > actual &&
 	test_cmp expect actual &&
-	echo "Note on a tag" > expect
+	echo "Note on a tag" > expect &&
 	git tag -a -m "This is an annotated tag" foobar HEAD^ &&
 	git notes add -m "Note on a tag" foobar &&
 	git notes show foobar > actual &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 7d20a74..c0e69f6 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -46,7 +46,7 @@ test_expect_success 'setup' '
 	test_commit G file1 &&
 	test_commit H file5 &&
 	git checkout -b branch2 F &&
-	test_commit I file6
+	test_commit I file6 &&
 	git checkout -b conflict-branch A &&
 	for n in one two three four
 	do
@@ -584,7 +584,7 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
 
 	git checkout -b branch4 HEAD &&
 	GIT_EDITOR=: git commit --amend \
-		--author="Somebody else <somebody@else.com>" 
+		--author="Somebody else <somebody@else.com>" &&
 	test $(git rev-parse branch3) != $(git rev-parse branch4) &&
 	git rebase -i branch3 &&
 	test $(git rev-parse branch3) = $(git rev-parse branch4)
@@ -599,7 +599,7 @@ test_expect_success 'submodule rebase setup' '
 		git add elif && git commit -m "submodule initial"
 	) &&
 	echo 1 >file1 &&
-	git add file1 sub
+	git add file1 sub &&
 	test_tick &&
 	git commit -m "One" &&
 	echo 2 >file1 &&
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index 8a676a5..414b09b 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -368,7 +368,7 @@ test_expect_success 'missing blanks at EOF must only match blank lines' '
 	git diff -- one >patch &&
 
 	echo a >one &&
-	test_must_fail git apply patch
+	test_must_fail git apply patch &&
 	test_must_fail git apply --whitespace=fix patch &&
 	test_must_fail git apply --ignore-space-change --whitespace=fix patch
 '
@@ -419,7 +419,7 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol set' '
 	printf "b\r\n" >>one &&
 	printf "c\r\n" >>one &&
 	cp one save-one &&
-	printf "                 \r\n" >>one
+	printf "                 \r\n" >>one &&
 	git add one &&
 	printf "d\r\n" >>one &&
 	cp one expect &&
@@ -436,7 +436,7 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol unset' '
 	printf "b\r\n" >>one &&
 	printf "c\r\n" >>one &&
 	cp one save-one &&
-	printf "                 \r\n" >>one
+	printf "                 \r\n" >>one &&
 	git add one &&
 	cp one expect &&
 	printf "d\r\n" >>one &&
diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh
index 8a298a6..7f6d3d2 100755
--- a/t/t5503-tagfollow.sh
+++ b/t/t5503-tagfollow.sh
@@ -54,7 +54,7 @@ EOF
 '
 
 test_expect_success NOT_MINGW 'fetch A (new commit : 1 connection)' '
-	rm -f $U
+	rm -f $U &&
 	(
 		cd cloned &&
 		GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
@@ -87,7 +87,7 @@ EOF
 '
 
 test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
-	rm -f $U
+	rm -f $U &&
 	(
 		cd cloned &&
 		GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
@@ -126,7 +126,7 @@ EOF
 '
 
 test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
-	rm -f $U
+	rm -f $U &&
 	(
 		cd cloned &&
 		GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 8b4c356..0f4d487 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -10,11 +10,11 @@ test_expect_success 'preparing origin repository' '
 	git clone --bare . a.git &&
 	git clone --bare . x &&
 	test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
-	test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true
+	test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true &&
 	git bundle create b1.bundle --all &&
 	git bundle create b2.bundle master &&
 	mkdir dir &&
-	cp b1.bundle dir/b3
+	cp b1.bundle dir/b3 &&
 	cp b1.bundle b4
 '
 
@@ -112,7 +112,7 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
 	cd "$D" &&
 	git clone b2.bundle b2 &&
 	cd b2 &&
-	git fetch
+	git fetch &&
 	test ! -e .git/refs/heads/master
 '
 
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 624e6d2..a845b15 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -207,7 +207,7 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' '
 	git init &&
 	echo 1 >dirty &&
 	git add dirty &&
-	entry="$(git ls-files --stage dirty | cut -f 1)"
+	entry="$(git ls-files --stage dirty | cut -f 1)" &&
 	git mv dirty dirty2 &&
 	[ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] &&
 	echo 2 >dirty2 &&
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index ac943f5..d05f421 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1097,7 +1097,7 @@ hash1=$(git rev-parse HEAD)
 test_expect_success 'creating second commit and tag' '
 	echo foo-2.0 >foo &&
 	git add foo &&
-	git commit -m second
+	git commit -m second &&
 	git tag v2.0
 '
 
@@ -1122,18 +1122,18 @@ v2.0
 EOF
 
 test_expect_success 'checking that first commit is in all tags (hash)' "
-	git tag -l --contains $hash1 v* >actual
+	git tag -l --contains $hash1 v* >actual &&
 	test_cmp expected actual
 "
 
 # other ways of specifying the commit
 test_expect_success 'checking that first commit is in all tags (tag)' "
-	git tag -l --contains v1.0 v* >actual
+	git tag -l --contains v1.0 v* >actual &&
 	test_cmp expected actual
 "
 
 test_expect_success 'checking that first commit is in all tags (relative)' "
-	git tag -l --contains HEAD~2 v* >actual
+	git tag -l --contains HEAD~2 v* >actual &&
 	test_cmp expected actual
 "
 
@@ -1142,7 +1142,7 @@ v2.0
 EOF
 
 test_expect_success 'checking that second commit only has one tag' "
-	git tag -l --contains $hash2 v* >actual
+	git tag -l --contains $hash2 v* >actual &&
 	test_cmp expected actual
 "
 
@@ -1151,7 +1151,7 @@ cat > expected <<EOF
 EOF
 
 test_expect_success 'checking that third commit has no tags' "
-	git tag -l --contains $hash3 v* >actual
+	git tag -l --contains $hash3 v* >actual &&
 	test_cmp expected actual
 "
 
@@ -1161,7 +1161,7 @@ test_expect_success 'creating simple branch' '
 	git branch stable v2.0 &&
         git checkout stable &&
 	echo foo-3.0 > foo &&
-	git commit foo -m fourth
+	git commit foo -m fourth &&
 	git tag v3.0
 '
 
@@ -1172,7 +1172,7 @@ v3.0
 EOF
 
 test_expect_success 'checking that branch head only has one tag' "
-	git tag -l --contains $hash4 v* >actual
+	git tag -l --contains $hash4 v* >actual &&
 	test_cmp expected actual
 "
 
@@ -1186,7 +1186,7 @@ v4.0
 EOF
 
 test_expect_success 'checking that original branch head has one tag now' "
-	git tag -l --contains $hash3 v* >actual
+	git tag -l --contains $hash3 v* >actual &&
 	test_cmp expected actual
 "
 
@@ -1201,18 +1201,18 @@ v4.0
 EOF
 
 test_expect_success 'checking that initial commit is in all tags' "
-	git tag -l --contains $hash1 v* >actual
+	git tag -l --contains $hash1 v* >actual &&
 	test_cmp expected actual
 "
 
 # mixing modes and options:
 
 test_expect_success 'mixing incompatibles modes and options is forbidden' '
-	test_must_fail git tag -a
-	test_must_fail git tag -l -v
-	test_must_fail git tag -n 100
-	test_must_fail git tag -l -m msg
-	test_must_fail git tag -l -F some file
+	test_must_fail git tag -a &&
+	test_must_fail git tag -l -v &&
+	test_must_fail git tag -n 100 &&
+	test_must_fail git tag -l -m msg &&
+	test_must_fail git tag -l -F some file &&
 	test_must_fail git tag -v -s
 '
 
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 6c776e9..c802ef8 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -183,7 +183,7 @@ test_expect_success 'git clean symbolic link' '
 
 	mkdir -p build docs &&
 	touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
-	ln -s docs/manual.txt src/part4.c
+	ln -s docs/manual.txt src/part4.c &&
 	git clean &&
 	test -f Makefile &&
 	test -f README &&
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index c1c6645..50da034 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -390,7 +390,7 @@ try_commit_status_combo () {
 
 	test_expect_success 'commit --no-status' '
 		clear_config commit.status &&
-		try_commit --no-status
+		try_commit --no-status &&
 		! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
 	'
 
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index c2f66ff..d954b84 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -56,7 +56,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
 '
 
 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
-	mkdir alt_objects/pack
+	mkdir alt_objects/pack &&
 	mv .git/objects/pack/* alt_objects/pack &&
 	git repack -a &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
@@ -95,14 +95,14 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
 	# swap the .keep so the commit object is in the pack with .keep
 	for p in alt_objects/pack/*.pack
 	do
-		base_name=$(basename $p .pack)
+		base_name=$(basename $p .pack) &&
 		if test -f alt_objects/pack/$base_name.keep
 		then
 			rm alt_objects/pack/$base_name.keep
 		else
 			touch alt_objects/pack/$base_name.keep
 		fi
-	done
+	done &&
 	git repack -a -d &&
 	myidx=$(ls -1 .git/objects/pack/*.idx) &&
 	test -f "$myidx" &&
diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh
index 565365c..158c8e3 100755
--- a/t/t9146-git-svn-empty-dirs.sh
+++ b/t/t9146-git-svn-empty-dirs.sh
@@ -33,7 +33,7 @@ test_expect_success 'more emptiness' '
 '
 
 test_expect_success 'git svn rebase creates empty directory' '
-	( cd cloned && git svn rebase )
+	( cd cloned && git svn rebase ) &&
 	test -d cloned/"! !"
 '
 
-- 
1.7.2.3.557.gab647.dirty

[RFC/PATCH 02/10] test-lib: introduce test_line_count to measure files

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Some tests check their output with code like the following:

	test "$(git ls-files -u B | wc -l)" -eq 3 || {
		echo "BAD: should have left stages for B"
		return 1
	}

The verbose failure condition is used because test, unlike
diff, does not print any useful information about the
nature of the failure when it fails.

Introduce a test_line_count function to help. If used like

	git ls-files -u B >output &&
	test_line_count -eq 3 output

it will produce output like

	test_line_count: line count for output !-eq 3
	100644 b023018cabc396e7692c70bbf5784a93d3f738ab 2	hi.c
	100644 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 3	hi.c

on failure.

Signed-off-by: Jonathan Nieder <redacted>
---
I don't imagine this would be too helpful for new tests,
but the idiom is common enough in old tests that maybe I'm
wrong about that.

 t/README      |    4 ++++
 t/test-lib.sh |   22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/t/README b/t/README
index 2aceb67..1a78982 100644
--- a/t/README
+++ b/t/README
@@ -500,6 +500,10 @@ library for your script to use.
    <expected> file.  This behaves like "cmp" but produces more
    helpful output when the test is run with "-v" option.
 
+ - test_line_count (= | -lt | -ge | ...) <length> <file>
+
+   Check whether a file has the length it is expected to.
+
  - test_path_is_file <file> [<diagnosis>]
    test_path_is_dir <dir> [<diagnosis>]
    test_path_is_missing <path> [<diagnosis>]
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 87308f5..a417bdf 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -598,6 +598,28 @@ test_path_is_missing () {
 	fi
 }
 
+# test_line_count checks that a file has the number of lines it
+# ought to. For example:
+#
+#	test_expect_success 'produce exactly one line of output' '
+#		do something >output &&
+#		test_line_count = 1 output
+#	'
+#
+# is like "test $(wc -l <output) = 1" except that it passes the
+# output through when the number of lines is wrong.
+
+test_line_count () {
+	if test $# != 3
+	then
+		error "bug in the test script: not 3 parameters to test_line_count"
+	elif ! test $(wc -l <"$3") "$1" "$2"
+	then
+		echo "test_line_count: line count for $3 !$1 $2"
+		cat "$3"
+		return 1
+	fi
+}
 
 # This is not among top-level (test_expect_success | test_expect_failure)
 # but is a prefix that can be used in the test script, like:
-- 
1.7.2.3.557.gab647.dirty

[PATCH 03/10] t6022 (renaming merge): chain test commands with &&

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Using 'return' in an attempt to end a test assertion can have
unpredictable results (probably escaping from test_run_ and breaking
its bookkeeping).  Redo the control flow using helpers like
test_expect_code and git diff --exit-code, so each test assertion can
follow the usual form

	command that should succeed &&
	command that should succeed &&
	command that should succeed &&
	...

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t6022-merge-rename.sh |  282 +++++++++++++++-------------------------------
 1 files changed, 92 insertions(+), 190 deletions(-)
diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh
index b66544b..83efc7a 100755
--- a/t/t6022-merge-rename.sh
+++ b/t/t6022-merge-rename.sh
@@ -94,245 +94,147 @@ git checkout master'
 
 test_expect_success 'pull renaming branch into unrenaming one' \
 '
-	git show-branch
-	git pull . white && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	git ls-files -s
-	test "$(git ls-files -u B | wc -l)" -eq 3 || {
-		echo "BAD: should have left stages for B"
-		return 1
-	}
-	test "$(git ls-files -s N | wc -l)" -eq 1 || {
-		echo "BAD: should have merged N"
-		return 1
-	}
+	git show-branch &&
+	test_expect_code 1 git pull . white &&
+	git ls-files -s &&
+	git ls-files -u B >b.stages &&
+	test_line_count = 3 b.stages &&
+	git ls-files -s N >n.stages &&
+	test_line_count = 1 n.stages &&
 	sed -ne "/^g/{
 	p
 	q
-	}" B | grep master || {
-		echo "BAD: should have listed our change first"
-		return 1
-	}
-	test "$(git diff white N | wc -l)" -eq 0 || {
-		echo "BAD: should have taken colored branch"
-		return 1
-	}
+	}" B | grep master &&
+	git diff --exit-code white N
 '
 
 test_expect_success 'pull renaming branch into another renaming one' \
 '
-	rm -f B
-	git reset --hard
-	git checkout red
-	git pull . white && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	test "$(git ls-files -u B | wc -l)" -eq 3 || {
-		echo "BAD: should have left stages"
-		return 1
-	}
-	test "$(git ls-files -s N | wc -l)" -eq 1 || {
-		echo "BAD: should have merged N"
-		return 1
-	}
+	rm -f B &&
+	git reset --hard &&
+	git checkout red &&
+	test_expect_code 1 git pull . white &&
+	git ls-files -u B >b.stages &&
+	test_line_count = 3 b.stages &&
+	git ls-files -s N >n.stages &&
+	test_line_count = 1 n.stages &&
 	sed -ne "/^g/{
 	p
 	q
-	}" B | grep red || {
-		echo "BAD: should have listed our change first"
-		return 1
-	}
-	test "$(git diff white N | wc -l)" -eq 0 || {
-		echo "BAD: should have taken colored branch"
-		return 1
-	}
+	}" B | grep red &&
+	git diff --exit-code white N
 '
 
 test_expect_success 'pull unrenaming branch into renaming one' \
 '
-	git reset --hard
-	git show-branch
-	git pull . master && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	test "$(git ls-files -u B | wc -l)" -eq 3 || {
-		echo "BAD: should have left stages"
-		return 1
-	}
-	test "$(git ls-files -s N | wc -l)" -eq 1 || {
-		echo "BAD: should have merged N"
-		return 1
-	}
+	git reset --hard &&
+	git show-branch &&
+	test_expect_code 1 git pull . master &&
+	git ls-files -u B >b.stages &&
+	test_line_count = 3 b.stages &&
+	git ls-files -s N >n.stages &&
+	test_line_count = 1 n.stages &&
 	sed -ne "/^g/{
 	p
 	q
-	}" B | grep red || {
-		echo "BAD: should have listed our change first"
-		return 1
-	}
-	test "$(git diff white N | wc -l)" -eq 0 || {
-		echo "BAD: should have taken colored branch"
-		return 1
-	}
+	}" B | grep red &&
+	git diff --exit-code white N
 '
 
 test_expect_success 'pull conflicting renames' \
 '
-	git reset --hard
-	git show-branch
-	git pull . blue && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	test "$(git ls-files -u A | wc -l)" -eq 1 || {
-		echo "BAD: should have left a stage"
-		return 1
-	}
-	test "$(git ls-files -u B | wc -l)" -eq 1 || {
-		echo "BAD: should have left a stage"
-		return 1
-	}
-	test "$(git ls-files -u C | wc -l)" -eq 1 || {
-		echo "BAD: should have left a stage"
-		return 1
-	}
-	test "$(git ls-files -s N | wc -l)" -eq 1 || {
-		echo "BAD: should have merged N"
-		return 1
-	}
+	git reset --hard &&
+	git show-branch &&
+	test_expect_code 1 git pull . blue &&
+	git ls-files -u A >a.stages &&
+	test_line_count = 1 a.stages &&
+	git ls-files -u B >b.stages &&
+	test_line_count = 1 b.stages &&
+	git ls-files -u C >c.stages &&
+	test_line_count = 1 c.stages &&
+	git ls-files -s N >n.stages &&
+	test_line_count = 1 n.stages &&
 	sed -ne "/^g/{
 	p
 	q
-	}" B | grep red || {
-		echo "BAD: should have listed our change first"
-		return 1
-	}
-	test "$(git diff white N | wc -l)" -eq 0 || {
-		echo "BAD: should have taken colored branch"
-		return 1
-	}
+	}" B | grep red &&
+	git diff --exit-code white N
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-	git reset --hard
-	git show-branch
-	echo >A this file should not matter
-	git pull . white && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	test -f A || {
-		echo "BAD: should have left A intact"
-		return 1
-	}
+	git reset --hard &&
+	git show-branch &&
+	echo >A this file should not matter &&
+	test_expect_code 1 git pull . white &&
+	test_path_is_file A
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-	git reset --hard
-	git checkout white
-	git show-branch
-	rm -f A
-	echo >A this file should not matter
-	git pull . red && {
-		echo "BAD: should have conflicted"
-		return 1
-	}
-	test -f A || {
-		echo "BAD: should have left A intact"
-		return 1
-	}
+	git reset --hard &&
+	git checkout white &&
+	git show-branch &&
+	rm -f A &&
+	echo >A this file should not matter &&
+	test_expect_code 1 git pull . red &&
+	test_path_is_file A
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-	git reset --hard
-	rm -f A M
-	git checkout -f master
-	git tag -f anchor
-	git show-branch
-	git pull . yellow || {
-		echo "BAD: should have cleanly merged"
-		return 1
-	}
-	test -f M && {
-		echo "BAD: should have removed M"
-		return 1
-	}
+	git reset --hard &&
+	rm -f A M &&
+	git checkout -f master &&
+	git tag -f anchor &&
+	git show-branch &&
+	git pull . yellow &&
+	test_path_is_missing M &&
 	git reset --hard anchor
 '
 
 test_expect_success 'updated working tree file should prevent the merge' '
-
-	git reset --hard
-	rm -f A M
-	git checkout -f master
-	git tag -f anchor
-	git show-branch
-	echo >>M one line addition
-	cat M >M.saved
-	git pull . yellow && {
-		echo "BAD: should have complained"
-		return 1
-	}
-	test_cmp M M.saved || {
-		echo "BAD: should have left M intact"
-		return 1
-	}
+	git reset --hard &&
+	rm -f A M &&
+	git checkout -f master &&
+	git tag -f anchor &&
+	git show-branch &&
+	echo >>M one line addition &&
+	cat M >M.saved &&
+	test_expect_code 128 git pull . yellow &&
+	test_cmp M M.saved &&
 	rm -f M.saved
 '
 
 test_expect_success 'updated working tree file should prevent the merge' '
-
-	git reset --hard
-	rm -f A M
-	git checkout -f master
-	git tag -f anchor
-	git show-branch
-	echo >>M one line addition
-	cat M >M.saved
-	git update-index M
-	git pull . yellow && {
-		echo "BAD: should have complained"
-		return 1
-	}
-	test_cmp M M.saved || {
-		echo "BAD: should have left M intact"
-		return 1
-	}
+	git reset --hard &&
+	rm -f A M &&
+	git checkout -f master &&
+	git tag -f anchor &&
+	git show-branch &&
+	echo >>M one line addition &&
+	cat M >M.saved &&
+	git update-index M &&
+	test_expect_code 128 git pull . yellow &&
+	test_cmp M M.saved &&
 	rm -f M.saved
 '
 
 test_expect_success 'interference with untracked working tree file' '
-
-	git reset --hard
-	rm -f A M
-	git checkout -f yellow
-	git tag -f anchor
-	git show-branch
-	echo >M this file should not matter
-	git pull . master || {
-		echo "BAD: should have cleanly merged"
-		return 1
-	}
-	test -f M || {
-		echo "BAD: should have left M intact"
-		return 1
-	}
-	git ls-files -s | grep M && {
-		echo "BAD: M must be untracked in the result"
-		return 1
-	}
+	git reset --hard &&
+	rm -f A M &&
+	git checkout -f yellow &&
+	git tag -f anchor &&
+	git show-branch &&
+	echo >M this file should not matter &&
+	git pull . master &&
+	test_path_is_file M &&
+	! {
+		git ls-files -s |
+		grep M
+	} &&
 	git reset --hard anchor
 '
 
 test_expect_success 'merge of identical changes in a renamed file' '
-	rm -f A M N
+	rm -f A M N &&
 	git reset --hard &&
 	git checkout change+rename &&
 	GIT_MERGE_VERBOSITY=3 git merge change | grep "^Skipped B" &&
-- 
1.7.2.3.557.gab647.dirty

[PATCH 04/10] t1502 (rev-parse --parseopt): test exit code from "-h"

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

rev-parse --parseopt exits with code 129 (usage error) when asked
to dump usage with -h on behalf of another command.  Scripts can
take advantage of this to avoid trying to parse usage information
as though it were the regular output from some git command.

Noticed with an &&-chaining tester.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t1502-rev-parse-parseopt.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh
index b3195c4..1efd7f7 100755
--- a/t/t1502-rev-parse-parseopt.sh
+++ b/t/t1502-rev-parse-parseopt.sh
@@ -40,7 +40,7 @@ extra1    line above used to cause a segfault but no longer does
 EOF
 
 test_expect_success 'test --parseopt help output' '
-	git rev-parse --parseopt -- -h > output < optionspec
+	test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
 	test_cmp expect output
 '
 
-- 
1.7.2.3.557.gab647.dirty

[PATCH 05/10] t1400 (update-ref): use test_must_fail

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

As t/README explains:

	When a gitcommand dies due to a segfault, test_must_fail
	diagnoses it as an error; "! git <command>" treats it as
	just another expected failure, which would let such a bug
	go unnoticed.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t1400-update-ref.sh |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index d17551e..ff747f8 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -52,9 +52,8 @@ rm -f .git/$m
 
 test_expect_success \
 	"fail to create $n" \
-	"touch .git/$n_dir
-	 git update-ref $n $A >out 2>err"'
-	 test $? != 0'
+	"touch .git/$n_dir &&
+	 test_must_fail git update-ref $n $A >out 2>err"
 rm -f .git/$n_dir out err
 
 test_expect_success \
-- 
1.7.2.3.557.gab647.dirty

[PATCH 06/10] t3301 (notes): use test_expect_code for clarity

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Use the test_expect_code helper instead of open-coding it.

The main behavior change is to print the command and actual exit
status when the test fails.  More importantly, this would make it
easier to add commands before "git notes show" as part of the
same test assertion if needed.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t3301-notes.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 6931171..7e84ab9 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -52,7 +52,7 @@ test_expect_success 'refusing to edit notes in refs/remotes/' '
 
 # 1 indicates caught gracefully by die, 128 means git-show barked
 test_expect_success 'handle empty notes gracefully' '
-	git notes show ; test 1 = $?
+	test_expect_code 1 git notes show
 '
 
 test_expect_success 'show non-existent notes entry with %N' '
-- 
1.7.2.3.557.gab647.dirty

[PATCH 07/10] t3404 (rebase -i): unroll test_commit loops

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Allow test_commit failures in loop iterations before the last one to
cause the test assertion to fail.

More importantly, avoiding these loops makes the test a little
simpler to read and decreases the vertical screen footprint of
the setup test assertion by one line.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t3404-rebase-interactive.sh |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index c0e69f6..b372314 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -48,20 +48,19 @@ test_expect_success 'setup' '
 	git checkout -b branch2 F &&
 	test_commit I file6 &&
 	git checkout -b conflict-branch A &&
-	for n in one two three four
-	do
-		test_commit $n conflict
-	done &&
+	test_commit one conflict &&
+	test_commit two conflict &&
+	test_commit three conflict &&
+	test_commit four conflict &&
 	git checkout -b no-conflict-branch A &&
-	for n in J K L M
-	do
-		test_commit $n file$n
-	done &&
+	test_commit J fileJ &&
+	test_commit K fileK &&
+	test_commit L fileL &&
+	test_commit M fileM &&
 	git checkout -b no-ff-branch A &&
-	for n in N O P
-	do
-		test_commit $n file$n
-	done
+	test_commit N fileN &&
+	test_commit O fileO &&
+	test_commit P fileP
 '
 
 # "exec" commands are ran with the user shell by default, but this may
-- 
1.7.2.3.557.gab647.dirty

[PATCH 08/10] t3404 (rebase -i): move comment to description

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Add a comment describing the setup in t3404 to its --help output.

This should make it easier to decide where to put new functions
without disrupting the flow of the file or obstructing the description
of the test setup.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t3404-rebase-interactive.sh |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index b372314..4097a2d 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -7,6 +7,23 @@ test_description='git rebase interactive
 
 This test runs git rebase "interactively", by faking an edit, and verifies
 that the result still makes sense.
+
+Initial setup:
+
+     one - two - three - four (conflict-branch)
+   /
+ A - B - C - D - E            (master)
+ | \
+ |   F - G - H                (branch1)
+ |     \
+ |\      I                    (branch2)
+ | \
+ |   J - K - L - M            (no-conflict-branch)
+  \
+    N - O - P                 (no-ff-branch)
+
+ where A, B, D and G all touch file1, and one, two, three, four all
+ touch file "conflict".
 '
 . ./test-lib.sh
 
@@ -14,27 +31,9 @@ that the result still makes sense.
 
 set_fake_editor
 
-# Set up the repository like this:
-#
-#     one - two - three - four (conflict-branch)
-#   /
-# A - B - C - D - E            (master)
-# | \
-# |   F - G - H                (branch1)
-# |     \
-# |\      I                    (branch2)
-# | \
-# |   J - K - L - M            (no-conflict-branch)
-#  \
-#    N - O - P                 (no-ff-branch)
-#
-# where A, B, D and G all touch file1, and one, two, three, four all
-# touch file "conflict".
-#
 # WARNING: Modifications to the initial repository can change the SHA ID used
 # in the expect2 file for the 'stop on conflicting pick' test.
 
-
 test_expect_success 'setup' '
 	test_commit A file1 &&
 	test_commit B file1 &&
-- 
1.7.2.3.557.gab647.dirty

[PATCH 09/10] t3404 (rebase -i): introduce helper to check position of HEAD

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

The same code to check the position of HEAD is used by several
tests in this script.  Factor it out as a function and simplify it.

Noticed using an &&-chaining tester, because the current code
does not propagate the precise exit status from errors.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t3404-rebase-interactive.sh |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 4097a2d..4fcedda 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -29,6 +29,12 @@ Initial setup:
 
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
+test_cmp_rev () {
+	git describe --always --tags "$1" >expect.rev &&
+	git describe --always --tags "$2" >actual.rev &&
+	test_cmp expect.rev actual.rev
+}
+
 set_fake_editor
 
 # WARNING: Modifications to the initial repository can change the SHA ID used
@@ -80,20 +86,12 @@ test_expect_success 'rebase -i with the exec command' '
 	test_path_is_file touch-one &&
 	test_path_is_file touch-two &&
 	test_path_is_missing touch-three " (should have stopped before)" &&
-	test $(git rev-parse C) = $(git rev-parse HEAD) || {
-		echo "Stopped at wrong revision:"
-		echo "($(git describe --tags HEAD) instead of C)"
-		false
-	} &&
+	test_cmp_rev C HEAD &&
 	git rebase --continue &&
 	test_path_is_file touch-three &&
 	test_path_is_file "touch-file  name with spaces" &&
 	test_path_is_file touch-after-semicolon &&
-	test $(git rev-parse master) = $(git rev-parse HEAD) || {
-		echo "Stopped at wrong revision:"
-		echo "($(git describe --tags HEAD) instead of master)"
-		false
-	} &&
+	test_cmp_rev master HEAD &&
 	rm -f touch-*
 '
 
@@ -114,11 +112,7 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' '
 	export FAKE_LINES &&
 	test_must_fail git rebase -i HEAD^
 	) &&
-	test $(git rev-parse master^) = $(git rev-parse HEAD) || {
-		echo "Stopped at wrong revision:"
-		echo "($(git describe --tags HEAD) instead of master^)"
-		false
-	} &&
+	test_cmp_rev master^ HEAD &&
 	git reset --hard &&
 	git rebase --continue
 '
-- 
1.7.2.3.557.gab647.dirty

[PATCH 10/10] t4124 (apply --whitespace): use test_might_fail

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:57

Use test_might_fail instead of ignoring the exit status from git
config --unset, and let the exit status propagate past rm -f (which
does not fail on ENOENT).  Otherwise bugs that lead git config to
crash would not be detected when this test runs.

Signed-off-by: Jonathan Nieder <redacted>
---
 t/t4124-apply-ws-rule.sh |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index 414b09b..61bfc56 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -176,9 +176,8 @@ test_expect_success 'trailing whitespace & no newline at the end of file' '
 '
 
 test_expect_success 'blank at EOF with --whitespace=fix (1)' '
-	: these can fail depending on what we did before
-	git config --unset core.whitespace
-	rm -f .gitattributes
+	test_might_fail git config --unset core.whitespace &&
+	rm -f .gitattributes &&
 
 	{ echo a; echo b; echo c; } >one &&
 	git add one &&
-- 
1.7.2.3.557.gab647.dirty

Re: [RFC/PATCH 02/10] test-lib: introduce test_line_count to measure files

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:00

Jonathan Nieder [off-list ref] writes:
Introduce a test_line_count function to help. If used like

	git ls-files -u B >output &&
	test_line_count -eq 3 output

it will produce output like

	test_line_count: line count for output !-eq 3
	100644 b023018cabc396e7692c70bbf5784a93d3f738ab 2	hi.c
	100644 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 3	hi.c

on failure.
Sounds like a sane thing to do.

Especially because you wrote the implementation without surrounding dq
pair, the callers can say "test_line_count = $N $file" instead of -eq and
things will not break.  Nice.

Re: [RFC/PATCH 02/10] test-lib: introduce test_line_count to measure files

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:50:00

On Sun, Oct 31, 2010 at 08:33, Jonathan Nieder [off-list ref] wrote:
Some tests check their output with code like the following:

       test "$(git ls-files -u B | wc -l)" -eq 3 || {
               echo "BAD: should have left stages for B"
               return 1
       }

The verbose failure condition is used because test, unlike
diff, does not print any useful information about the
nature of the failure when it fails.

Introduce a test_line_count function to help. If used like

       git ls-files -u B >output &&
       test_line_count -eq 3 output
In an earlier thread I suggested an interface like:

    test_line_count 3 "git ls-files -u B"

But I like yours much better. Ack.

Re: [PATCH 09/10] t3404 (rebase -i): introduce helper to check position of HEAD

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:03

Jonathan Nieder [off-list ref] writes:
The same code to check the position of HEAD is used by several
tests in this script.  Factor it out as a function and simplify it.
That rationale makes sense, but why use describe for it, especially if the
helper is called "cmp-rev"?  The tests here are not about catching
breakages in describe.

When we later want to move this helper to test-lib.sh, some potential
callers may find it inconvenient that use of describe robs the ability to
tell annotated tags from bare commits.
+test_cmp_rev () {
+	git describe --always --tags "$1" >expect.rev &&
+	git describe --always --tags "$2" >actual.rev &&
+	test_cmp expect.rev actual.rev
+}

Re: [PATCH 08/10] t3404 (rebase -i): move comment to description

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:03

Jonathan Nieder [off-list ref] writes:
Add a comment describing the setup in t3404 to its --help output.
You learn new things every day---I didn't know our tests supported the -h
option ;-)

Yeah, yeah, e1970ce ([PATCH 1/2] Test framework take two., 2005-05-13) was
mine, but I forgot all about it.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help