Skip to content

Commit 324b170

Browse files
newrengitster
authored andcommitted
t2501: simplify the tests since we can now assume desired behavior
We no longer are dealing with a mixture of previous and desired behavior, so simplify the tests a bit. Acked-by: Derrick Stolee <[email protected]> Acked-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 580a5d7 commit 324b170

File tree

1 file changed

+36
-87
lines changed

1 file changed

+36
-87
lines changed

t/t2501-cwd-empty.sh

Lines changed: 36 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ test_expect_success setup '
3232
'
3333

3434
test_incidental_dir_removal () {
35-
works=$1 &&
36-
shift &&
37-
3835
test_when_finished "git reset --hard" &&
3936

4037
git checkout foo/bar/baz^{commit} &&
@@ -44,88 +41,57 @@ test_incidental_dir_removal () {
4441
cd foo &&
4542
"$@" &&
4643

47-
# Although we want pwd & git status to pass, test for existing
48-
# rather than desired behavior.
49-
if test "$works" = "success"
50-
then
51-
test-tool getcwd &&
52-
git status --porcelain
53-
else
54-
! test-tool getcwd &&
55-
test_might_fail git status --porcelain
56-
fi
44+
# Make sure foo still exists, and commands needing it work
45+
test-tool getcwd &&
46+
git status --porcelain
5747
) &&
5848
test_path_is_missing foo/bar/baz &&
5949
test_path_is_missing foo/bar &&
6050

61-
# Although we want dir to be present, test for existing rather
62-
# than desired behavior.
63-
if test "$works" = "success"
64-
then
65-
test_path_is_dir foo
66-
else
67-
test_path_is_missing foo
68-
fi
51+
test_path_is_dir foo
6952
}
7053

7154
test_required_dir_removal () {
72-
works=$1 &&
73-
shift &&
74-
7555
git checkout df_conflict^{commit} &&
7656
test_when_finished "git clean -fdx" &&
7757

7858
(
7959
cd dirORfile &&
8060

81-
# We'd like for the command to fail (much as it would if there
82-
# was an untracked file there), and for the index and worktree
83-
# to be left clean with pwd and git status working afterwards.
84-
# But test for existing rather than desired behavior.
85-
if test "$works" = "success"
86-
then
87-
test_must_fail "$@" 2>../error &&
88-
grep "Refusing to remove.*current working directory" ../error &&
89-
90-
git diff --exit-code HEAD &&
91-
92-
test-tool getcwd &&
93-
git status --porcelain
94-
else
95-
"$@" &&
96-
! test-tool getcwd &&
97-
test_might_fail git status --porcelain
98-
fi
61+
# Ensure command refuses to run
62+
test_must_fail "$@" 2>../error &&
63+
grep "Refusing to remove.*current working directory" ../error &&
64+
65+
# ...and that the index and working tree are left clean
66+
git diff --exit-code HEAD &&
67+
68+
# Ensure that getcwd and git status do not error out (which
69+
# they might if the current working directory had been removed)
70+
test-tool getcwd &&
71+
git status --porcelain
9972
) &&
10073

101-
# Although we want dirORfile to be present, test for existing rather
102-
# than desired behavior.
103-
if test "$works" = "success"
104-
then
105-
test_path_is_dir dirORfile
106-
else
107-
test_path_is_file dirORfile
108-
fi
74+
test_path_is_dir dirORfile
10975
}
11076

11177
test_expect_success 'checkout does not clean cwd incidentally' '
112-
test_incidental_dir_removal success git checkout init
78+
test_incidental_dir_removal git checkout init
11379
'
11480

11581
test_expect_success 'checkout fails if cwd needs to be removed' '
116-
test_required_dir_removal success git checkout fd_conflict
82+
test_required_dir_removal git checkout fd_conflict
11783
'
11884

11985
test_expect_success 'reset --hard does not clean cwd incidentally' '
120-
test_incidental_dir_removal success git reset --hard init
86+
test_incidental_dir_removal git reset --hard init
12187
'
12288

12389
test_expect_success 'reset --hard fails if cwd needs to be removed' '
124-
test_required_dir_removal success git reset --hard fd_conflict
90+
test_required_dir_removal git reset --hard fd_conflict
12591
'
12692

12793
test_expect_success 'merge does not clean cwd incidentally' '
128-
test_incidental_dir_removal success git merge reverted
94+
test_incidental_dir_removal git merge reverted
12995
'
13096

13197
# This file uses some simple merges where
@@ -154,46 +120,43 @@ test_expect_success 'merge fails if cwd needs to be removed; recursive friendly'
154120
GIT_TEST_MERGE_ALGORITHM=ort
155121

156122
test_expect_success 'merge fails if cwd needs to be removed' '
157-
test_required_dir_removal success git merge fd_conflict
123+
test_required_dir_removal git merge fd_conflict
158124
'
159125

160126
test_expect_success 'cherry-pick does not clean cwd incidentally' '
161-
test_incidental_dir_removal success git cherry-pick reverted
127+
test_incidental_dir_removal git cherry-pick reverted
162128
'
163129

164130
test_expect_success 'cherry-pick fails if cwd needs to be removed' '
165-
test_required_dir_removal success git cherry-pick fd_conflict
131+
test_required_dir_removal git cherry-pick fd_conflict
166132
'
167133

168134
test_expect_success 'rebase does not clean cwd incidentally' '
169-
test_incidental_dir_removal success git rebase reverted
135+
test_incidental_dir_removal git rebase reverted
170136
'
171137

172138
test_expect_success 'rebase fails if cwd needs to be removed' '
173-
test_required_dir_removal success git rebase fd_conflict
139+
test_required_dir_removal git rebase fd_conflict
174140
'
175141

176142
test_expect_success 'revert does not clean cwd incidentally' '
177-
test_incidental_dir_removal success git revert HEAD
143+
test_incidental_dir_removal git revert HEAD
178144
'
179145

180146
test_expect_success 'revert fails if cwd needs to be removed' '
181-
test_required_dir_removal success git revert undo_fd_conflict
147+
test_required_dir_removal git revert undo_fd_conflict
182148
'
183149

184150
test_expect_success 'rm does not clean cwd incidentally' '
185-
test_incidental_dir_removal success git rm bar/baz.t
151+
test_incidental_dir_removal git rm bar/baz.t
186152
'
187153

188154
test_expect_success 'apply does not remove cwd incidentally' '
189155
git diff HEAD HEAD~1 >patch &&
190-
test_incidental_dir_removal success git apply ../patch
156+
test_incidental_dir_removal git apply ../patch
191157
'
192158

193159
test_incidental_untracked_dir_removal () {
194-
works=$1 &&
195-
shift &&
196-
197160
test_when_finished "git reset --hard" &&
198161

199162
git checkout foo/bar/baz^{commit} &&
@@ -205,38 +168,24 @@ test_incidental_untracked_dir_removal () {
205168
cd untracked &&
206169
"$@" &&
207170

208-
# Although we want pwd & git status to pass, test for existing
209-
# rather than desired behavior.
210-
if test "$works" = "success"
211-
then
212-
test-tool getcwd &&
213-
git status --porcelain
214-
else
215-
! test-tool getcwd &&
216-
test_might_fail git status --porcelain
217-
fi
171+
# Make sure untracked still exists, and commands needing it work
172+
test-tool getcwd &&
173+
git status --porcelain
218174
) &&
219175
test_path_is_missing empty &&
220176
test_path_is_missing untracked/random &&
221177

222-
# Although we want dir to be present, test for existing rather
223-
# than desired behavior.
224-
if test "$works" = "success"
225-
then
226-
test_path_is_dir untracked
227-
else
228-
test_path_is_missing untracked
229-
fi
178+
test_path_is_dir untracked
230179
}
231180

232181
test_expect_success 'clean does not remove cwd incidentally' '
233-
test_incidental_untracked_dir_removal success \
182+
test_incidental_untracked_dir_removal \
234183
git -C .. clean -fd -e warnings . >warnings &&
235184
grep "Refusing to remove current working directory" warnings
236185
'
237186

238187
test_expect_success 'stash does not remove cwd incidentally' '
239-
test_incidental_untracked_dir_removal success \
188+
test_incidental_untracked_dir_removal \
240189
git stash --include-untracked
241190
'
242191

0 commit comments

Comments
 (0)