[v2,1/2] t3903: avoid git commands inside command substitution
diff mbox series

Message ID 20191113111718.21412-1-t.gummerer@gmail.com
State New
Headers show
Series
  • [v2,1/2] t3903: avoid git commands inside command substitution
Related show

Commit Message

Thomas Gummerer Nov. 13, 2019, 11:17 a.m. UTC
Running git commands inside command substitution can hide errors.
Avoid doing so in t3903.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 t/t3903-stash.sh | 99 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 69 insertions(+), 30 deletions(-)

Patch
diff mbox series

diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 392954d6dd..db7cc6e664 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -34,7 +34,7 @@  index 0cfbf08..00750ed 100644
 EOF
 
 test_expect_success 'parents of stash' '
-	test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
+	test_cmp_rev stash^ HEAD &&
 	git diff stash^2..stash >output &&
 	test_cmp expect output
 '
@@ -68,8 +68,11 @@  test_expect_success 'apply stashed changes' '
 	git commit -m other-file &&
 	git stash apply &&
 	test 3 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file)
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'apply stashed changes (including index)' '
@@ -80,8 +83,12 @@  test_expect_success 'apply stashed changes (including index)' '
 	git commit -m other-file &&
 	git stash apply --index &&
 	test 3 = $(cat file) &&
-	test 2 = $(git show :file) &&
-	test 1 = $(git show HEAD:file)
+	echo 2 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	echo 1 >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'unstashing in a subdirectory' '
@@ -107,8 +114,11 @@  test_expect_success 'drop top stash' '
 	test_cmp expected actual &&
 	git stash apply &&
 	test 3 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file)
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'drop middle stash' '
@@ -118,17 +128,24 @@  test_expect_success 'drop middle stash' '
 	echo 9 >file &&
 	git stash &&
 	git stash drop stash@{1} &&
-	test 2 = $(git stash list | wc -l) &&
+	git stash list >output &&
+	test_line_count = 2 output &&
 	git stash apply &&
 	test 9 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file) &&
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual &&
 	git reset --hard &&
 	git stash drop &&
 	git stash apply &&
 	test 3 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file)
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'drop middle stash by index' '
@@ -138,26 +155,37 @@  test_expect_success 'drop middle stash by index' '
 	echo 9 >file &&
 	git stash &&
 	git stash drop 1 &&
-	test 2 = $(git stash list | wc -l) &&
+	git stash list >output &&
+	test_line_count = 2 output &&
 	git stash apply &&
 	test 9 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file) &&
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual &&
 	git reset --hard &&
 	git stash drop &&
 	git stash apply &&
 	test 3 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file)
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'stash pop' '
 	git reset --hard &&
 	git stash pop &&
 	test 3 = $(cat file) &&
-	test 1 = $(git show :file) &&
-	test 1 = $(git show HEAD:file) &&
-	test 0 = $(git stash list | wc -l)
+	echo 1 >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual &&
+	git stash list >output &&
+	test_must_be_empty output
 '
 
 cat >expect <<EOF
@@ -207,8 +235,10 @@  test_expect_success 'stash branch' '
 	echo baz >file &&
 	git commit file -m second &&
 	git stash branch stashbranch &&
-	test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
-	test $(git rev-parse HEAD) = $(git rev-parse master^) &&
+	echo "refs/heads/stashbranch" >expect3 &&
+	git symbolic-ref HEAD >actual &&
+	test_cmp expect3 actual &&
+	test_cmp_rev HEAD master^ &&
 	git diff --cached >output &&
 	test_cmp expect output &&
 	git diff >output &&
@@ -217,7 +247,8 @@  test_expect_success 'stash branch' '
 	git commit -m alternate\ second &&
 	git diff master..stashbranch >output &&
 	test_cmp output expect2 &&
-	test 0 = $(git stash list | wc -l)
+	git stash list >output &&
+	test_must_be_empty output
 '
 
 test_expect_success 'apply -q is quiet' '
@@ -242,7 +273,9 @@  test_expect_success 'pop -q --index works and is quiet' '
 	git add file &&
 	git stash save --quiet &&
 	git stash pop -q --index >output.out 2>&1 &&
-	test foo = "$(git show :file)" &&
+	echo foo >expect &&
+	git show :file >actual &&
+	test_cmp expect actual &&
 	test_must_be_empty output.out
 '
 
@@ -500,7 +533,8 @@  test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
 	git stash branch stash-branch ${STASH_ID} &&
 	test_when_finished "git reset --hard HEAD && git checkout master &&
 	git branch -D stash-branch" &&
-	test $(git ls-files --modified | wc -l) -eq 1
+	git ls-files --modified >output &&
+	test_line_count = 1 output
 '
 
 test_expect_success 'stash branch - stashes on stack, stash-like argument' '
@@ -516,7 +550,8 @@  test_expect_success 'stash branch - stashes on stack, stash-like argument' '
 	git stash branch stash-branch ${STASH_ID} &&
 	test_when_finished "git reset --hard HEAD && git checkout master &&
 	git branch -D stash-branch" &&
-	test $(git ls-files --modified | wc -l) -eq 1
+	git ls-files --modified >actual &&
+	test_line_count = 1 actual
 '
 
 test_expect_success 'stash branch complains with no arguments' '
@@ -638,7 +673,8 @@  test_expect_success 'drop: fail early if specified stash is not a stash ref' '
 	git stash &&
 	echo bar >file &&
 	git stash &&
-	test_must_fail git stash drop $(git rev-parse stash@{0}) &&
+	stash=$(git rev-parse stash@{0}) &&
+	test_must_fail git stash drop $stash &&
 	git stash pop &&
 	test bar = "$(cat file)" &&
 	git reset --hard HEAD
@@ -652,7 +688,8 @@  test_expect_success 'pop: fail early if specified stash is not a stash ref' '
 	git stash &&
 	echo bar >file &&
 	git stash &&
-	test_must_fail git stash pop $(git rev-parse stash@{0}) &&
+	stash=$(git rev-parse stash@{0}) &&
+	test_must_fail git stash pop $stash &&
 	git stash pop &&
 	test bar = "$(cat file)" &&
 	git reset --hard HEAD
@@ -789,7 +826,7 @@  test_expect_success 'stash where working directory contains "HEAD" file' '
 	git stash &&
 	git diff-files --quiet &&
 	git diff-index --cached --quiet HEAD &&
-	test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
+	test_cmp_rev stash^ HEAD &&
 	git diff stash^..stash >output &&
 	test_cmp expect output
 '
@@ -807,7 +844,9 @@  test_expect_success 'store updates stash ref and reflog' '
 	git reset --hard &&
 	test_path_is_missing bazzy &&
 	git stash store -m quuxery $STASH_ID &&
-	test $(git rev-parse stash) = $STASH_ID &&
+	echo $STASH_ID >expect &&
+	git rev-parse stash >actual &&
+	test_cmp expect actual &&
 	git reflog --format=%H stash| grep $STASH_ID &&
 	git stash pop &&
 	grep quux bazzy