Skip to content

Commit 0cd1a88

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 62f3a45 commit 0cd1a88

File tree

6 files changed

+45
-24
lines changed

6 files changed

+45
-24
lines changed

t/lib-httpd.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ test_http_push_nonff () {
217217
git commit -a -m path2 --amend &&
218218
219219
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+
)
222226
'
223227

224228
test_expect_success 'non-fast-forward push show ref status' '

t/lib-submodule-update.sh

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,16 @@ replace_gitfile_with_git_dir () {
168168
# Note that this only supports submodules at the root level of the
169169
# superproject, with the default name, i.e. same as its path.
170170
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 &&
179178
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"
185181
}
186182

187183
test_git_directory_exists () {

t/t0060-path-utils.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ test_expect_success 'prefix_path rejects absolute path to dir with same beginnin
255255
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
256256
git init repo &&
257257
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
259262
'
260263

261264
relative_path /foo/a/b/c/ /foo/a/b/ c/

t/t3200-branch.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,13 @@ test_expect_success 'git branch -M baz bam should succeed within a worktree in w
245245
(
246246
cd bazdir &&
247247
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
249251
) &&
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 &&
251255
rm -r bazdir &&
252256
git worktree prune
253257
'

t/t5605-clone-local.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ test_expect_success 'preparing origin repository' '
1515
: >file && git add . && git commit -m1 &&
1616
git clone --bare . a.git &&
1717
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 &&
2024
git bundle create b1.bundle --all &&
2125
git bundle create b2.bundle main &&
2226
mkdir dir &&
@@ -29,7 +33,9 @@ test_expect_success 'preparing origin repository' '
2933
test_expect_success 'local clone without .git suffix' '
3034
git clone -l -s a b &&
3135
(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 &&
3339
git fetch)
3440
'
3541

t/t7402-submodule-rebase.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,19 @@ test_expect_success 'stash with a dirty submodule' '
8282
CURRENT=$(cd submodule && git rev-parse HEAD) &&
8383
git stash &&
8484
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+
8793
git stash apply &&
8894
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
9098
9199
'
92100

0 commit comments

Comments
 (0)