completion tests: consolidate getting path of current working directory

Some tests of the __gitdir() helper function use the $TRASH_DIRECTORY variable in direct path comparisons. In general this should be avoided, because it might contain symbolic links. There happens to be no issues with this here, however, because those tests use $TRASH_DIRECTORY both for specifying the expected result and for specifying input which in turn is just 'echo'ed verbatim. Other __gitdir() tests ask for the path of the trash directory by running $(pwd -P) in each test, sometimes even twice in a single test. Run $(pwd) only once at the beginning of the test script to store the path of the trash directory in a variable, and use that variable in all __gitdir() tests. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 3, 2017 at 03:48 UTC f6114408113af39a18b21693c3a83600e06e5475
1 file changed +21 -23
t/t9902-completion.sh
+21 -23
@@ -124,15 +124,22 @@ invalid_variable_name='${foo.bar}'
124
125 actual="$TRASH_DIRECTORY/actual"
126
127 +if test_have_prereq MINGW
128 +then
129 + ROOT="$(pwd -W)"
130 +else
131 + ROOT="$(pwd)"
132 +fi
133 +
134 test_expect_success 'setup for __gitdir tests' '
135 mkdir -p subdir/subsubdir &&
136 git init otherrepo
137 '
138
139 test_expect_success '__gitdir - from command line (through $__git_dir)' '
133 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
140 + echo "$ROOT/otherrepo/.git" >expected &&
141 (
135 - __git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
142 + __git_dir="$ROOT/otherrepo/.git" &&
143 __gitdir >"$actual"
144 ) &&
145 test_cmp expected "$actual"
@@ -157,7 +164,7 @@ test_expect_success '__gitdir - .git directory in cwd' '
164 '
165
166 test_expect_success '__gitdir - .git directory in parent' '
160 - echo "$(pwd -P)/.git" >expected &&
167 + echo "$ROOT/.git" >expected &&
168 (
169 cd subdir/subsubdir &&
170 __gitdir >"$actual"
@@ -175,7 +182,7 @@ test_expect_success '__gitdir - cwd is a .git directory' '
182 '
183
184 test_expect_success '__gitdir - parent is a .git directory' '
178 - echo "$(pwd -P)/.git" >expected &&
185 + echo "$ROOT/.git" >expected &&
186 (
187 cd .git/refs/heads &&
188 __gitdir >"$actual"
@@ -184,9 +191,9 @@ test_expect_success '__gitdir - parent is a .git directory' '
191 '
192
193 test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
187 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
194 + echo "$ROOT/otherrepo/.git" >expected &&
195 (
189 - GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
196 + GIT_DIR="$ROOT/otherrepo/.git" &&
197 export GIT_DIR &&
198 __gitdir >"$actual"
199 ) &&
@@ -194,9 +201,9 @@ test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
201 '
202
203 test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
197 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
204 + echo "$ROOT/otherrepo/.git" >expected &&
205 (
199 - GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
206 + GIT_DIR="$ROOT/otherrepo/.git" &&
207 export GIT_DIR &&
208 cd subdir &&
209 __gitdir >"$actual"
@@ -206,24 +213,15 @@ test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
213
214 test_expect_success '__gitdir - non-existing $GIT_DIR' '
215 (
209 - GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
216 + GIT_DIR="$ROOT/non-existing" &&
217 export GIT_DIR &&
218 test_must_fail __gitdir
219 )
220 '
221
215 -function pwd_P_W () {
216 - if test_have_prereq MINGW
217 - then
218 - pwd -W
219 - else
220 - pwd -P
221 - fi
222 -}
223 -
222 test_expect_success '__gitdir - gitfile in cwd' '
225 - echo "$(pwd_P_W)/otherrepo/.git" >expected &&
226 - echo "gitdir: $(pwd_P_W)/otherrepo/.git" >subdir/.git &&
223 + echo "$ROOT/otherrepo/.git" >expected &&
224 + echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
225 test_when_finished "rm -f subdir/.git" &&
226 (
227 cd subdir &&
@@ -233,8 +231,8 @@ test_expect_success '__gitdir - gitfile in cwd' '
231 '
232
233 test_expect_success '__gitdir - gitfile in parent' '
236 - echo "$(pwd_P_W)/otherrepo/.git" >expected &&
237 - echo "gitdir: $(pwd_P_W)/otherrepo/.git" >subdir/.git &&
234 + echo "$ROOT/otherrepo/.git" >expected &&
235 + echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git &&
236 test_when_finished "rm -f subdir/.git" &&
237 (
238 cd subdir/subsubdir &&
@@ -244,7 +242,7 @@ test_expect_success '__gitdir - gitfile in parent' '
242 '
243
244 test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
247 - echo "$(pwd -P)/otherrepo/.git" >expected &&
245 + echo "$ROOT/otherrepo/.git" >expected &&
246 mkdir otherrepo/dir &&
247 test_when_finished "rm -rf otherrepo/dir" &&
248 ln -s otherrepo/dir link &&