tests: don't lose exit status with "(cd ...; test <op> $(git ...))"
Rewrite tests that ran "git" inside command substitution and lost the exit status of "git" so that we notice the failing "git". Have them use modern patterns such as a "test_cmp" of the expected outputs instead. We'll fix more of these these in the subsequent commit, for now we're only converting the cases where this loss of exit code was combined with spawning a sub-shell. 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
0cd1a8818db35df70c88d7864682146bf4fa8227
6 files changed
+45
-24
t/lib-httpd.sh
+6
-2
@@ -217,8 +217,12 @@ test_http_push_nonff () {
217
git commit -a -m path2 --amend &&
218
219
test_must_fail git push -v origin >output 2>&1 &&
220
- (cd "$REMOTE_REPO" &&
221
- test $HEAD = $(git rev-parse --verify HEAD))
220
+ (
221
+ cd "$REMOTE_REPO" &&
222
+ echo "$HEAD" >expect &&
223
+ git rev-parse --verify HEAD >actual &&
224
+ test_cmp expect actual
225
+ )
226
'
227
228
test_expect_success 'non-fast-forward push show ref status' '
t/lib-submodule-update.sh
+9
-13
@@ -168,20 +168,16 @@ replace_gitfile_with_git_dir () {
168
# Note that this only supports submodules at the root level of the
169
# superproject, with the default name, i.e. same as its path.
170
test_git_directory_is_unchanged () {
171
- (
172
- cd ".git/modules/$1" &&
173
- # does core.worktree point at the right place?
174
- test "$(git config core.worktree)" = "../../../$1" &&
175
- # remove it temporarily before comparing, as
176
- # "$1/.git/config" lacks it...
177
- git config --unset core.worktree
178
- ) &&
171
+ # does core.worktree point at the right place?
172
+ echo "../../../$1" >expect &&
173
+ git -C ".git/modules/$1" config core.worktree >actual &&
174
+ test_cmp expect actual &&
175
+ # remove it temporarily before comparing, as
176
+ # "$1/.git/config" lacks it...
177
+ git -C ".git/modules/$1" config --unset core.worktree &&
178
diff -r ".git/modules/$1" "$1/.git" &&
180
- (
181
- # ... and then restore.
182
- cd ".git/modules/$1" &&
183
- git config core.worktree "../../../$1"
184
- )
179
+ # ... and then restore.
180
+ git -C ".git/modules/$1" config core.worktree "../../../$1"
181
}
182
183
test_git_directory_exists () {
t/t0060-path-utils.sh
+4
-1
@@ -255,7 +255,10 @@ test_expect_success 'prefix_path rejects absolute path to dir with same beginnin
255
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
256
git init repo &&
257
ln -s repo repolink &&
258
- test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")"
258
+ echo "a" >expect &&
259
+ repo_path="$(cd repo && pwd)" &&
260
+ test-tool -C repo path-utils prefix_path prefix "$repo_path/../repolink/a" >actual &&
261
+ test_cmp expect actual
262
'
263
264
relative_path /foo/a/b/c/ /foo/a/b/ c/
t/t3200-branch.sh
+6
-2
@@ -245,9 +245,13 @@ test_expect_success 'git branch -M baz bam should succeed within a worktree in w
245
(
246
cd bazdir &&
247
git branch -M baz bam &&
248
- test $(git rev-parse --abbrev-ref HEAD) = bam
248
+ echo bam >expect &&
249
+ git rev-parse --abbrev-ref HEAD >actual &&
250
+ test_cmp expect actual
251
) &&
250
- test $(git rev-parse --abbrev-ref HEAD) = bam &&
252
+ echo bam >expect &&
253
+ git rev-parse --abbrev-ref HEAD >actual &&
254
+ test_cmp expect actual &&
255
rm -r bazdir &&
256
git worktree prune
257
'
t/t5605-clone-local.sh
+9
-3
@@ -15,8 +15,12 @@ test_expect_success 'preparing origin repository' '
15
: >file && git add . && git commit -m1 &&
16
git clone --bare . a.git &&
17
git clone --bare . x &&
18
- test "$(cd a.git && git config --bool core.bare)" = true &&
19
- test "$(cd x && git config --bool core.bare)" = true &&
18
+ echo true >expect &&
19
+ git -C a.git config --bool core.bare >actual &&
20
+ test_cmp expect actual &&
21
+ echo true >expect &&
22
+ git -C x config --bool core.bare >actual &&
23
+ test_cmp expect actual &&
24
git bundle create b1.bundle --all &&
25
git bundle create b2.bundle main &&
26
mkdir dir &&
@@ -29,7 +33,9 @@ test_expect_success 'preparing origin repository' '
33
test_expect_success 'local clone without .git suffix' '
34
git clone -l -s a b &&
35
(cd b &&
32
- test "$(git config --bool core.bare)" = false &&
36
+ echo false >expect &&
37
+ git config --bool core.bare >actual &&
38
+ test_cmp expect actual &&
39
git fetch)
40
'
41
t/t7402-submodule-rebase.sh
+11
-3
@@ -82,11 +82,19 @@ test_expect_success 'stash with a dirty submodule' '
82
CURRENT=$(cd submodule && git rev-parse HEAD) &&
83
git stash &&
84
test new != $(cat file) &&
85
- test submodule = $(git diff --name-only) &&
86
- test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
85
+ echo submodule >expect &&
86
+ git diff --name-only >actual &&
87
+ test_cmp expect actual &&
88
+
89
+ echo "$CURRENT" >expect &&
90
+ git -C submodule rev-parse HEAD >actual &&
91
+ test_cmp expect actual &&
92
+
93
git stash apply &&
94
test new = $(cat file) &&
89
- test $CURRENT = $(cd submodule && git rev-parse HEAD)
95
+ echo "$CURRENT" >expect &&
96
+ git -C submodule rev-parse HEAD >actual &&
97
+ test_cmp expect actual
98
99
'
100