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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 23:44 UTC 4bd0785dc2eb7b3f23d25c8013337cc51ab1065d
11 files changed +120 -45
t/lib-submodule-update.sh
+3 -1
@@ -185,7 +185,9 @@ test_git_directory_exists () {
185 if test -f sub1/.git
186 then
187 # 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
191 fi
192 }
193
t/t0001-init.sh
+7 -2
@@ -598,9 +598,14 @@ test_expect_success 'invalid default branch name' '
598 test_expect_success 'branch -m with the initial branch' '
599 git init rename-initial &&
600 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 +
605 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
609 '
610
611 test_done
t/t0002-gitfile.sh
+3 -1
@@ -33,7 +33,9 @@ test_expect_success 'bad setup: invalid .git file path' '
33
34 test_expect_success 'final setup + check rev-parse --git-dir' '
35 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
39 '
40
41 test_expect_success 'check hash-object' '
t/t0060-path-utils.sh
+75 -28
@@ -10,20 +10,27 @@ TEST_PASSES_SANITIZE_LEAK=true
10
11 norm_path() {
12 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 + "
18 }
19
20 relative_path() {
21 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 + "
27 }
28
29 test_submodule_relative_url() {
30 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
34 "
35 }
36
@@ -64,9 +71,11 @@ ancestor() {
71 expected=$(($expected-$rootslash+$rootoff))
72 ;;
73 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 + "
79 }
80
81 # Some absolute path tests should be skipped on Windows due to path mangling
@@ -166,8 +175,10 @@ ancestor D:/Users/me C:/ -1 MINGW
175 ancestor //server/share/my-directory //server/share/ 14 MINGW
176
177 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
182 '
183
184 test_expect_success 'absolute path rejects the empty string' '
@@ -188,35 +199,61 @@ test_expect_success 'real path rejects the empty string' '
199 '
200
201 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 +
206 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
210 '
211
212 test_expect_success 'real path works on absolute paths 2' '
197 - nopath="hopefully-absent-path" &&
213 # Find an existing top-level directory for the remaining tests:
214 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
223 '
224
225 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 +
230 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 +
235 # Find an existing top-level directory for the remaining tests:
236 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
244 '
245
246 test_expect_success 'real path removes other extra slashes' '
215 - nopath="hopefully-absent-path" &&
247 # Find an existing top-level directory for the remaining tests:
248 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
257 '
258
259 test_expect_success SYMLINKS 'real path works on symlinks' '
@@ -227,19 +264,29 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
264 mkdir third &&
265 dir="$(cd .git && pwd -P)" &&
266 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 &&
270 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 &&
274 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 &&
278 ln -s ../first/file .git/syml &&
279 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
283 '
284
285 test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
286 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
290 '
291
292 test_expect_success 'prefix_path works with only absolute path to work tree' '
t/t0100-previous.sh
+6 -2
@@ -12,7 +12,9 @@ test_expect_success 'branch -d @{-1}' '
12 test_commit A &&
13 git checkout -b junk &&
14 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 &&
18 git branch -d @{-1} &&
19 test_must_fail git rev-parse --verify refs/heads/junk
20 '
@@ -21,7 +23,9 @@ test_expect_success 'branch -d @{-12} when there is not enough switches yet' '
23 git reflog expire --expire=now &&
24 git checkout -b junk2 &&
25 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 &&
29 test_must_fail git branch -d @{-12} &&
30 git rev-parse --verify refs/heads/main
31 '
t/t1504-ceiling-dirs.sh
+6 -2
@@ -6,8 +6,12 @@ TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 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 + '
15 }
16
17 test_fail() {
t/t2005-checkout-index-symlinks.sh
+5 -3
@@ -22,8 +22,10 @@ test_expect_success \
22 git checkout-index symlink &&
23 test -f symlink'
24
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 +'
30
31 test_done
t/t5522-pull-symlink.sh
+3 -1
@@ -78,7 +78,9 @@ test_expect_success SYMLINKS 'pushing from symlinked subdir' '
78 git commit -m push ./file &&
79 git push
80 ) &&
81 - test push = $(git show HEAD:subdir/file)
81 + echo push >expect &&
82 + git show HEAD:subdir/file >actual &&
83 + test_cmp expect actual
84 '
85
86 test_done
t/t7402-submodule-rebase.sh
+6 -3
@@ -55,12 +55,15 @@ chmod a+x fake-editor.sh
55
56 test_expect_success 'interactive rebase with a dirty submodule' '
57
58 - test submodule = $(git diff --name-only) &&
58 + echo submodule >expect &&
59 + git diff --name-only >actual &&
60 + test_cmp expect actual &&
61 HEAD=$(git rev-parse HEAD) &&
62 GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
63 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
67 '
68
69 test_expect_success 'rebase with dirty file and submodule fails' '
t/t7504-commit-msg-hook.sh
+3 -1
@@ -101,7 +101,9 @@ test_expect_success 'setup: commit-msg hook that always fails' '
101 '
102
103 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
107 }
108
109 test_expect_success 'with failing hook' '
t/t7810-grep.sh
+3 -1
@@ -1001,7 +1001,9 @@ test_expect_success 'log --committer does not search in timestamp' '
1001 test_expect_success 'grep with CE_VALID file' '
1002 git update-index --assume-unchanged t/t &&
1003 rm t/t &&
1004 - test "$(git grep test)" = "t/t:test" &&
1004 + echo "t/t:test" >expect &&
1005 + git grep test >actual &&
1006 + test_cmp expect actual &&
1007 git update-index --no-assume-unchanged t/t &&
1008 git checkout t/t
1009 '