Skip to content

Commit 4bd0785

Browse files
avargitster
authored andcommitted
tests: don't lose exit status with "test <op> $(git ...)"
As with the preceding commit, rewrite tests that ran "git" inside command substitution and lost the exit status of "git" so that we notice the failing "git". This time around we're converting cases that didn't involve a containing sub-shell around the command substitution. In the case of "t0060-path-utils.sh" and "t2005-checkout-index-symlinks.sh" convert the relevant code to using the modern style of indentation and newline wrapping while having to change it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c7e03b4 commit 4bd0785

11 files changed

+120
-45
lines changed

t/lib-submodule-update.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ test_git_directory_exists () {
185185
if test -f sub1/.git
186186
then
187187
# does core.worktree point at the right place?
188-
test "$(git -C .git/modules/$1 config core.worktree)" = "../../../$1"
188+
echo "../../../$1" >expect &&
189+
git -C ".git/modules/$1" config core.worktree >actual &&
190+
test_cmp expect actual
189191
fi
190192
}
191193

t/t0001-init.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,14 @@ test_expect_success 'invalid default branch name' '
598598
test_expect_success 'branch -m with the initial branch' '
599599
git init rename-initial &&
600600
git -C rename-initial branch -m renamed &&
601-
test renamed = $(git -C rename-initial symbolic-ref --short HEAD) &&
601+
echo renamed >expect &&
602+
git -C rename-initial symbolic-ref --short HEAD >actual &&
603+
test_cmp expect actual &&
604+
602605
git -C rename-initial branch -m renamed again &&
603-
test again = $(git -C rename-initial symbolic-ref --short HEAD)
606+
echo again >expect &&
607+
git -C rename-initial symbolic-ref --short HEAD >actual &&
608+
test_cmp expect actual
604609
'
605610

606611
test_done

t/t0002-gitfile.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ test_expect_success 'bad setup: invalid .git file path' '
3333

3434
test_expect_success 'final setup + check rev-parse --git-dir' '
3535
echo "gitdir: $REAL" >.git &&
36-
test "$REAL" = "$(git rev-parse --git-dir)"
36+
echo "$REAL" >expect &&
37+
git rev-parse --git-dir >actual &&
38+
test_cmp expect actual
3739
'
3840

3941
test_expect_success 'check hash-object' '

t/t0060-path-utils.sh

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ TEST_PASSES_SANITIZE_LEAK=true
1010

1111
norm_path() {
1212
expected=$(test-tool path-utils print_path "$2")
13-
test_expect_success $3 "normalize path: $1 => $2" \
14-
"test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'"
13+
test_expect_success $3 "normalize path: $1 => $2" "
14+
echo '$expected' >expect &&
15+
test-tool path-utils normalize_path_copy '$1' >actual &&
16+
test_cmp expect actual
17+
"
1518
}
1619

1720
relative_path() {
1821
expected=$(test-tool path-utils print_path "$3")
19-
test_expect_success $4 "relative path: $1 $2 => $3" \
20-
"test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'"
22+
test_expect_success $4 "relative path: $1 $2 => $3" "
23+
echo '$expected' >expect &&
24+
test-tool path-utils relative_path '$1' '$2' >actual &&
25+
test_cmp expect actual
26+
"
2127
}
2228

2329
test_submodule_relative_url() {
2430
test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
25-
actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') &&
26-
test \"\$actual\" = '$4'
31+
echo '$4' >expect &&
32+
test-tool submodule resolve-relative-url '$1' '$2' '$3' >actual &&
33+
test_cmp expect actual
2734
"
2835
}
2936

@@ -64,9 +71,11 @@ ancestor() {
6471
expected=$(($expected-$rootslash+$rootoff))
6572
;;
6673
esac
67-
test_expect_success $4 "longest ancestor: $1 $2 => $expected" \
68-
"actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') &&
69-
test \"\$actual\" = '$expected'"
74+
test_expect_success $4 "longest ancestor: $1 $2 => $expected" "
75+
echo '$expected' >expect &&
76+
test-tool path-utils longest_ancestor_length '$1' '$2' >actual &&
77+
test_cmp expect actual
78+
"
7079
}
7180

7281
# Some absolute path tests should be skipped on Windows due to path mangling
@@ -166,8 +175,10 @@ ancestor D:/Users/me C:/ -1 MINGW
166175
ancestor //server/share/my-directory //server/share/ 14 MINGW
167176

168177
test_expect_success 'strip_path_suffix' '
169-
test c:/msysgit = $(test-tool path-utils strip_path_suffix \
170-
c:/msysgit/libexec//git-core libexec/git-core)
178+
echo c:/msysgit >expect &&
179+
test-tool path-utils strip_path_suffix \
180+
c:/msysgit/libexec//git-core libexec/git-core >actual &&
181+
test_cmp expect actual
171182
'
172183

173184
test_expect_success 'absolute path rejects the empty string' '
@@ -188,35 +199,61 @@ test_expect_success 'real path rejects the empty string' '
188199
'
189200

190201
test_expect_success POSIX 'real path works on absolute paths 1' '
202+
echo / >expect &&
203+
test-tool path-utils real_path "/" >actual &&
204+
test_cmp expect actual &&
205+
191206
nopath="hopefully-absent-path" &&
192-
test "/" = "$(test-tool path-utils real_path "/")" &&
193-
test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")"
207+
echo "/$nopath" >expect &&
208+
test-tool path-utils real_path "/$nopath" >actual &&
209+
test_cmp expect actual
194210
'
195211

196212
test_expect_success 'real path works on absolute paths 2' '
197-
nopath="hopefully-absent-path" &&
198213
# Find an existing top-level directory for the remaining tests:
199214
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
200-
test "$d" = "$(test-tool path-utils real_path "$d")" &&
201-
test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")"
215+
echo "$d" >expect &&
216+
test-tool path-utils real_path "$d" >actual &&
217+
test_cmp expect actual &&
218+
219+
nopath="hopefully-absent-path" &&
220+
echo "$d/$nopath" >expect &&
221+
test-tool path-utils real_path "$d/$nopath" >actual &&
222+
test_cmp expect actual
202223
'
203224

204225
test_expect_success POSIX 'real path removes extra leading slashes' '
226+
echo "/" >expect &&
227+
test-tool path-utils real_path "///" >actual &&
228+
test_cmp expect actual &&
229+
205230
nopath="hopefully-absent-path" &&
206-
test "/" = "$(test-tool path-utils real_path "///")" &&
207-
test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" &&
231+
echo "/$nopath" >expect &&
232+
test-tool path-utils real_path "///$nopath" >actual &&
233+
test_cmp expect actual &&
234+
208235
# Find an existing top-level directory for the remaining tests:
209236
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
210-
test "$d" = "$(test-tool path-utils real_path "//$d")" &&
211-
test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")"
237+
echo "$d" >expect &&
238+
test-tool path-utils real_path "//$d" >actual &&
239+
test_cmp expect actual &&
240+
241+
echo "$d/$nopath" >expect &&
242+
test-tool path-utils real_path "//$d/$nopath" >actual &&
243+
test_cmp expect actual
212244
'
213245

214246
test_expect_success 'real path removes other extra slashes' '
215-
nopath="hopefully-absent-path" &&
216247
# Find an existing top-level directory for the remaining tests:
217248
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
218-
test "$d" = "$(test-tool path-utils real_path "$d///")" &&
219-
test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")"
249+
echo "$d" >expect &&
250+
test-tool path-utils real_path "$d///" >actual &&
251+
test_cmp expect actual &&
252+
253+
nopath="hopefully-absent-path" &&
254+
echo "$d/$nopath" >expect &&
255+
test-tool path-utils real_path "$d///$nopath" >actual &&
256+
test_cmp expect actual
220257
'
221258

222259
test_expect_success SYMLINKS 'real path works on symlinks' '
@@ -227,19 +264,29 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
227264
mkdir third &&
228265
dir="$(cd .git && pwd -P)" &&
229266
dir2=third/../second/other/.git &&
230-
test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
267+
echo "$dir" >expect &&
268+
test-tool path-utils real_path $dir2 >actual &&
269+
test_cmp expect actual &&
231270
file="$dir"/index &&
232-
test "$file" = "$(test-tool path-utils real_path $dir2/index)" &&
271+
echo "$file" >expect &&
272+
test-tool path-utils real_path $dir2/index >actual &&
273+
test_cmp expect actual &&
233274
basename=blub &&
234-
test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
275+
echo "$dir/$basename" >expect &&
276+
test-tool -C .git path-utils real_path "$basename" >actual &&
277+
test_cmp expect actual &&
235278
ln -s ../first/file .git/syml &&
236279
sym="$(cd first && pwd -P)"/file &&
237-
test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
280+
echo "$sym" >expect &&
281+
test-tool path-utils real_path "$dir2/syml" >actual &&
282+
test_cmp expect actual
238283
'
239284

240285
test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
241286
ln -s target symlink &&
242-
test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
287+
echo "symlink" >expect &&
288+
test-tool path-utils prefix_path prefix "$(pwd)/symlink" >actual &&
289+
test_cmp expect actual
243290
'
244291

245292
test_expect_success 'prefix_path works with only absolute path to work tree' '

t/t0100-previous.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ test_expect_success 'branch -d @{-1}' '
1212
test_commit A &&
1313
git checkout -b junk &&
1414
git checkout - &&
15-
test "$(git symbolic-ref HEAD)" = refs/heads/main &&
15+
echo refs/heads/main >expect &&
16+
git symbolic-ref HEAD >actual &&
17+
test_cmp expect actual &&
1618
git branch -d @{-1} &&
1719
test_must_fail git rev-parse --verify refs/heads/junk
1820
'
@@ -21,7 +23,9 @@ test_expect_success 'branch -d @{-12} when there is not enough switches yet' '
2123
git reflog expire --expire=now &&
2224
git checkout -b junk2 &&
2325
git checkout - &&
24-
test "$(git symbolic-ref HEAD)" = refs/heads/main &&
26+
echo refs/heads/main >expect &&
27+
git symbolic-ref HEAD >actual &&
28+
test_cmp expect actual &&
2529
test_must_fail git branch -d @{-12} &&
2630
git rev-parse --verify refs/heads/main
2731
'

t/t1504-ceiling-dirs.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77

88
test_prefix() {
9-
test_expect_success "$1" \
10-
"test '$2' = \"\$(git rev-parse --show-prefix)\""
9+
local expect="$2" &&
10+
test_expect_success "$1: git rev-parse --show-prefix is '$2'" '
11+
echo "$expect" >expect &&
12+
git rev-parse --show-prefix >actual &&
13+
test_cmp expect actual
14+
'
1115
}
1216

1317
test_fail() {

t/t2005-checkout-index-symlinks.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ test_expect_success \
2222
git checkout-index symlink &&
2323
test -f symlink'
2424

25-
test_expect_success \
26-
'the file must be the blob we added during the setup' '
27-
test "$(git hash-object -t blob symlink)" = $l'
25+
test_expect_success 'the file must be the blob we added during the setup' '
26+
echo "$l" >expect &&
27+
git hash-object -t blob symlink >actual &&
28+
test_cmp expect actual
29+
'
2830

2931
test_done

t/t5522-pull-symlink.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ test_expect_success SYMLINKS 'pushing from symlinked subdir' '
7878
git commit -m push ./file &&
7979
git push
8080
) &&
81-
test push = $(git show HEAD:subdir/file)
81+
echo push >expect &&
82+
git show HEAD:subdir/file >actual &&
83+
test_cmp expect actual
8284
'
8385

8486
test_done

t/t7402-submodule-rebase.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ chmod a+x fake-editor.sh
5555

5656
test_expect_success 'interactive rebase with a dirty submodule' '
5757
58-
test submodule = $(git diff --name-only) &&
58+
echo submodule >expect &&
59+
git diff --name-only >actual &&
60+
test_cmp expect actual &&
5961
HEAD=$(git rev-parse HEAD) &&
6062
GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
6163
git rebase -i HEAD^ &&
62-
test submodule = $(git diff --name-only)
63-
64+
echo submodule >expect &&
65+
git diff --name-only >actual &&
66+
test_cmp expect actual
6467
'
6568

6669
test_expect_success 'rebase with dirty file and submodule fails' '

t/t7504-commit-msg-hook.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ test_expect_success 'setup: commit-msg hook that always fails' '
101101
'
102102

103103
commit_msg_is () {
104-
test "$(git log --pretty=format:%s%b -1)" = "$1"
104+
printf "%s" "$1" >expect &&
105+
git log --pretty=format:%s%b -1 >actual &&
106+
test_cmp expect actual
105107
}
106108

107109
test_expect_success 'with failing hook' '

0 commit comments

Comments
 (0)