git-p4: test client view handling
Test many aspects of processing p4 client views with the git-p4 option --use-client-spec. 16 out of 22 tests are currently broken. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Jan 2, 2012 at 18:05 UTC
c700b684cf879f80d5e9e918210475b02339fc29
1 file changed
+290
t/t9809-git-p4-client-view.sh
new
+290
@@ -0,0 +1,290 @@
1
+#!/bin/sh
2
+
3
+test_description='git-p4 client view'
4
+
5
+. ./lib-git-p4.sh
6
+
7
+test_expect_success 'start p4d' '
8
+ start_p4d
9
+'
10
+
11
+#
12
+# Construct a client with this list of View lines
13
+#
14
+client_view() {
15
+ (
16
+ cat <<-EOF &&
17
+ Client: client
18
+ Description: client
19
+ Root: $cli
20
+ View:
21
+ EOF
22
+ for arg ; do
23
+ printf "\t$arg\n"
24
+ done
25
+ ) | p4 client -i
26
+}
27
+
28
+#
29
+# Verify these files exist, exactly. Caller creates
30
+# a list of files in file "files".
31
+#
32
+check_files_exist() {
33
+ ok=0 &&
34
+ num=${#@} &&
35
+ for arg ; do
36
+ test_path_is_file "$arg" &&
37
+ ok=$(($ok + 1))
38
+ done &&
39
+ test $ok -eq $num &&
40
+ test_line_count = $num files
41
+}
42
+
43
+#
44
+# Sync up the p4 client, make sure the given files (and only
45
+# those) exist.
46
+#
47
+client_verify() {
48
+ (
49
+ cd "$cli" &&
50
+ p4 sync &&
51
+ find . -type f ! -name files >files &&
52
+ check_files_exist "$@"
53
+ )
54
+}
55
+
56
+#
57
+# Make sure the named files, exactly, exist.
58
+#
59
+git_verify() {
60
+ (
61
+ cd "$git" &&
62
+ git ls-files >files &&
63
+ check_files_exist "$@"
64
+ )
65
+}
66
+
67
+# //depot
68
+# - dir1
69
+# - file11
70
+# - file12
71
+# - dir2
72
+# - file21
73
+# - file22
74
+test_expect_success 'init depot' '
75
+ (
76
+ cd "$cli" &&
77
+ for d in 1 2 ; do
78
+ mkdir -p dir$d &&
79
+ for f in 1 2 ; do
80
+ echo dir$d/file$d$f >dir$d/file$d$f &&
81
+ p4 add dir$d/file$d$f &&
82
+ p4 submit -d "dir$d/file$d$f"
83
+ done
84
+ done &&
85
+ find . -type f ! -name files >files &&
86
+ check_files_exist dir1/file11 dir1/file12 \
87
+ dir2/file21 dir2/file22
88
+ )
89
+'
90
+
91
+# double % for printf
92
+test_expect_failure 'unsupported view wildcard %%n' '
93
+ client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
94
+ test_when_finished cleanup_git &&
95
+ test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
96
+'
97
+
98
+test_expect_failure 'unsupported view wildcard *' '
99
+ client_view "//depot/*/bar/... //client/*/bar/..." &&
100
+ test_when_finished cleanup_git &&
101
+ test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
102
+'
103
+
104
+test_expect_success 'wildcard ... only supported at end of spec' '
105
+ client_view "//depot/.../file11 //client/.../file11" &&
106
+ test_when_finished cleanup_git &&
107
+ test_must_fail "$GITP4" clone --use-client-spec --dest="$git" //depot
108
+'
109
+
110
+test_expect_failure 'basic map' '
111
+ client_view "//depot/dir1/... //client/cli1/..." &&
112
+ files="cli1/file11 cli1/file12" &&
113
+ client_verify $files &&
114
+ test_when_finished cleanup_git &&
115
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
116
+ git_verify $files
117
+'
118
+
119
+test_expect_failure 'client view with no mappings' '
120
+ client_view &&
121
+ client_verify &&
122
+ test_when_finished cleanup_git &&
123
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
124
+ git_verify
125
+'
126
+
127
+test_expect_failure 'single file map' '
128
+ client_view "//depot/dir1/file11 //client/file11" &&
129
+ files="file11" &&
130
+ client_verify $files &&
131
+ test_when_finished cleanup_git &&
132
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
133
+ git_verify $files
134
+'
135
+
136
+test_expect_failure 'later mapping takes precedence (entire repo)' '
137
+ client_view "//depot/dir1/... //client/cli1/..." \
138
+ "//depot/... //client/cli2/..." &&
139
+ files="cli2/dir1/file11 cli2/dir1/file12
140
+ cli2/dir2/file21 cli2/dir2/file22" &&
141
+ client_verify $files &&
142
+ test_when_finished cleanup_git &&
143
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
144
+ git_verify $files
145
+'
146
+
147
+test_expect_failure 'later mapping takes precedence (partial repo)' '
148
+ client_view "//depot/dir1/... //client/..." \
149
+ "//depot/dir2/... //client/..." &&
150
+ files="file21 file22" &&
151
+ client_verify $files &&
152
+ test_when_finished cleanup_git &&
153
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
154
+ git_verify $files
155
+'
156
+
157
+# Reading the view backwards,
158
+# dir2 goes to cli12
159
+# dir1 cannot go to cli12 since it was filled by dir2
160
+# dir1 also does not go to cli3, since the second rule
161
+# noticed that it matched, but was already filled
162
+test_expect_failure 'depot path matching rejected client path' '
163
+ client_view "//depot/dir1/... //client/cli3/..." \
164
+ "//depot/dir1/... //client/cli12/..." \
165
+ "//depot/dir2/... //client/cli12/..." &&
166
+ files="cli12/file21 cli12/file22" &&
167
+ client_verify $files &&
168
+ test_when_finished cleanup_git &&
169
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
170
+ git_verify $files
171
+'
172
+
173
+# since both have the same //client/..., the exclusion
174
+# rule keeps everything out
175
+test_expect_failure 'exclusion wildcard, client rhs same (odd)' '
176
+ client_view "//depot/... //client/..." \
177
+ "-//depot/dir2/... //client/..." &&
178
+ client_verify &&
179
+ test_when_finished cleanup_git &&
180
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
181
+ git_verify
182
+'
183
+
184
+test_expect_success 'exclusion wildcard, client rhs different (normal)' '
185
+ client_view "//depot/... //client/..." \
186
+ "-//depot/dir2/... //client/dir2/..." &&
187
+ files="dir1/file11 dir1/file12" &&
188
+ client_verify $files &&
189
+ test_when_finished cleanup_git &&
190
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
191
+ git_verify $files
192
+'
193
+
194
+test_expect_failure 'exclusion single file' '
195
+ client_view "//depot/... //client/..." \
196
+ "-//depot/dir2/file22 //client/file22" &&
197
+ files="dir1/file11 dir1/file12 dir2/file21" &&
198
+ client_verify $files &&
199
+ test_when_finished cleanup_git &&
200
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
201
+ git_verify $files
202
+'
203
+
204
+test_expect_failure 'overlay wildcard' '
205
+ client_view "//depot/dir1/... //client/cli/..." \
206
+ "+//depot/dir2/... //client/cli/...\n" &&
207
+ files="cli/file11 cli/file12 cli/file21 cli/file22" &&
208
+ client_verify $files &&
209
+ test_when_finished cleanup_git &&
210
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
211
+ git_verify $files
212
+'
213
+
214
+test_expect_failure 'overlay single file' '
215
+ client_view "//depot/dir1/... //client/cli/..." \
216
+ "+//depot/dir2/file21 //client/cli/file21" &&
217
+ files="cli/file11 cli/file12 cli/file21" &&
218
+ client_verify $files &&
219
+ test_when_finished cleanup_git &&
220
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
221
+ git_verify $files
222
+'
223
+
224
+test_expect_failure 'exclusion with later inclusion' '
225
+ client_view "//depot/... //client/..." \
226
+ "-//depot/dir2/... //client/dir2/..." \
227
+ "//depot/dir2/... //client/dir2incl/..." &&
228
+ files="dir1/file11 dir1/file12 dir2incl/file21 dir2incl/file22" &&
229
+ client_verify $files &&
230
+ test_when_finished cleanup_git &&
231
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
232
+ git_verify $files
233
+'
234
+
235
+test_expect_failure 'quotes on rhs only' '
236
+ client_view "//depot/dir1/... \"//client/cdir 1/...\"" &&
237
+ client_verify "cdir 1/file11" "cdir 1/file12" &&
238
+ test_when_finished cleanup_git &&
239
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
240
+ git_verify "cdir 1/file11" "cdir 1/file12"
241
+'
242
+
243
+#
244
+# Rename directories to test quoting in depot-side mappings
245
+# //depot
246
+# - "dir 1"
247
+# - file11
248
+# - file12
249
+# - "dir 2"
250
+# - file21
251
+# - file22
252
+#
253
+test_expect_success 'rename files to introduce spaces' '
254
+ client_view "//depot/... //client/..." &&
255
+ client_verify dir1/file11 dir1/file12 \
256
+ dir2/file21 dir2/file22 &&
257
+ (
258
+ cd "$cli" &&
259
+ p4 open dir1/... &&
260
+ p4 move dir1/... "dir 1"/... &&
261
+ p4 open dir2/... &&
262
+ p4 move dir2/... "dir 2"/... &&
263
+ p4 submit -d "rename with spaces"
264
+ ) &&
265
+ client_verify "dir 1/file11" "dir 1/file12" \
266
+ "dir 2/file21" "dir 2/file22"
267
+'
268
+
269
+test_expect_failure 'quotes on lhs only' '
270
+ client_view "\"//depot/dir 1/...\" //client/cdir1/..." &&
271
+ files="cdir1/file11 cdir1/file12" &&
272
+ client_verify $files &&
273
+ test_when_finished cleanup_git &&
274
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
275
+ client_verify $files
276
+'
277
+
278
+test_expect_failure 'quotes on both sides' '
279
+ client_view "\"//depot/dir 1/...\" \"//client/cdir 1/...\"" &&
280
+ client_verify "cdir 1/file11" "cdir 1/file12" &&
281
+ test_when_finished cleanup_git &&
282
+ "$GITP4" clone --use-client-spec --dest="$git" //depot &&
283
+ git_verify "cdir 1/file11" "cdir 1/file12"
284
+'
285
+
286
+test_expect_success 'kill p4d' '
287
+ kill_p4d
288
+'
289
+
290
+test_done