completion, bash prompt: move __gitdir() tests to completion test suite

Currently __gitdir() is duplicated in the git completion and prompt scripts, while its tests are in the prompt test suite. This patch series is about to change __git_ps1() in a way that it won't need __gitdir() anymore and __gitdir() will be removed from the prompt script. So move all __gitdir() tests from the prompt test suite over to the completion test suite. Update the setup tests so that they perform only those steps that are necessary for each test suite. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>

SZEDER Gábor committed Jun 17, 2013 at 20:31 UTC c9a102e81ffedde3fed4b88199ea13a3a5ee5f5d
2 files changed +134 -128
t/t9902-completion.sh
+134
@@ -122,6 +122,140 @@ test_gitcomp_nl ()
122
123 invalid_variable_name='${foo.bar}'
124
125 +actual="$TRASH_DIRECTORY/actual"
126 +
127 +test_expect_success 'setup for __gitdir tests' '
128 + mkdir -p subdir/subsubdir &&
129 + git init otherrepo
130 +'
131 +
132 +test_expect_success '__gitdir - from command line (through $__git_dir)' '
133 + echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
134 + (
135 + __git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
136 + __gitdir >"$actual"
137 + ) &&
138 + test_cmp expected "$actual"
139 +'
140 +
141 +test_expect_success '__gitdir - repo as argument' '
142 + echo "otherrepo/.git" >expected &&
143 + __gitdir "otherrepo" >"$actual" &&
144 + test_cmp expected "$actual"
145 +'
146 +
147 +test_expect_success '__gitdir - remote as argument' '
148 + echo "remote" >expected &&
149 + __gitdir "remote" >"$actual" &&
150 + test_cmp expected "$actual"
151 +'
152 +
153 +test_expect_success '__gitdir - .git directory in cwd' '
154 + echo ".git" >expected &&
155 + __gitdir >"$actual" &&
156 + test_cmp expected "$actual"
157 +'
158 +
159 +test_expect_success '__gitdir - .git directory in parent' '
160 + echo "$(pwd -P)/.git" >expected &&
161 + (
162 + cd subdir/subsubdir &&
163 + __gitdir >"$actual"
164 + ) &&
165 + test_cmp expected "$actual"
166 +'
167 +
168 +test_expect_success '__gitdir - cwd is a .git directory' '
169 + echo "." >expected &&
170 + (
171 + cd .git &&
172 + __gitdir >"$actual"
173 + ) &&
174 + test_cmp expected "$actual"
175 +'
176 +
177 +test_expect_success '__gitdir - parent is a .git directory' '
178 + echo "$(pwd -P)/.git" >expected &&
179 + (
180 + cd .git/refs/heads &&
181 + __gitdir >"$actual"
182 + ) &&
183 + test_cmp expected "$actual"
184 +'
185 +
186 +test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' '
187 + echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
188 + (
189 + GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
190 + export GIT_DIR &&
191 + __gitdir >"$actual"
192 + ) &&
193 + test_cmp expected "$actual"
194 +'
195 +
196 +test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' '
197 + echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
198 + (
199 + GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
200 + export GIT_DIR &&
201 + cd subdir &&
202 + __gitdir >"$actual"
203 + ) &&
204 + test_cmp expected "$actual"
205 +'
206 +
207 +test_expect_success '__gitdir - non-existing $GIT_DIR' '
208 + (
209 + GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
210 + export GIT_DIR &&
211 + test_must_fail __gitdir
212 + )
213 +'
214 +
215 +test_expect_success '__gitdir - gitfile in cwd' '
216 + echo "$(pwd -P)/otherrepo/.git" >expected &&
217 + echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git &&
218 + test_when_finished "rm -f subdir/.git" &&
219 + (
220 + cd subdir &&
221 + __gitdir >"$actual"
222 + ) &&
223 + test_cmp expected "$actual"
224 +'
225 +
226 +test_expect_success '__gitdir - gitfile in parent' '
227 + echo "$(pwd -P)/otherrepo/.git" >expected &&
228 + echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git &&
229 + test_when_finished "rm -f subdir/.git" &&
230 + (
231 + cd subdir/subsubdir &&
232 + __gitdir >"$actual"
233 + ) &&
234 + test_cmp expected "$actual"
235 +'
236 +
237 +test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' '
238 + echo "$(pwd -P)/otherrepo/.git" >expected &&
239 + mkdir otherrepo/dir &&
240 + test_when_finished "rm -rf otherrepo/dir" &&
241 + ln -s otherrepo/dir link &&
242 + test_when_finished "rm -f link" &&
243 + (
244 + cd link &&
245 + __gitdir >"$actual"
246 + ) &&
247 + test_cmp expected "$actual"
248 +'
249 +
250 +test_expect_success '__gitdir - not a git repository' '
251 + (
252 + cd subdir/subsubdir &&
253 + GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
254 + export GIT_CEILING_DIRECTORIES &&
255 + test_must_fail __gitdir
256 + )
257 +'
258 +
259 test_expect_success '__gitcomp - trailing space - options' '
260 test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
261 --reset-author" <<-EOF
t/t9903-bash-prompt.sh
-128
@@ -12,7 +12,6 @@ test_description='test git-specific bash prompt functions'
12 actual="$TRASH_DIRECTORY/actual"
13
14 test_expect_success 'setup for prompt tests' '
15 - mkdir -p subdir/subsubdir &&
15 git init otherrepo &&
16 echo 1 >file &&
17 git add file &&
@@ -35,133 +34,6 @@ test_expect_success 'setup for prompt tests' '
34 git checkout master
35 '
36
38 -test_expect_success 'gitdir - from command line (through $__git_dir)' '
39 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
40 - (
41 - __git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
42 - __gitdir >"$actual"
43 - ) &&
44 - test_cmp expected "$actual"
45 -'
46 -
47 -test_expect_success 'gitdir - repo as argument' '
48 - echo "otherrepo/.git" >expected &&
49 - __gitdir "otherrepo" >"$actual" &&
50 - test_cmp expected "$actual"
51 -'
52 -
53 -test_expect_success 'gitdir - remote as argument' '
54 - echo "remote" >expected &&
55 - __gitdir "remote" >"$actual" &&
56 - test_cmp expected "$actual"
57 -'
58 -
59 -test_expect_success 'gitdir - .git directory in cwd' '
60 - echo ".git" >expected &&
61 - __gitdir >"$actual" &&
62 - test_cmp expected "$actual"
63 -'
64 -
65 -test_expect_success 'gitdir - .git directory in parent' '
66 - echo "$(pwd -P)/.git" >expected &&
67 - (
68 - cd subdir/subsubdir &&
69 - __gitdir >"$actual"
70 - ) &&
71 - test_cmp expected "$actual"
72 -'
73 -
74 -test_expect_success 'gitdir - cwd is a .git directory' '
75 - echo "." >expected &&
76 - (
77 - cd .git &&
78 - __gitdir >"$actual"
79 - ) &&
80 - test_cmp expected "$actual"
81 -'
82 -
83 -test_expect_success 'gitdir - parent is a .git directory' '
84 - echo "$(pwd -P)/.git" >expected &&
85 - (
86 - cd .git/refs/heads &&
87 - __gitdir >"$actual"
88 - ) &&
89 - test_cmp expected "$actual"
90 -'
91 -
92 -test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' '
93 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
94 - (
95 - GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
96 - export GIT_DIR &&
97 - __gitdir >"$actual"
98 - ) &&
99 - test_cmp expected "$actual"
100 -'
101 -
102 -test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
103 - echo "$TRASH_DIRECTORY/otherrepo/.git" >expected &&
104 - (
105 - GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
106 - export GIT_DIR &&
107 - cd subdir &&
108 - __gitdir >"$actual"
109 - ) &&
110 - test_cmp expected "$actual"
111 -'
112 -
113 -test_expect_success 'gitdir - non-existing $GIT_DIR' '
114 - (
115 - GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
116 - export GIT_DIR &&
117 - test_must_fail __gitdir
118 - )
119 -'
120 -
121 -test_expect_success 'gitdir - gitfile in cwd' '
122 - echo "$(pwd -P)/otherrepo/.git" >expected &&
123 - echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git &&
124 - test_when_finished "rm -f subdir/.git" &&
125 - (
126 - cd subdir &&
127 - __gitdir >"$actual"
128 - ) &&
129 - test_cmp expected "$actual"
130 -'
131 -
132 -test_expect_success 'gitdir - gitfile in parent' '
133 - echo "$(pwd -P)/otherrepo/.git" >expected &&
134 - echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git &&
135 - test_when_finished "rm -f subdir/.git" &&
136 - (
137 - cd subdir/subsubdir &&
138 - __gitdir >"$actual"
139 - ) &&
140 - test_cmp expected "$actual"
141 -'
142 -
143 -test_expect_success SYMLINKS 'gitdir - resulting path avoids symlinks' '
144 - echo "$(pwd -P)/otherrepo/.git" >expected &&
145 - mkdir otherrepo/dir &&
146 - test_when_finished "rm -rf otherrepo/dir" &&
147 - ln -s otherrepo/dir link &&
148 - test_when_finished "rm -f link" &&
149 - (
150 - cd link &&
151 - __gitdir >"$actual"
152 - ) &&
153 - test_cmp expected "$actual"
154 -'
155 -
156 -test_expect_success 'gitdir - not a git repository' '
157 - (
158 - cd subdir/subsubdir &&
159 - GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
160 - export GIT_CEILING_DIRECTORIES &&
161 - test_must_fail __gitdir
162 - )
163 -'
164 -
37 test_expect_success 'prompt - branch name' '
38 printf " (master)" >expected &&
39 __git_ps1 >"$actual" &&