Skip to contentSkip to conversation

t/t3700: convert two uses of negation operator '!' to use test_must_fail

PATCH In review Brandon Casey 8 participants 40 messages Jun 15, 2016 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t/t3700: convert two uses of negation operator '!' to use test_must_fail

From: Brandon Casey <[email protected]>

These two lines use the negation '!' operator to negate the result of a simple command. Since these commands do not contain any pipes or other complexities, the test_must_fail function can be used and is preferred since it will additionally detect termination due to a signal.

This was noticed because the second use of '!' does not include a space between the '!' and the opening parens. Ksh interprets this as follows:

!(pattern-list)
Matches anything except one of the given patterns.

Ksh performs a file glob using the pattern-list and then tries to execute the first file in the list. If a space is added between the '!' and the open parens, then Ksh will not interpret it as a pattern list, but in this case, it is preferred to use test_must_fail, so lets do so.

---
 t/t3700-add.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
t/t3700-add.sh +2 -2
index 47fbf53..d03495d 100755
@@ -268,7 +268,7 @@ test_expect_success 'git add --dry-run of existing changed file' "
 
 test_expect_success 'git add --dry-run of non-existing file' "
 	echo ignored-file >>.gitignore &&
-	! (git add --dry-run track-this ignored-file >actual 2>&1) &&
+	test_must_fail git add --dry-run track-this ignored-file >actual 2>&1 &&
 	echo \"fatal: pathspec 'ignored-file' did not match any files\" | test_cmp - actual
 "
 
@@ -281,7 +281,7 @@ add 'track-this'
 EOF
 
 test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
-	!(git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1) &&
+	test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1 &&
 	test_cmp expect actual
 '
 
Signature · 1 line
1.6.6.2
#1 lore raw
Quoted 4 lines · Brandon Casey

These two lines use the negation '!' operator to negate the result of a simple command.  Since these commands do not contain any pipes or other complexities, the test_must_fail function can be used and is preferred since it will additionally detect termination due to a signal.

Maybe I'm missing something, but unless git add --dry-run is special in being killed due to a signal this seems misguided. We actually prefer to use !, from t/README:

- test_must_fail <git-command>

Run a git command and ensure it fails in a controlled way. Use this instead of "! <git-command>" to fail when git commands segfault.

Quoted 10 lines

This was noticed because the second use of '!' does not include a space between the '!' and the opening parens.  Ksh interprets this as follows:

  !(pattern-list)
     Matches anything except one of the given patterns.

Ksh performs a file glob using the pattern-list and then tries to execute the first file in the list.  If a space is added between the '!' and the open parens, then Ksh will not interpret it as a pattern list, but in this case, it is preferred to use test_must_fail, so lets do so.

Isn't this a completely seperate thing? Was this test really the only bit in the test suite that did "!foo" instead of "! foo" ?

Does the test pass for you if you just:

    @@ -281,7 +281,7 @@ add 'track-this'
     EOF

     test_expect_success 'git add --dry-run --ignore-missing of

non-existing file' '
-       !(git add --dry-run --ignore-missing track-this
ignored-file >actual 2>&1) &&
+       ! (git add --dry-run --ignore-missing track-this
ignored-file >actual 2>&1) &&
       test_cmp expect actual
 '

?

Quoted 35 lines

---
 t/t3700-add.sh |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
t/t3700-add.sh +0 -0
index 47fbf53..d03495d 100755
@@ -268,7 +268,7 @@ test_expect_success 'git add --dry-run of existing changed file' "
 

 test_expect_success 'git add --dry-run of non-existing file' "
       echo ignored-file >>.gitignore &&
-       ! (git add --dry-run track-this ignored-file >actual 2>&1) &&
+       test_must_fail git add --dry-run track-this ignored-file >actual 2>&1 && echo \"fatal: pathspec 'ignored-file' did not match any files\" | test_cmp - actual "

t/t3700-add.sh +0 -0
@@ -281,7 +281,7 @@ add 'track-this'

 EOF

 test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
-       !(git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1) &&
+       test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1 && test_cmp expect actual
 '

--
1.6.6.2

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 11 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines · Brandon Casey

These two lines use the negation '!' operator to negate the result of a simple command. Since these commands do not contain any pipes or other complexities, the test_must_fail function can be used and is preferred since it will additionally detect termination due to a signal.

Maybe I'm missing something, but unless git add --dry-run is special in being killed due to a signal this seems misguided. We actually prefer to use !, from t/README:

Quoted 5 lines

- test_must_fail <git-command>

Run a git command and ensure it fails in a controlled way. Use this instead of "! <git-command>" to fail when git commands segfault.

I think you have misunderstood the explanation of test_must_fail. The paragraph you quoted actually recommends using test_must_fail instead of "! <git-command>".

It says:

Use this instead of "! <git-command>" to fail when git commands segfault.

Or with a slight rewording:

Use test_must_fail instead of "! <git-command>" since test_must_fail will fail when <git-command> segfaults.

See, if "! <git-command>" is used, then if "<git-command>" is terminated due to some flaw in git (like a segfault), then the statement will still be interpreted as a success. When test_must_fail is used, termination due to segfault or other signal is detected, and the statement will fail.

Quoted 6 lines
Quoted 6 lines

This was noticed because the second use of '!' does not include a space between the '!' and the opening parens. Ksh interprets this as follows:

!(pattern-list)
Matches anything except one of the given patterns.

Quoted 7 lines
Quoted 4 lines

Ksh performs a file glob using the pattern-list and then tries to execute the first file in the list. If a space is added between the '!' and the open parens, then Ksh will not interpret it as a pattern list, but in this case, it is preferred to use test_must_fail, so lets do so.

Isn't this a completely seperate thing? Was this test really the only bit in the test suite that did "!foo" instead of "! foo" ?

This was the only instance of "!()" that was failing for me. I didn't look before, but now that I have, there is another instance of "!()" in t5541 that should be fixed. t5541 hasn't caused a problem for me because GIT_TEST_HTTPD must be set in order to enable it, and I haven't done so.

Quoted 1 line

Does the test pass for you if you just:

Yes.

Quoted 13 lines
    @@ -281,7 +281,7 @@ add 'track-this'
     EOF

     test_expect_success 'git add --dry-run --ignore-missing of

non-existing file' '
- !(git add --dry-run --ignore-missing track-this
ignored-file >actual 2>&1) &&
+ ! (git add --dry-run --ignore-missing track-this
ignored-file >actual 2>&1) &&
test_cmp expect actual
'

?

#3 lore raw
Quoted 6 lines · Brandon Casey

I think you have misunderstood the explanation of test_must_fail. The paragraph you quoted actually recommends using test_must_fail instead of "! <git-command>".

It says:

Quoted 7 lines

Use this instead of "! <git-command>" to fail when git commands segfault.

Or with a slight rewording:

Use test_must_fail instead of "! <git-command>" since test_must_fail will fail when <git-command> segfaults.

I think the wording of description of test_must_fail is slightly ambiguous. I read it to mean that:

Use test_must_fail only when you are testing to see if git will segfault.

Rather than:

Use test_must_fail to be safe from git segfaults.

Perhaps the description should be updated to be a bit more clear?

#4 lore raw

PATCH 1/1 t/README: clarify test_must_fail description

From: Brandon Casey <[email protected]>

Some have found the wording of the description to be somewhat ambiguous with respect to when it is desirable to use test_must_fail instead of "! <git-command>". Tweak the wording somewhat to hopefully clarify that it is _because_ test_must_fail can detect segmentation fault that it is desirable to use it instead of "! <git-command>".

---

Quoted 5 lines · Jared Hance

I think the wording of description of test_must_fail is slightly ambiguous. I read it to mean that:

Use test_must_fail only when you are testing to see if git will segfault.

I think that is a correct interpretation. But I ask you this:
Are there times when we would _not_ want to test for segfault? :)

Quoted 6 lines

Rather than:

Use test_must_fail to be safe from git segfaults.

Perhaps the description should be updated to be a bit more clear?

How about this?

 t/README |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
t/README +2 -2
index b906ceb..a830daa 100644
@@ -451,8 +451,8 @@ library for your script to use.
  - test_must_fail <git-command>
 
    Run a git command and ensure it fails in a controlled way.  Use
-   this instead of "! <git-command>" to fail when git commands
-   segfault.
+   this instead of "! <git-command>" since it will fail when git
+   commands segfault.
 
  - test_might_fail <git-command>
 
Signature · 1 line
1.6.6.2
#5 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 40 lines · Brandon Casey

From: Brandon Casey <[email protected]>

Some have found the wording of the description to be somewhat ambiguous with respect to when it is desirable to use test_must_fail instead of "! <git-command>". Tweak the wording somewhat to hopefully clarify that it is _because_ test_must_fail can detect segmentation fault that it is desirable to use it instead of "! <git-command>".

---

Quoted 5 lines · Jared Hance

I think the wording of description of test_must_fail is slightly ambiguous. I read it to mean that:

Use test_must_fail only when you are testing to see if git will segfault.

I think that is a correct interpretation. But I ask you this:
Are there times when we would _not_ want to test for segfault? :)

Quoted 6 lines

Rather than:

Use test_must_fail to be safe from git segfaults.

Perhaps the description should be updated to be a bit more clear?

How about this?

 t/README |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
t/README +0 -0
index b906ceb..a830daa 100644

t/README library for your script to use. · line 455

Quoted 7 lines
t/README +2 -2
@@ -451,8 +451,8 @@ library for your script to use.
  - test_must_fail <git-command>
 
    Run a git command and ensure it fails in a controlled way.  Use
-   this instead of "! <git-command>" to fail when git commands
-   segfault.
+   this instead of "! <git-command>" since it will fail when git
+   commands segfault.

I found your earlier

Use test_must_fail instead of "! <git-command>" since test_must_fail will fail when <git-command> segfaults.

slightly clearer.

- "it" in "since it will fail" is a bit ambiguous: is it "!" or "test_must_fail"?

- it is not obvious if "fail" in "since it will fail" is a good thing or a bad thing; as we are discussing test_MUST_fail, it may even be a good thing that it "will fail"---which is not what we want our audience to read from this.

How about being more explicit?

Run a git command and ensure it fails in a controlled way. Use this instead of "! <git-command>". When git-command dies due to a segfault, test_must_fail diagnoses it as an error; "! <git-command>" treats it as just another expected failure. letting such a bug go unnoticed.

Quoted 10 lines
t/README +0 -0
  - test_might_fail <git-command>
 
Signature · 6 lines
1.6.6.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 5 lines · Junio C Hamano

   Run a git command and ensure it fails in a controlled way.  Use this instead of "! <git-command>".  When git-command dies due to a segfault, test_must_fail diagnoses it as an error; "! <git-command>" treats it as just another expected failure. letting such a bug go unnoticed.

To add to that:

Don't use test_must_fail to negate the return values of commands on the system like grep, sed etc. If we can't trust that the core utilities won't randomly segfault we might as well die horribly.

#7 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

I've written a patch that converted most (all?) of the "! git" to "test_must_fail git". I'll send it as soon as I make sure I didn't somehow break the testsuite with it.

#8 lore raw

PATCH 1/1 Convert "! git" to "test_must_fail" git.

test_must_fail prevents problems with segfault, so it is better to use rather than "! git".

---
 t/t1001-read-tree-m-2way.sh                |    2 +-
 t/t3301-notes.sh                           |    6 +++---
 t/t3306-notes-prune.sh                     |    8 ++++----
 t/t3410-rebase-preserve-dropped-merges.sh  |    8 ++++----
 t/t6037-merge-ours-theirs.sh               |    2 +-
 t/t7509-commit.sh                          |    4 ++--
 t/t7607-merge-overwrite.sh                 |   12 ++++++------
 t/t7810-grep.sh                            |    4 ++--
 t/t9100-git-svn-basic.sh                   |    2 +-
 t/t9130-git-svn-authors-file.sh            |    4 ++--
 t/t9139-git-svn-non-utf8-commitencoding.sh |    2 +-
 t/t9140-git-svn-reset.sh                   |    2 +-
 12 files changed, 28 insertions(+), 28 deletions(-)
t/t1001-read-tree-m-2way.sh +1 -1
index 0c562bb..93ca84f 100755
@@ -359,7 +359,7 @@ test_expect_success \
 
 test_expect_success \
     'a/b (untracked) vs a, plus c/d case test.' \
-    '! git read-tree -u -m "$treeH" "$treeM" &&
+    'test_must_fail git read-tree -u -m "$treeH" "$treeM" &&
      git ls-files --stage &&
      test -f a/b'
 
t/t3301-notes.sh +3 -3
index 2d67a40..421c988 100755
@@ -299,7 +299,7 @@ cat expect-F >> expect-rm-F
 test_expect_success 'verify note removal with -F /dev/null' '
 	git log -4 > output &&
 	test_cmp expect-rm-F output &&
-	! git notes show
+	test_must_fail git notes show
 '
 
 test_expect_success 'do not create empty note with -m "" (setup)' '
@@ -309,7 +309,7 @@ test_expect_success 'do not create empty note with -m "" (setup)' '
 test_expect_success 'verify non-creation of note with -m ""' '
 	git log -4 > output &&
 	test_cmp expect-rm-F output &&
-	! git notes show
+	test_must_fail git notes show
 '
 
 cat > expect-combine_m_and_F << EOF
@@ -357,7 +357,7 @@ cat expect-multiline >> expect-rm-remove
 test_expect_success 'verify note removal with "git notes remove"' '
 	git log -4 > output &&
 	test_cmp expect-rm-remove output &&
-	! git notes show HEAD^
+	test_must_fail git notes show HEAD^
 '
 
 cat > expect << EOF
t/t3306-notes-prune.sh +4 -4
index b455404..c428217 100755
@@ -67,7 +67,7 @@ test_expect_success 'remove some commits' '
 
 test_expect_success 'verify that commits are gone' '
 
-	! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 	git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
@@ -106,7 +106,7 @@ test_expect_success 'prune notes' '
 
 test_expect_success 'verify that notes are gone' '
 
-	! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 	git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
@@ -130,8 +130,8 @@ test_expect_success 'prune -v notes' '
 
 test_expect_success 'verify that notes are gone' '
 
-	! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
-	! git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+	test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
 
t/t3410-rebase-preserve-dropped-merges.sh +4 -4
index c49143a..6f73b95 100755
@@ -43,11 +43,11 @@ test_expect_success 'setup' '
 # G2 = same changes as G
 test_expect_success 'skip same-resolution merges with -p' '
 	git checkout H &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit L file1 23 &&
 	git checkout I &&
 	test_commit G2 file1 3 &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit J file1 23 &&
 	test_commit K file7 file7 &&
 	git rebase -i -p L &&
@@ -65,11 +65,11 @@ test_expect_success 'skip same-resolution merges with -p' '
 # G2 = different changes as G
 test_expect_success 'keep different-resolution merges with -p' '
 	git checkout H &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit L2 file1 23 &&
 	git checkout I &&
 	test_commit G3 file1 4 &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit J2 file1 24 &&
 	test_commit K2 file7 file7 &&
 	test_must_fail git rebase -i -p L2 &&
t/t6037-merge-ours-theirs.sh +1 -1
index 8ab3d61..2cf42c7 100755
@@ -58,7 +58,7 @@ test_expect_success 'pull with -X' '
 	git reset --hard master && git pull -s recursive -X ours . side &&
 	git reset --hard master && git pull -s recursive -Xtheirs . side &&
 	git reset --hard master && git pull -s recursive -X theirs . side &&
-	git reset --hard master && ! git pull -s recursive -X bork . side
+	git reset --hard master && test_must_fail git pull -s recursive -X bork . side
 '
 
 test_done
t/t7509-commit.sh +2 -2
index 3ea33db..643ab03 100755
@@ -111,7 +111,7 @@ test_expect_success '--amend option with empty author' '
 	test_when_finished "git checkout Initial" &&
 	echo "Empty author test" >>foo &&
 	test_tick &&
-	! git commit -a -m "empty author" --amend 2>err &&
+	test_must_fail git commit -a -m "empty author" --amend 2>err &&
 	grep "empty ident" err
 '
 
@@ -125,7 +125,7 @@ test_expect_success '--amend option with missing author' '
 	test_when_finished "git checkout Initial" &&
 	echo "Missing author test" >>foo &&
 	test_tick &&
-	! git commit -a -m "malformed author" --amend 2>err &&
+	test_must_fail git commit -a -m "malformed author" --amend 2>err &&
 	grep "empty ident" err
 '
 
t/t7607-merge-overwrite.sh +6 -6
index 49f4e15..d82349a 100755
@@ -31,7 +31,7 @@ test_expect_success 'setup' '
 test_expect_success 'will not overwrite untracked file' '
 	git reset --hard c1 &&
 	cat important > c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	test_cmp important c2.c
 '
 
@@ -39,7 +39,7 @@ test_expect_success 'will not overwrite new file' '
 	git reset --hard c1 &&
 	cat important > c2.c &&
 	git add c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	test_cmp important c2.c
 '
 
@@ -48,7 +48,7 @@ test_expect_success 'will not overwrite staged changes' '
 	cat important > c2.c &&
 	git add c2.c &&
 	rm c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	git checkout c2.c &&
 	test_cmp important c2.c
 '
@@ -58,7 +58,7 @@ test_expect_success 'will not overwrite removed file' '
 	git rm c1.c &&
 	git commit -m "rm c1.c" &&
 	cat important > c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	test_cmp important c1.c
 '
 
@@ -68,7 +68,7 @@ test_expect_success 'will not overwrite re-added file' '
 	git commit -m "rm c1.c" &&
 	cat important > c1.c &&
 	git add c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	test_cmp important c1.c
 '
 
@@ -79,7 +79,7 @@ test_expect_success 'will not overwrite removed file with staged changes' '
 	cat important > c1.c &&
 	git add c1.c &&
 	rm c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	git checkout c1.c &&
 	test_cmp important c1.c
 '
t/t7810-grep.sh +2 -2
index 8a63227..b20edff 100755
@@ -65,7 +65,7 @@ do
 
 	test_expect_success "grep -w $L (w)" '
 		: >expected &&
-		! git grep -n -w -e "^w" >actual &&
+		test_must_fail git grep -n -w -e "^w" >actual &&
 		test_cmp expected actual
 	'
 
@@ -134,7 +134,7 @@ do
 	'
 
 	test_expect_success "grep -c $L (no /dev/null)" '
-		! git grep -c test $H | grep /dev/null
+		test_must_fail git grep -c test $H | grep /dev/null
         '
 
 	test_expect_success "grep --max-depth -1 $L" '
t/t9100-git-svn-basic.sh +1 -1
index 13766ab..9e86e9f 100755
@@ -245,7 +245,7 @@ test_expect_success 'dcommit $rev does not clobber current branch' '
 	test $old_head = $(git rev-parse HEAD) &&
 	test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
 	git log refs/remotes/bar | grep "change 1" &&
-	! git log refs/remotes/bar | grep "change 2" &&
+	test_must_fail git log refs/remotes/bar | grep "change 2" &&
 	git checkout master &&
 	git branch -D my-bar
 	'
t/t9130-git-svn-authors-file.sh +2 -2
index 134411e..3c4f319 100755
@@ -20,7 +20,7 @@ test_expect_success 'setup svnrepo' '
 	'
 
 test_expect_success 'start import with incomplete authors file' '
-	! git svn clone --authors-file=svn-authors "$svnrepo" x
+	test_must_fail git svn clone --authors-file=svn-authors "$svnrepo" x
 	'
 
 test_expect_success 'imported 2 revisions successfully' '
@@ -63,7 +63,7 @@ test_expect_success 'authors-file against globs' '
 	'
 
 test_expect_success 'fetch fails on ee' '
-	( cd aa-work && ! git svn fetch --authors-file=../svn-authors )
+	( cd aa-work && test_must_fail git svn fetch --authors-file=../svn-authors )
 	'
 
 tmp_config_get () {
t/t9139-git-svn-non-utf8-commitencoding.sh +1 -1
index f337959..22d80b0 100755
@@ -39,7 +39,7 @@ do
 	(
 		cd $H &&
 		git config --unset i18n.commitencoding &&
-		! git svn dcommit
+		test_must_fail git svn dcommit
 	)
 	'
 done
t/t9140-git-svn-reset.sh +1 -1
index 0735526..e855904 100755
@@ -41,7 +41,7 @@ test_expect_success 'modify hidden file in SVN repo' '
 test_expect_success 'fetch fails on modified hidden file' '
 	( cd g &&
 	  git svn find-rev refs/remotes/git-svn > ../expect &&
-	  ! git svn fetch 2> ../errors &&
+	  test_must_fail git svn fetch 2> ../errors &&
 	  git svn find-rev refs/remotes/git-svn > ../expect2 ) &&
 	fgrep "not found in commit" errors &&
 	test_cmp expect expect2
Signature · 1 line
1.7.1.1
#9 lore raw

Re: [PATCH] Convert "! git" to "test_must_fail" git.

Are you sure these are working properly? If I recall correctly, test_must_fail does not act the same as '!' when a '|' is involved. I believe the '!' negates the result of the entire statement, but test_must_fail only operates on the arguments preceding the '|'.

The rest looks good, and I'm surprised there were so many.

Quoted 27 lines · Jared Hance
t/t7810-grep.sh +1 -1
index 8a63227..b20edff 100755
@@ -134,7 +134,7 @@ do
 	'
 
 	test_expect_success "grep -c $L (no /dev/null)" '
-		! git grep -c test $H | grep /dev/null
+		test_must_fail git grep -c test $H | grep /dev/null
         '
 
 	test_expect_success "grep --max-depth -1 $L" '
t/t9100-git-svn-basic.sh +1 -1
index 13766ab..9e86e9f 100755
@@ -245,7 +245,7 @@ test_expect_success 'dcommit $rev does not clobber current branch' '
 	test $old_head = $(git rev-parse HEAD) &&
 	test refs/heads/my-bar = $(git symbolic-ref HEAD) &&
 	git log refs/remotes/bar | grep "change 1" &&
-	! git log refs/remotes/bar | grep "change 2" &&
+	test_must_fail git log refs/remotes/bar | grep "change 2" &&
 	git checkout master &&
 	git branch -D my-bar
 	'
#10 lore raw

Re: [PATCH] Convert "! git" to "test_must_fail" git.

Quoted 3 lines · Brandon Casey

I believe the '!' negates the
result of the entire statement, but test_must_fail only operates on the arguments preceding the '|'.

Right. For example:

Quoted 1 line · Jared Hance

[...]

Quoted 7 lines

t/t7810-grep.sh do · line 137

Quoted 7 lines

+++ b/t/t7810-grep.sh

t/t7810-grep.sh +1 -1
@@ -134,7 +134,7 @@ do
 	'
 
 	test_expect_success "grep -c $L (no /dev/null)" '
-		! git grep -c test $H | grep /dev/null
+		test_must_fail git grep -c test $H | grep /dev/null

should be

git grep -c test $H | ! grep /dev/null

or if it is considered important to test the exit code of git grep,

	git grep -c test $H >actual &&
	! grep /dev/null actual

Regards,
Jonathan

#11 lore raw

Re: [PATCH] Convert "! git" to "test_must_fail" git.

Quoted 15 lines · Jonathan Nieder
Quoted 3 lines · Brandon Casey

I believe the '!' negates the
result of the entire statement, but test_must_fail only operates on the arguments preceding the '|'.

Right. For example:

Quoted 1 line · Jared Hance

[...]

Quoted 4 lines
Quoted 4 lines

+++ b/t/t7810-grep.sh

(quoted diff) +0 -0
@@ -134,7 +134,7 @@ do
 	'
 
Quoted 7 lines
Quoted 3 lines

t/t7810-grep.sh do · line 137

Quoted 3 lines
t/t7810-grep.sh +1 -1
 	test_expect_success "grep -c $L (no /dev/null)" '
-		! git grep -c test $H | grep /dev/null
+		test_must_fail git grep -c test $H | grep /dev/null

should be

git grep -c test $H | ! grep /dev/null

I seem to recall that that doesn't work either.

   $ /bin/bash -c 'echo foo | ! grep bar && echo success || echo failure'
   /bin/bash: -c: line 0: syntax error near unexpected token `!'
   /bin/bash: -c: line 0: `echo foo | ! grep bar && echo success || echo failure'

-brandon

#12 lore raw

PATCH v2 1/1 Convert "! git" to "test_must_fail git"

In reply to Brandon Casey

test_must_fail will account for segfaults in git, so it should be used instead of "! git"

This patch does not change any of the commands that use pipes.

---
 t/t1001-read-tree-m-2way.sh                |    2 +-
 t/t3301-notes.sh                           |    6 +++---
 t/t3306-notes-prune.sh                     |    8 ++++----
 t/t3410-rebase-preserve-dropped-merges.sh  |    8 ++++----
 t/t6037-merge-ours-theirs.sh               |    2 +-
 t/t7509-commit.sh                          |    4 ++--
 t/t7607-merge-overwrite.sh                 |   12 ++++++------
 t/t7810-grep.sh                            |    2 +-
 t/t9130-git-svn-authors-file.sh            |    4 ++--
 t/t9139-git-svn-non-utf8-commitencoding.sh |    2 +-
 t/t9140-git-svn-reset.sh                   |    2 +-
 11 files changed, 26 insertions(+), 26 deletions(-)
t/t1001-read-tree-m-2way.sh +1 -1
index 0c562bb..93ca84f 100755
@@ -359,7 +359,7 @@ test_expect_success \
 
 test_expect_success \
     'a/b (untracked) vs a, plus c/d case test.' \
-    '! git read-tree -u -m "$treeH" "$treeM" &&
+    'test_must_fail git read-tree -u -m "$treeH" "$treeM" &&
      git ls-files --stage &&
      test -f a/b'
 
t/t3301-notes.sh +3 -3
index 2d67a40..421c988 100755
@@ -299,7 +299,7 @@ cat expect-F >> expect-rm-F
 test_expect_success 'verify note removal with -F /dev/null' '
 	git log -4 > output &&
 	test_cmp expect-rm-F output &&
-	! git notes show
+	test_must_fail git notes show
 '
 
 test_expect_success 'do not create empty note with -m "" (setup)' '
@@ -309,7 +309,7 @@ test_expect_success 'do not create empty note with -m "" (setup)' '
 test_expect_success 'verify non-creation of note with -m ""' '
 	git log -4 > output &&
 	test_cmp expect-rm-F output &&
-	! git notes show
+	test_must_fail git notes show
 '
 
 cat > expect-combine_m_and_F << EOF
@@ -357,7 +357,7 @@ cat expect-multiline >> expect-rm-remove
 test_expect_success 'verify note removal with "git notes remove"' '
 	git log -4 > output &&
 	test_cmp expect-rm-remove output &&
-	! git notes show HEAD^
+	test_must_fail git notes show HEAD^
 '
 
 cat > expect << EOF
t/t3306-notes-prune.sh +4 -4
index b455404..c428217 100755
@@ -67,7 +67,7 @@ test_expect_success 'remove some commits' '
 
 test_expect_success 'verify that commits are gone' '
 
-	! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 	git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
@@ -106,7 +106,7 @@ test_expect_success 'prune notes' '
 
 test_expect_success 'verify that notes are gone' '
 
-	! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 	git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
@@ -130,8 +130,8 @@ test_expect_success 'prune -v notes' '
 
 test_expect_success 'verify that notes are gone' '
 
-	! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
-	! git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+	test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+	test_must_fail git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 	git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 '
 
t/t3410-rebase-preserve-dropped-merges.sh +4 -4
index c49143a..6f73b95 100755
@@ -43,11 +43,11 @@ test_expect_success 'setup' '
 # G2 = same changes as G
 test_expect_success 'skip same-resolution merges with -p' '
 	git checkout H &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit L file1 23 &&
 	git checkout I &&
 	test_commit G2 file1 3 &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit J file1 23 &&
 	test_commit K file7 file7 &&
 	git rebase -i -p L &&
@@ -65,11 +65,11 @@ test_expect_success 'skip same-resolution merges with -p' '
 # G2 = different changes as G
 test_expect_success 'keep different-resolution merges with -p' '
 	git checkout H &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit L2 file1 23 &&
 	git checkout I &&
 	test_commit G3 file1 4 &&
-	! git merge E &&
+	test_must_fail git merge E &&
 	test_commit J2 file1 24 &&
 	test_commit K2 file7 file7 &&
 	test_must_fail git rebase -i -p L2 &&
t/t6037-merge-ours-theirs.sh +1 -1
index 8ab3d61..2cf42c7 100755
@@ -58,7 +58,7 @@ test_expect_success 'pull with -X' '
 	git reset --hard master && git pull -s recursive -X ours . side &&
 	git reset --hard master && git pull -s recursive -Xtheirs . side &&
 	git reset --hard master && git pull -s recursive -X theirs . side &&
-	git reset --hard master && ! git pull -s recursive -X bork . side
+	git reset --hard master && test_must_fail git pull -s recursive -X bork . side
 '
 
 test_done
t/t7509-commit.sh +2 -2
index 3ea33db..643ab03 100755
@@ -111,7 +111,7 @@ test_expect_success '--amend option with empty author' '
 	test_when_finished "git checkout Initial" &&
 	echo "Empty author test" >>foo &&
 	test_tick &&
-	! git commit -a -m "empty author" --amend 2>err &&
+	test_must_fail git commit -a -m "empty author" --amend 2>err &&
 	grep "empty ident" err
 '
 
@@ -125,7 +125,7 @@ test_expect_success '--amend option with missing author' '
 	test_when_finished "git checkout Initial" &&
 	echo "Missing author test" >>foo &&
 	test_tick &&
-	! git commit -a -m "malformed author" --amend 2>err &&
+	test_must_fail git commit -a -m "malformed author" --amend 2>err &&
 	grep "empty ident" err
 '
 
t/t7607-merge-overwrite.sh +6 -6
index 49f4e15..d82349a 100755
@@ -31,7 +31,7 @@ test_expect_success 'setup' '
 test_expect_success 'will not overwrite untracked file' '
 	git reset --hard c1 &&
 	cat important > c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	test_cmp important c2.c
 '
 
@@ -39,7 +39,7 @@ test_expect_success 'will not overwrite new file' '
 	git reset --hard c1 &&
 	cat important > c2.c &&
 	git add c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	test_cmp important c2.c
 '
 
@@ -48,7 +48,7 @@ test_expect_success 'will not overwrite staged changes' '
 	cat important > c2.c &&
 	git add c2.c &&
 	rm c2.c &&
-	! git merge c2 &&
+	test_must_fail git merge c2 &&
 	git checkout c2.c &&
 	test_cmp important c2.c
 '
@@ -58,7 +58,7 @@ test_expect_success 'will not overwrite removed file' '
 	git rm c1.c &&
 	git commit -m "rm c1.c" &&
 	cat important > c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	test_cmp important c1.c
 '
 
@@ -68,7 +68,7 @@ test_expect_success 'will not overwrite re-added file' '
 	git commit -m "rm c1.c" &&
 	cat important > c1.c &&
 	git add c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	test_cmp important c1.c
 '
 
@@ -79,7 +79,7 @@ test_expect_success 'will not overwrite removed file with staged changes' '
 	cat important > c1.c &&
 	git add c1.c &&
 	rm c1.c &&
-	! git merge c1a &&
+	test_must_fail git merge c1a &&
 	git checkout c1.c &&
 	test_cmp important c1.c
 '
t/t7810-grep.sh +1 -1
index 8a63227..023f225 100755
@@ -65,7 +65,7 @@ do
 
 	test_expect_success "grep -w $L (w)" '
 		: >expected &&
-		! git grep -n -w -e "^w" >actual &&
+		test_must_fail git grep -n -w -e "^w" >actual &&
 		test_cmp expected actual
 	'
 
t/t9130-git-svn-authors-file.sh +2 -2
index 134411e..3c4f319 100755
@@ -20,7 +20,7 @@ test_expect_success 'setup svnrepo' '
 	'
 
 test_expect_success 'start import with incomplete authors file' '
-	! git svn clone --authors-file=svn-authors "$svnrepo" x
+	test_must_fail git svn clone --authors-file=svn-authors "$svnrepo" x
 	'
 
 test_expect_success 'imported 2 revisions successfully' '
@@ -63,7 +63,7 @@ test_expect_success 'authors-file against globs' '
 	'
 
 test_expect_success 'fetch fails on ee' '
-	( cd aa-work && ! git svn fetch --authors-file=../svn-authors )
+	( cd aa-work && test_must_fail git svn fetch --authors-file=../svn-authors )
 	'
 
 tmp_config_get () {
t/t9139-git-svn-non-utf8-commitencoding.sh +1 -1
index f337959..22d80b0 100755
@@ -39,7 +39,7 @@ do
 	(
 		cd $H &&
 		git config --unset i18n.commitencoding &&
-		! git svn dcommit
+		test_must_fail git svn dcommit
 	)
 	'
 done
t/t9140-git-svn-reset.sh +1 -1
index 0735526..e855904 100755
@@ -41,7 +41,7 @@ test_expect_success 'modify hidden file in SVN repo' '
 test_expect_success 'fetch fails on modified hidden file' '
 	( cd g &&
 	  git svn find-rev refs/remotes/git-svn > ../expect &&
-	  ! git svn fetch 2> ../errors &&
+	  test_must_fail git svn fetch 2> ../errors &&
 	  git svn find-rev refs/remotes/git-svn > ../expect2 ) &&
 	fgrep "not found in commit" errors &&
 	test_cmp expect expect2
Signature · 1 line
1.7.1.1
#13 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

In reply to Ævar Arnfjörð Bjarmason
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 5 lines · Junio C Hamano

   Run a git command and ensure it fails in a controlled way.  Use this instead of "! <git-command>".  When git-command dies due to a segfault, test_must_fail diagnoses it as an error; "! <git-command>" treats it as just another expected failure. letting such a bug go unnoticed.

Quoted 5 lines

To add to that:

Don't use test_must_fail to negate the return values of commands on the system like grep, sed etc. If we can't trust that the core utilities won't randomly segfault we might as well die horribly.

I think you are being incoherent. If we can't trust system "grep" and it randomly segfaults, then a test:

git some-command >actual &&
! grep string-that-should-not-be-in-the-output actual

would _pass_ when the command segfaults. I do agree with you that "We might as well die horribly", and the way you do so is by protecting the test with test_must_fail, like this:

git some-command >actual &&
test_must_fail grep string-that-should-not-be-in-the-output actual

Having said that, as we _do_ trust system tools to a certain degree, we do not care very deeply about this. IOW, I wouldn't want to see a patch that rewrites "! grep" to "test_must_fail grep".

Thanks.

#14 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 26 lines · Junio C Hamano
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 5 lines · Junio C Hamano

   Run a git command and ensure it fails in a controlled way.  Use this instead of "! <git-command>".  When git-command dies due to a segfault, test_must_fail diagnoses it as an error; "! <git-command>" treats it as just another expected failure. letting such a bug go unnoticed.

Quoted 5 lines

To add to that:

    Don't use test_must_fail to negate the return values of commands on the system like grep, sed etc. If we can't trust that the core utilities won't randomly segfault we might as well die horribly.

I think you are being incoherent.  If we can't trust system "grep" and it randomly segfaults, then a test:

   git some-command >actual &&
   ! grep string-that-should-not-be-in-the-output actual

would _pass_ when the command segfaults.  I do agree with you that "We might as well die horribly", and the way you do so is by protecting the test with test_must_fail, like this:

Quoted 6 lines

   git some-command >actual &&
   test_must_fail grep string-that-should-not-be-in-the-output actual

Having said that, as we _do_ trust system tools to a certain degree, we do not care very deeply about this.  IOW, I wouldn't want to see a patch that rewrites "! grep" to "test_must_fail grep".

An individual test would pass, yes. But if test or grep are segfaulting we're going to bail out horribly eventually anyway, so I don't think it's worth the effort to guard them with test_must_fail, and I wouldn't write tests to do that. I'd just use !.

That's what we seem to be doing in the tests so far, i.e. test_must_fail is reserved for git commands only.

#15 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 2 lines · Ævar Arnfjörð Bjarmason

That's what we seem to be doing in the tests so far, i.e. test_must_fail is reserved for git commands only.

test_must_fail relies on conventions for return value that cannot necessarily be relied on from outside utilities.

Thanks for cleaning up my mess.
Jonathan

#16 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 7 lines · Jonathan Nieder
Quoted 2 lines · Ęvar Arnfjörš Bjarmason

That's what we seem to be doing in the tests so far, i.e. test_must_fail is reserved for git commands only.

test_must_fail relies on conventions for return value that cannot necessarily be relied on from outside utilities.

Right, someone should send a patch for these:

    ack 'test_must_fail (?!git)' *sh

:)

#17 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 5 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines · Jonathan Nieder
Quoted 2 lines · Ęvar Arnfjörš Bjarmason

That's what we seem to be doing in the tests so far, i.e. test_must_fail is reserved for git commands only.

Quoted 8 lines
Quoted 2 lines

test_must_fail relies on conventions for return value that cannot necessarily be relied on from outside utilities.

Right, someone should send a patch for these:

    ack 'test_must_fail (?!git)' *sh

:)

You joke, but thanks to your prodding, I discovered these broken tests that should definitely all be fixed:

   $ perl -ne 'm/test_must_fail +[^ ]+=/ && print' *sh
        test_must_fail PAGER= git reflog show delta &&
        test_must_fail PAGER= git reflog show epsilon &&
        test_must_fail PAGER= git reflog show epsilon
        test_must_fail PAGER= git reflog show zeta &&
        test_must_fail PAGER= git reflog show eta &&
        test_must_fail PAGER= git reflog show eta
        test_must_fail PAGER= git reflog show beta
        test_must_fail MSG="yet another note" git notes add -c deadbeef &&

one-shot variable assignment does not work with test_must_fail.

See e2007832552ccea9befed9003580c494f09e666e for an explanation.

-brandon

#18 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

Quoted 9 lines · Brandon Casey
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Jonathan Nieder
Quoted 2 lines · Ęvar Arnfjörš Bjarmason

That's what we seem to be doing in the tests so far, i.e. test_must_fail is reserved for git commands only.

test_must_fail relies on conventions for return value that cannot necessarily be relied on from outside utilities.

Quoted 8 lines
Quoted 5 lines

Right, someone should send a patch for these:

    ack 'test_must_fail (?!git)' *sh

:)

You joke, but thanks to your prodding, I discovered these broken tests that should definitely all be fixed:

Oh I'm completely serious, I'm just too lazy to do these myself today :)

Quoted 11 lines
  $ perl -ne 'm/test_must_fail +[^ ]+=/ && print' *sh

       test_must_fail PAGER= git reflog show delta && test_must_fail PAGER= git reflog show epsilon && test_must_fail PAGER= git reflog show epsilon test_must_fail PAGER= git reflog show zeta && test_must_fail PAGER= git reflog show eta && test_must_fail PAGER= git reflog show eta test_must_fail PAGER= git reflog show beta test_must_fail MSG="yet another note" git notes add -c deadbeef &&

Quoted 3 lines

one-shot variable assignment does not work with test_must_fail.

See e2007832552ccea9befed9003580c494f09e666e for an explanation.

Good catch.

#19 lore raw

PATCH 1/1 t/: work around one-shot variable assignment with test_must_fail

In reply to Brandon Casey

No time to investigate, but here is an example patch and the results of running the affected tests. Looks like reflog may be creating a reflog when it is not supposed to.

Erick, I added you to cc since you appear to be the author of the tests in question.

$ ./t2017-checkout-orphan.sh
<snip>
not ok - 8 --orphan does not make reflog when core.logAllRefUpdates = false
#
#               git checkout master &&
#               git config core.logAllRefUpdates false &&
#               git checkout --orphan epsilon &&
#               ! test -f .git/logs/refs/heads/epsilon &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show epsilon
#               ) &&
#               git commit -m Epsilon &&
#               ! test -f .git/logs/refs/heads/epsilon &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show epsilon
#               )
#
<snip>
$ ./t3200-branch.sh
<snip>
not ok - 32 checkout -b does not make reflog when core.logAllRefUpdates = false
#
#               git checkout master &&
#               git config core.logAllRefUpdates false &&
#               git checkout -b beta &&
#               ! test -f .git/logs/refs/heads/beta &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show beta
#               )
#
<snip>

--->8---
From: Brandon Casey <[email protected]>

See e2007832552ccea9befed9003580c494f09e666e

---
 t/t2017-checkout-orphan.sh |   36 ++++++++++++++++++++++++++++++------
 t/t3200-branch.sh          |    6 +++++-
 t/t3301-notes.sh           |    6 +++++-
 3 files changed, 40 insertions(+), 8 deletions(-)
t/t2017-checkout-orphan.sh +30 -6
index be88d4b..81cb393 100755
@@ -69,7 +69,11 @@ test_expect_success '--orphan makes reflog by default' '
 	git config --unset core.logAllRefUpdates &&
 	git checkout --orphan delta &&
 	! test -f .git/logs/refs/heads/delta &&
-	test_must_fail PAGER= git reflog show delta &&
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show delta
+	) &&
 	git commit -m Delta &&
 	test -f .git/logs/refs/heads/delta &&
 	PAGER= git reflog show delta
@@ -80,17 +84,29 @@ test_expect_success '--orphan does not make reflog when core.logAllRefUpdates =
 	git config core.logAllRefUpdates false &&
 	git checkout --orphan epsilon &&
 	! test -f .git/logs/refs/heads/epsilon &&
-	test_must_fail PAGER= git reflog show epsilon &&
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show epsilon
+	) &&
 	git commit -m Epsilon &&
 	! test -f .git/logs/refs/heads/epsilon &&
-	test_must_fail PAGER= git reflog show epsilon
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show epsilon
+	)
 '
 
 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git checkout -l --orphan zeta &&
 	test -f .git/logs/refs/heads/zeta &&
-	test_must_fail PAGER= git reflog show zeta &&
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show zeta
+	) &&
 	git commit -m Zeta &&
 	PAGER= git reflog show zeta
 '
@@ -99,10 +115,18 @@ test_expect_success 'giving up --orphan not committed when -l and core.logAllRef
 	git checkout master &&
 	git checkout -l --orphan eta &&
 	test -f .git/logs/refs/heads/eta &&
-	test_must_fail PAGER= git reflog show eta &&
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show eta
+	) &&
 	git checkout master &&
 	! test -f .git/logs/refs/heads/eta &&
-	test_must_fail PAGER= git reflog show eta
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show eta
+	)
 '
 
 test_expect_success '--orphan is rejected with an existing name' '
t/t3200-branch.sh +5 -1
index 859b99a..bf7747d 100755
@@ -237,7 +237,11 @@ test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates
 	git config core.logAllRefUpdates false &&
 	git checkout -b beta &&
 	! test -f .git/logs/refs/heads/beta &&
-	test_must_fail PAGER= git reflog show beta
+	(
+		PAGER= &&
+		export PAGER &&
+		test_must_fail git reflog show beta
+	)
 '
 
 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
t/t3301-notes.sh +5 -1
index 2d67a40..1d82f79 100755
@@ -693,7 +693,11 @@ test_expect_success 'create note from non-existing note with "git notes add -c"
 	git add a10 &&
 	test_tick &&
 	git commit -m 10th &&
-	test_must_fail MSG="yet another note" git notes add -c deadbeef &&
+	(
+		MSG="yet another note" &&
+		export MSG &&
+		test_must_fail git notes add -c deadbeef
+	) &&
 	test_must_fail git notes list HEAD
 '
 
Signature · 1 line
1.6.6.2
#20 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Quoted 3 lines · Brandon Casey

No time to investigate, but here is an example patch and the results of running the affected tests. Looks like reflog may be creating a reflog when it is not supposed to.

Your later analysis is correct; "git reflog show <branch>" does not complain when there is no reflog for <branch>, which might or might not be a bug.

Because these tests are not about behaviour of "git reflog show" command, let's do this for now.

Thanks.

-- >8 --
Subject: tests: correct "does reflog exist" tests

These two tests were not about how "git reflog show <branch>" exits when there is no reflog, but were about whether "checkout" and "branch" create or not create reflog when creating a new <branch>, update the tests to check it in a more direct way, namely using "git rev-parse --verify".

Also lose tests based on "test -f .git/logs/refs/heads/<branch>" from nearby, to avoid exposing this particular implementation detail unnecessarily.

---
 t/t2017-checkout-orphan.sh |   47 +++++++------------------------------------
 t/t3200-branch.sh          |   13 ++---------
 2 files changed, 11 insertions(+), 49 deletions(-)
t/t2017-checkout-orphan.sh +8 -39
index 81cb393..2d2f63f 100755
@@ -68,65 +68,34 @@ test_expect_success '--orphan makes reflog by default' '
 	git checkout master &&
 	git config --unset core.logAllRefUpdates &&
 	git checkout --orphan delta &&
-	! test -f .git/logs/refs/heads/delta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show delta
-	) &&
+	test_must_fail git rev-parse --verify delta@{0} &&
 	git commit -m Delta &&
-	test -f .git/logs/refs/heads/delta &&
-	PAGER= git reflog show delta
+	git rev-parse --verify delta@{0}
 '
 
 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git config core.logAllRefUpdates false &&
 	git checkout --orphan epsilon &&
-	! test -f .git/logs/refs/heads/epsilon &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show epsilon
-	) &&
+	test_must_fail git rev-parse --verify epsilon@{0} &&
 	git commit -m Epsilon &&
-	! test -f .git/logs/refs/heads/epsilon &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show epsilon
-	)
+	test_must_fail git rev-parse --verify epsilon@{0}
 '
 
 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git checkout -l --orphan zeta &&
-	test -f .git/logs/refs/heads/zeta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show zeta
-	) &&
+	test_must_fail git rev-parse --verify zeta@{0} &&
 	git commit -m Zeta &&
-	PAGER= git reflog show zeta
+	git rev-parse --verify zeta@{0}
 '
 
 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
 	git checkout master &&
 	git checkout -l --orphan eta &&
-	test -f .git/logs/refs/heads/eta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show eta
-	) &&
+	test_must_fail git rev-parse --verify eta@{0} &&
 	git checkout master &&
-	! test -f .git/logs/refs/heads/eta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show eta
-	)
+	test_must_fail git rev-parse --verify eta@{0}
 '
 
 test_expect_success '--orphan is rejected with an existing name' '
t/t3200-branch.sh +3 -10
index bf7747d..f54a533 100755
@@ -228,28 +228,21 @@ test_expect_success 'checkout -b makes reflog by default' '
 	git checkout master &&
 	git config --unset core.logAllRefUpdates &&
 	git checkout -b alpha &&
-	test -f .git/logs/refs/heads/alpha &&
-	PAGER= git reflog show alpha
+	git rev-parse --verify alpha@{0}
 '
 
 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git config core.logAllRefUpdates false &&
 	git checkout -b beta &&
-	! test -f .git/logs/refs/heads/beta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show beta
-	)
+	test_must_fail git rev-parse --verify beta@{0}
 '
 
 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git checkout -lb gamma &&
 	git config --unset core.logAllRefUpdates &&
-	test -f .git/logs/refs/heads/gamma &&
-	PAGER= git reflog show gamma
+	git rev-parse --verify gamma@{0}
 '
 
 test_expect_success 'avoid ambiguous track' '
#21 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Hi,

2010/7/21 Junio C Hamano <[email protected]>:

Quoted 9 lines
Quoted 3 lines · Brandon Casey

No time to investigate, but here is an example patch and the results of running the affected tests.  Looks like reflog may be creating a reflog when it is not supposed to.

Your later analysis is correct; "git reflog show <branch>" does not complain when there is no reflog for <branch>, which might or might not be a bug.

I think is not a bug but almost one.

Quoted 8 lines

Because these tests are not about behaviour of "git reflog show" command, let's do this for now.

Thanks.

-- >8 --
Subject: tests: correct "does reflog exist" tests

Quoted 8 lines

These two tests were not about how "git reflog show <branch>" exits when there is no reflog, but were about whether "checkout" and "branch" create or not create reflog when creating a new <branch>, update the tests to check it in a more direct way, namely using "git rev-parse --verify".

Also lose tests based on "test -f .git/logs/refs/heads/<branch>" from nearby, to avoid exposing this particular implementation detail unnecessarily.

Quite pretty. Clean and optimized solution. Better this way.

Regards

#22 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

In reply to Junio C Hamano

btw, this works and is a definite improvement.

-Brandon

Quoted 146 lines · Junio C Hamano
Quoted 3 lines · Brandon Casey

No time to investigate, but here is an example patch and the results of running the affected tests. Looks like reflog may be creating a reflog when it is not supposed to.

Your later analysis is correct; "git reflog show <branch>" does not complain when there is no reflog for <branch>, which might or might not be a bug.

Because these tests are not about behaviour of "git reflog show" command, let's do this for now.

Thanks.

-- >8 --
Subject: tests: correct "does reflog exist" tests

These two tests were not about how "git reflog show <branch>" exits when there is no reflog, but were about whether "checkout" and "branch" create or not create reflog when creating a new <branch>, update the tests to check it in a more direct way, namely using "git rev-parse --verify".

Also lose tests based on "test -f .git/logs/refs/heads/<branch>" from nearby, to avoid exposing this particular implementation detail unnecessarily.

---
 t/t2017-checkout-orphan.sh |   47 +++++++------------------------------------
 t/t3200-branch.sh          |   13 ++---------
 2 files changed, 11 insertions(+), 49 deletions(-)
t/t2017-checkout-orphan.sh +8 -39
index 81cb393..2d2f63f 100755
@@ -68,65 +68,34 @@ test_expect_success '--orphan makes reflog by default' '
 	git checkout master &&
 	git config --unset core.logAllRefUpdates &&
 	git checkout --orphan delta &&
-	! test -f .git/logs/refs/heads/delta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show delta
-	) &&
+	test_must_fail git rev-parse --verify delta@{0} &&
 	git commit -m Delta &&
-	test -f .git/logs/refs/heads/delta &&
-	PAGER= git reflog show delta
+	git rev-parse --verify delta@{0}
 '
 
 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git config core.logAllRefUpdates false &&
 	git checkout --orphan epsilon &&
-	! test -f .git/logs/refs/heads/epsilon &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show epsilon
-	) &&
+	test_must_fail git rev-parse --verify epsilon@{0} &&
 	git commit -m Epsilon &&
-	! test -f .git/logs/refs/heads/epsilon &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show epsilon
-	)
+	test_must_fail git rev-parse --verify epsilon@{0}
 '
 
 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git checkout -l --orphan zeta &&
-	test -f .git/logs/refs/heads/zeta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show zeta
-	) &&
+	test_must_fail git rev-parse --verify zeta@{0} &&
 	git commit -m Zeta &&
-	PAGER= git reflog show zeta
+	git rev-parse --verify zeta@{0}
 '
 
 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
 	git checkout master &&
 	git checkout -l --orphan eta &&
-	test -f .git/logs/refs/heads/eta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show eta
-	) &&
+	test_must_fail git rev-parse --verify eta@{0} &&
 	git checkout master &&
-	! test -f .git/logs/refs/heads/eta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show eta
-	)
+	test_must_fail git rev-parse --verify eta@{0}
 '
 
 test_expect_success '--orphan is rejected with an existing name' '
t/t3200-branch.sh +3 -10
index bf7747d..f54a533 100755
@@ -228,28 +228,21 @@ test_expect_success 'checkout -b makes reflog by default' '
 	git checkout master &&
 	git config --unset core.logAllRefUpdates &&
 	git checkout -b alpha &&
-	test -f .git/logs/refs/heads/alpha &&
-	PAGER= git reflog show alpha
+	git rev-parse --verify alpha@{0}
 '
 
 test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git config core.logAllRefUpdates false &&
 	git checkout -b beta &&
-	! test -f .git/logs/refs/heads/beta &&
-	(
-		PAGER= &&
-		export PAGER &&
-		test_must_fail git reflog show beta
-	)
+	test_must_fail git rev-parse --verify beta@{0}
 '
 
 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 	git checkout master &&
 	git checkout -lb gamma &&
 	git config --unset core.logAllRefUpdates &&
-	test -f .git/logs/refs/heads/gamma &&
-	PAGER= git reflog show gamma
+	git rev-parse --verify gamma@{0}
 '
 
 test_expect_success 'avoid ambiguous track' '
#23 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

In reply to Brandon Casey

Hi,

2010/7/20 Brandon Casey <[email protected]>

Quoted 7 lines

No time to investigate, but here is an example patch and the results of running the affected tests.  Looks like reflog may be creating a reflog when it is not supposed to.

Erick, I added you to cc since you appear to be the author of the tests in question.

Thanks for your kindness.

Quoted 23 lines
$ ./t2017-checkout-orphan.sh
<snip>
not ok - 8 --orphan does not make reflog when core.logAllRefUpdates = false
#
#               git checkout master &&
#               git config core.logAllRefUpdates false &&
#               git checkout --orphan epsilon &&
#               ! test -f .git/logs/refs/heads/epsilon &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show epsilon
#               ) &&
#               git commit -m Epsilon &&
#               ! test -f .git/logs/refs/heads/epsilon &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show epsilon
#               )
#
<snip>
Quoted 15 lines
$ ./t3200-branch.sh
<snip>
not ok - 32 checkout -b does not make reflog when core.logAllRefUpdates = false
#
#               git checkout master &&
#               git config core.logAllRefUpdates false &&
#               git checkout -b beta &&
#               ! test -f .git/logs/refs/heads/beta &&
#               (
#                       PAGER= &&
#                       export PAGER &&
#                       test_must_fail git reflog show beta
#               )
#
<snip>

You have made cosmetic changes which do not do the same as the original.

Quoted 116 lines

--->8---
From: Brandon Casey <[email protected]>

See e2007832552ccea9befed9003580c494f09e666e
---
 t/t2017-checkout-orphan.sh |   36 ++++++++++++++++++++++++++++++------ t/t3200-branch.sh          |    6 +++++-
 t/t3301-notes.sh           |    6 +++++-

 3 files changed, 40 insertions(+), 8 deletions(-)
t/t2017-checkout-orphan.sh +0 -0
index be88d4b..81cb393 100755
@@ -69,7 +69,11 @@ test_expect_success '--orphan makes reflog by default' '

       git config --unset core.logAllRefUpdates && git checkout --orphan delta &&
       ! test -f .git/logs/refs/heads/delta &&
-       test_must_fail PAGER= git reflog show delta &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show delta
+       ) &&
       git commit -m Delta &&
       test -f .git/logs/refs/heads/delta && PAGER= git reflog show delta

t/t2017-checkout-orphan.sh +0 -0
@@ -80,17 +84,29 @@ test_expect_success '--orphan does not make reflog when core.logAllRefUpdates =

       git config core.logAllRefUpdates false && git checkout --orphan epsilon &&
       ! test -f .git/logs/refs/heads/epsilon &&
-       test_must_fail PAGER= git reflog show epsilon &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show epsilon
+       ) &&
       git commit -m Epsilon &&
       ! test -f .git/logs/refs/heads/epsilon &&
-       test_must_fail PAGER= git reflog show epsilon
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show epsilon
+       )
 '

 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' ' git checkout master &&
       git checkout -l --orphan zeta &&
       test -f .git/logs/refs/heads/zeta &&
-       test_must_fail PAGER= git reflog show zeta &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show zeta
+       ) &&
       git commit -m Zeta &&
       PAGER= git reflog show zeta
 '

t/t2017-checkout-orphan.sh +0 -0
@@ -99,10 +115,18 @@ test_expect_success 'giving up --orphan not committed when -l and core.logAllRef

       git checkout master &&
       git checkout -l --orphan eta &&
       test -f .git/logs/refs/heads/eta &&
-       test_must_fail PAGER= git reflog show eta &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show eta
+       ) &&
       git checkout master &&
       ! test -f .git/logs/refs/heads/eta &&
-       test_must_fail PAGER= git reflog show eta
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show eta
+       )
 '

 test_expect_success '--orphan is rejected with an existing name' '

t/t3200-branch.sh +0 -0
index 859b99a..bf7747d 100755
@@ -237,7 +237,11 @@ test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates

       git config core.logAllRefUpdates false && git checkout -b beta &&
       ! test -f .git/logs/refs/heads/beta &&
-       test_must_fail PAGER= git reflog show beta
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show beta
+       )
 '

 test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '

t/t3301-notes.sh +0 -0
index 2d67a40..1d82f79 100755
@@ -693,7 +693,11 @@ test_expect_success 'create note from non-existing note with "git notes add -c"

       git add a10 &&
       test_tick &&
       git commit -m 10th &&
-       test_must_fail MSG="yet another note" git notes add -c deadbeef &&
+       (
+               MSG="yet another note" &&
+               export MSG &&
+               test_must_fail git notes add -c deadbeef
+       ) &&
       test_must_fail git notes list HEAD
 '

Quoted 3 lines

--
1.6.6.2

I don't like this proposed patch because I don't see an improvement when:
* you change a line to three;
* the original line is clear enough;
* the resulting lines improves nothing;
* it is for cosmetic purposes only inside a script;
* and it uses more resources, even if little more as by creating a subshell environment, to do the same.

Best regards

A message that is not in the archive (sent off-list or not yet received): 20100721000823.GD4282@burratino

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20100721141140.GA12123@burratino

A message that is not in the archive (sent off-list or not yet received): [email protected]

#28 lore raw

PATCH 1/1 gitweb: clarify search results page when no matching commit found

Quoted 5 lines · Erick Mattos

I did a search in gitweb
(http://git.kernel.org/?p=git/git.git;a=summary) by commit e2007832552ccea9befed9003580c494f09e666e.

Looks as gitweb's search is broken and giving false results.

Maybe something like the following would help.

-- 8< --
When searching commits for a string that never occurs, the results page looks something like this:

projects / foo.git / search \o/
summary | ... | tree [commit] search: [ kfjdkas ] [ ]re
first ⋅ prev ⋅ next

Merge branch 'maint'

Foo: a demonstration project

Without a list of hits to compare it to, the header describing the commit named by the hash parameter (usually HEAD) may itself look like a hit. Add some text (“No match.”) to replace the empty list of hits to avoid this confusion.

---

gitweb/gitweb.perl +5 -4
index cedc357..a47eed2 100755
@@ -6522,12 +6522,13 @@ sub git_search {
 			$paging_nav .= " &sdot; next";
 		}
 
-		if ($#commitlist >= 100) {
-		}
-
 		git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
 		git_print_header_div('commit', esc_html($co{'title'}), $hash);
-		git_search_grep_body(\@commitlist, 0, 99, $next_link);
+		if ($page == 0 && $#commitlist == 0) {
+			print 'No match.\n';
+		} else {
+			git_search_grep_body(\@commitlist, 0, 99, $next_link);
+		}
 	}
 
 	if ($searchtype eq 'pickaxe') {
Acked-by on v1 1/1
#29 lore raw

Re: [PATCH] gitweb: clarify search results page when no matching commit found

Quoted 22 lines · Jonathan Nieder
Quoted 5 lines · Erick Mattos

I did a search in gitweb
(http://git.kernel.org/?p=git/git.git;a=summary) by commit e2007832552ccea9befed9003580c494f09e666e.

Looks as gitweb's search is broken and giving false results.

Maybe something like the following would help.

-- 8< --
When searching commits for a string that never occurs, the results page looks something like this:

projects / foo.git / search \o/
summary | ... | tree [commit] search: [ kfjdkas ] [ ]re
first ⋅ prev ⋅ next

Merge branch 'maint'

Foo: a demonstration project

Quoted 7 lines

Without a list of hits to compare it to, the header describing the commit named by the hash parameter (usually HEAD) may itself look like a hit. Add some text (“No match.”) to replace the empty list of hits to avoid this confusion.

Very good idea

gitweb/gitweb.perl sub git_search { · line 6527

Quoted 13 lines

---

gitweb/gitweb.perl +0 -3
index cedc357..a47eed2 100755
@@ -6522,12 +6522,13 @@ sub git_search {
 			$paging_nav .= " &sdot; next";
 		}
 
-		if ($#commitlist >= 100) {
-		}
-

P.S. I wonder WTF was that...

Signature · 2 lines
Jakub Narebski
Poland
#30 lore raw

PATCH v2 1/1 gitweb: clarify search results page when no matching commit found

When searching commits for a string that never occurs, the results page looks something like this:

projects / foo.git / search \o/
summary | ... | tree [commit] search: [ kfjdkas ] [ ]re
first ⋅ prev ⋅ next

Merge branch 'maint'

Foo: a demonstration project

Without a list of hits to compare it to, the header describing the commit named by the hash parameter (usually HEAD) may itself look like a hit. Add some text (“No match.”) to replace the empty list of hits to avoid this confusion.

While at it, remove some nearby dead code, left behind from a simplification a few years ago (v1.5.4-rc0~276^2~4, 2007-11-01).

---

Quoted 1 line · Jakub Narebski

Very good idea

Shoddy implementation, though. Apparently (yes, I should know this; and testing reminded me before I sent the wrong patch) the index of the last element ($#array) of an empty array is -1, not 0.

Sorry about that.

 gitweb/gitweb.perl |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +5 -4
index cedc357..801575d 100755
@@ -6522,12 +6522,13 @@ sub git_search {
 			$paging_nav .= " &sdot; next";
 		}
 
-		if ($#commitlist >= 100) {
-		}
-
 		git_print_page_nav('','', $hash,$co{'tree'},$hash, $paging_nav);
 		git_print_header_div('commit', esc_html($co{'title'}), $hash);
-		git_search_grep_body(\@commitlist, 0, 99, $next_link);
+		if ($page == 0 && !@commitlist) {
+			print "<p>No match.\n</p>";
+		} else {
+			git_search_grep_body(\@commitlist, 0, 99, $next_link);
+		}
 	}
 
 	if ($searchtype eq 'pickaxe') {
#31 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

In reply to Erick Mattos
Quoted 5 lines · Erick Mattos

2010/7/20 Brandon Casey <[email protected]>

Quoted 2 lines

No time to investigate, but here is an example patch and the results of running the affected tests.

You have made cosmetic changes which do not do the same as the original.

Nope, look closer. The changes are not cosmetic.

Try this:

   run_it () { "$@"; }; run_it foo= true && echo success || echo failure

You probably get something like this (if you're using bash):

bash: foo=: command not found

That's because the one-shot variable assignment doesn't work when used like this. It also means that the original tests which do:

test_must_fail PAGER= git ...

are broken. We ran into this problem a while back and fixed it in the commit that I referenced (e2007832). I fixed the new instances in t2017, t3200, and t3301 in the patch that I sent.

For the tests in t2017 and t3200 that now fail, the originals seem to expect 'git reflog show' to return non-zero when asked to show the reflog for a ref which doesn't have a log. reflog does not currently return non-zero in this case. Either the tests should be updated to reflect the actual behavior of 'reflog show', or 'reflog show' should be updated to return non-zero when passed a ref without a log.

-brandon

Quoted 50 lines
Quoted 50 lines

--->8---
From: Brandon Casey <[email protected]>

See e2007832552ccea9befed9003580c494f09e666e

---
 t/t2017-checkout-orphan.sh |   36 ++++++++++++++++++++++++++++++------
 t/t3200-branch.sh          |    6 +++++-
 t/t3301-notes.sh           |    6 +++++-
 3 files changed, 40 insertions(+), 8 deletions(-)
t/t2017-checkout-orphan.sh +10 -2
index be88d4b..81cb393 100755
@@ -80,17 +84,29 @@ test_expect_success '--orphan does not make reflog when core.logAllRefUpdates =
       git config core.logAllRefUpdates false &&
       git checkout --orphan epsilon &&
       ! test -f .git/logs/refs/heads/epsilon &&
-       test_must_fail PAGER= git reflog show epsilon &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show epsilon
+       ) &&
       git commit -m Epsilon &&
       ! test -f .git/logs/refs/heads/epsilon &&
-       test_must_fail PAGER= git reflog show epsilon
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show epsilon
+       )
 '
 
t/t3200-branch.sh +5 -1
index 859b99a..bf7747d 100755
@@ -237,7 +237,11 @@ test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates
       git config core.logAllRefUpdates false &&
       git checkout -b beta &&
       ! test -f .git/logs/refs/heads/beta &&
-       test_must_fail PAGER= git reflog show beta
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show beta
+       )
 '
#32 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Hi,

2010/7/21 Brandon Casey <[email protected]>:

Quoted 8 lines · Erick Mattos
Quoted 5 lines

2010/7/20 Brandon Casey <[email protected]>

Quoted 2 lines

No time to investigate, but here is an example patch and the results of running the affected tests.

You have made cosmetic changes which do not do the same as the original.

?
Nope, look closer.  The changes are not cosmetic.

Now I see it. I was not completely aware of the problem, only of your email. Maybe I should subscribe to the list at last... ;-D

Quoted 7 lines

Try this:

  run_it () { "$@"; }; run_it foo= true && echo success || echo failure

You probably get something like this (if you're using bash):

  bash: foo=: command not found

It would work if it was like:

run_it () { eval "$@"; }; run_it "foo= true" && echo success || echo failure

But I think your approach is better shaped for a fast solution.

Quoted 9 lines

That's because the one-shot variable assignment doesn't work when used like this.  It also means that the original tests which do:

  test_must_fail PAGER= git ...

are broken.  We ran into this problem a while back and fixed it in the commit that I referenced (e2007832).  I fixed the new instances in t2017, t3200, and t3301 in the patch that I sent.

Quoted 6 lines

For the tests in t2017 and t3200 that now fail, the originals seem to expect 'git reflog show' to return non-zero when asked to show the reflog for a ref which doesn't have a log.  reflog does not currently return non-zero in this case.  Either the tests should be updated to reflect the actual behavior of 'reflog show', or 'reflog show' should be updated to return non-zero when passed a ref without a log.

So fixing it is a need.

On t2017 and t3200 the problem that appeared was because no message and error had been generated when there is no reflog. Git reflog when run on a ref with a nonexistent reflog file exits with 0 saying nothing.

I don't see this as a correct behavior but as those tests were just to enforce the previous "! test -f..." test which is already enough for checking the intended behavior then I would think it was good enough just to wipe out the "problematic git reflog" commands until deciding how quiet git reflog command should be when there is no reflog file to show.

Although I just realized Junio sent an email following this thread and I bet he could give a better solution or his directions. Going to read it now.

Thanks for your clarifications.

Regards

#33 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

In reply to Brandon Casey
Quoted 6 lines · Brandon Casey

-       test_must_fail PAGER= git reflog show delta &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show delta
+       ) &&

You must use "export PAGER;", not "export PAGER &&". export doesn't return zero on all systems when exporting, see previous changes in this regard in t/.

#34 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Quoted 3 lines · Ævar Arnfjörð Bjarmason

You must use "export PAGER;", not "export PAGER &&". export doesn't return zero on all systems when exporting, see previous changes in this regard in t/.

Nope. Sorry I missed this before.

t/README +4 -4
index b906ceb..f81998b 100644
@@ -259,11 +259,11 @@ Do:
 	test ...
 
    That way all of the commands in your tests will succeed or fail. If
-   you must ignore the return value of something (e.g. the return
-   value of export is unportable) it's best to indicate so explicitly
-   with a semicolon:
+   you must ignore the return value of something (e.g., the return
+   after unsetting a variable that was already unset is unportable) it's
+   best to indicate so explicitly with a semicolon:
 
-	export HLAGH;
+	unset HLAGH;
 	git merge hla &&
 	git push gh &&
 	test ...
#35 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Quoted 15 lines · Jonathan Nieder
Quoted 3 lines · Ævar Arnfjörð Bjarmason

You must use "export PAGER;", not "export PAGER &&". export doesn't return zero on all systems when exporting, see previous changes in this regard in t/.

Nope.  Sorry I missed this before.

t/README +0 -0
index b906ceb..f81998b 100644
@@ -259,11 +259,11 @@ Do:

       test ...

Quoted 7 lines

   That way all of the commands in your tests will succeed or fail. If
-   you must ignore the return value of something (e.g. the return
-   value of export is unportable) it's best to indicate so explicitly
-   with a semicolon:
+   you must ignore the return value of something (e.g., the return
+   after unsetting a variable that was already unset is unportable) it's
+   best to indicate so explicitly with a semicolon:

We should have examples for both export and unset, but the prose should mention both IMO

#36 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Quoted 1 line · Ævar Arnfjörð Bjarmason

We should have examples for both export and unset

What is unportable for “export” is the effect of exporting an unset variable. I am not even sure whether the return value is unportable, but it doesn’t matter; that is an example of a “Don’t” rather than a “Do it this way”.

See v1.5.6-rc0~61 (filter-branch: fix variable export logic, 2008-05-13) for an example.

Quoted 2 lines

but the prose
should mention both IMO

Yes, thanks for putting this portability guide together.

Jonathan

#37 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

Quoted 8 lines · Jonathan Nieder
Quoted 1 line · Ævar Arnfjörð Bjarmason

We should have examples for both export and unset

What is unportable for “export” is the effect of exporting an unset variable.  I am not even sure whether the return value is unportable, but it doesn’t matter; that is an example of a “Don’t” rather than a “Do it this way”.

I didn't know that. It'd be good if it were mentioned in the docs. I thought it was just export in general.

Quoted 2 lines

See v1.5.6-rc0~61 (filter-branch: fix variable export logic, 2008-05-13) for an example.

As an aside, how do you make these 61-commits-after-rc0 commit ids. Is there a sha1->that tool that I haven't spotted?

Quoted 4 lines
Quoted 2 lines

but the prose
should mention both IMO

Yes, thanks for putting this portability guide together.

Thanks for improving it, this change is a definite improvement, I just had a "wait, what's the export doing there then?" question when reading it.

#38 lore raw

git name-rev for fun and profit (Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail)

Quoted 2 lines · Ævar Arnfjörð Bjarmason

As an aside, how do you make these 61-commits-after-rc0 commit ids. Is there a sha1->that tool that I haven't spotted?

GIT_PAGER_IN_USE=1 git log --all-match --grep=shell --grep=export | git -p name-rev --tags --stdin

v1.5.6-rc0~61 is 61 commits before rc0 (well, the 61st-generation grandparent using the first parent where there is a choice). The distinction matters because “61 commits _after_ 1.5.6-rc0” is not well-defined.

If you want the latter sort of description anyway, ‘git describe’ might help.

#39 lore raw

Re: git name-rev for fun and profit (Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail)

Quoted 5 lines · Jonathan Nieder
Quoted 2 lines · Ævar Arnfjörð Bjarmason

As an aside, how do you make these 61-commits-after-rc0 commit ids. Is there a sha1->that tool that I haven't spotted?

Quoted 7 lines

 GIT_PAGER_IN_USE=1 git log --all-match --grep=shell --grep=export | git -p name-rev --tags --stdin

v1.5.6-rc0~61 is 61 commits before rc0 (well, the 61st-generation grandparent using the first parent where there is a choice).  The distinction matters because “61 commits _after_ 1.5.6-rc0” is not well-defined.

Thanks, added that as an alias in my .gitconfig:

        abbrev-commit = "!f() { git name-rev --tags \"$@\" | sed

's|.*tags/||;s|\\([0-9a-f]\\{7\\}\\).*|\\1|'; }; f"

Quoted 2 lines

If you want the latter sort of description anyway, ‘git describe’ might help.

git describe was actually more like what I wanted. I'd used it before, but forgotten it. Thanks.

#40 lore raw

Re: [PATCH] t/: work around one-shot variable assignment with test_must_fail

In reply to Ævar Arnfjörð Bjarmason
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Brandon Casey

-       test_must_fail PAGER= git reflog show delta &&
+       (
+               PAGER= &&
+               export PAGER &&
+               test_must_fail git reflog show delta
+       ) &&

Quoted 3 lines

You must use "export PAGER;", not "export PAGER &&". export doesn't return zero on all systems when exporting, see previous changes in this regard in t/.

Actually, see the t/README docs which explicitly mention this. Yay docs.

#41 lore raw

Re: [PATCH] t/README: clarify test_must_fail description

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano

How about being more explicit?

Run a git command and ensure it fails in a controlled way. Use this instead of "! <git-command>". When git-command dies due to a segfault, test_must_fail diagnoses it as an error; "! <git-command>" treats it as just another expected failure. letting such a bug go unnoticed.

Much better. If you want the last sentence to be grammatically correct, you could rephrase it like this:

...just another expected failure, which would let such a bug go unnoticed.

-brandon

#42 lore raw
In reply to Jared Hance
Quoted 12 lines · Jared Hance
Quoted 11 lines · Brandon Casey

I think you have misunderstood the explanation of test_must_fail.  The paragraph you quoted actually recommends using test_must_fail instead of "! <git-command>".

It says:

   Use this instead of "! <git-command>" to fail when git commands segfault.

Or with a slight rewording:

Quoted 8 lines
Quoted 2 lines

   Use test_must_fail instead of "! <git-command>" since test_must_fail will fail when <git-command> segfaults.

I think the wording of description of test_must_fail is slightly ambiguous. I read it to mean that:

   Use test_must_fail only when you are testing to see if git will segfault.

I've interpreted it to mean that as well, but it's starting to look like a good example of a garden path sentence.

Anyway, it looks like we're wrong and Brandon was right. But I'm going to submit a doc patch to t/README. Here's the existing use of ! v.s. test_must_fail:

    $ cat *.sh | grep -c 'test_must_fail git'
    863
    $ cat *sh | grep -c '! git '
    30

I.e. ! is only used to negate non-git commands like test.

The example in the comments for test_must_fail in test-lib.sh backs this up:

# Writing this as "! git checkout ../outerspace" is wrong, because # the failure could be due to a segv. We want a controlled failure.

Quoted 3 lines

Rather than:

   Use test_must_fail to be safe from git segfaults.

#43 lore raw
In reply to Brandon Casey
Quoted 14 lines · Brandon Casey
Quoted 6 lines
Quoted 6 lines

This was noticed because the second use of '!' does not include a space between the '!' and the opening parens.  Ksh interprets this as follows:

  !(pattern-list)
     Matches anything except one of the given patterns.

Quoted 7 lines
Quoted 4 lines

Ksh performs a file glob using the pattern-list and then tries to execute the first file in the list.  If a space is added between the '!' and the open parens, then Ksh will not interpret it as a pattern list, but in this case, it is preferred to use test_must_fail, so lets do so.

Isn't this a completely seperate thing? Was this test really the only bit in the test suite that did "!foo" instead of "! foo" ?

Quoted 20 lines

This was the only instance of "!()" that was failing for me.  I didn't look before, but now that I have, there is another instance of "!()" in t5541 that should be fixed.  t5541 hasn't caused a problem for me because GIT_TEST_HTTPD must be set in order to enable it, and I haven't done so.

Quoted 1 line

Does the test pass for you if you just:

Yes.

Quoted 11 lines

    @@ -281,7 +281,7 @@ add 'track-this'
     EOF

     test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
    -       !(git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1) &&
    +       ! (git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1) &&
           test_cmp expect actual
     '

A seperate patch to clean up those two + doc patch to the "Do's, don'ts & things to keep in mind" section in t/README would be really useful IMO. I had no idea that "!cmd" was an issue no ksh.