]>
Commit | Line | Data |
---|---|---|
e1970ce4 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test the very basics part #1. | |
7 | ||
8 | The rest of the test suite does not check the basic operation of git | |
9 | plumbing commands to work very carefully. Their job is to concentrate | |
10 | on tricky features that caused bugs in the past to detect regression. | |
11 | ||
12 | This test runs very basic features, like registering things in cache, | |
13 | writing tree, etc. | |
14 | ||
15 | Note that this test *deliberately* hard-codes many expected object | |
16 | IDs. When object ID computation changes, like in the previous case of | |
17 | swapping compression and hashing order, the person who is making the | |
18 | modification *should* take notice and update the test vectors here. | |
19 | ' | |
eea42069 | 20 | |
e1970ce4 JH |
21 | . ./test-lib.sh |
22 | ||
8cb79803 DL |
23 | try_local_xy () { |
24 | local x="local" y="alsolocal" && | |
25 | echo "$x $y" | |
01d3a526 MH |
26 | } |
27 | ||
7f0b5908 | 28 | # Check whether the shell supports the "local" keyword. "local" is not |
01d3a526 | 29 | # POSIX-standard, but it is very widely supported by POSIX-compliant |
7f0b5908 | 30 | # shells, and we rely on it within Git's test framework. |
01d3a526 | 31 | # |
7f0b5908 JK |
32 | # If your shell fails this test, the results of other tests may be |
33 | # unreliable. You may wish to report the problem to the Git mailing | |
34 | # list <git@vger.kernel.org>, as it could cause us to reconsider | |
35 | # relying on "local". | |
01d3a526 MH |
36 | test_expect_success 'verify that the running shell supports "local"' ' |
37 | x="notlocal" && | |
8cb79803 DL |
38 | y="alsonotlocal" && |
39 | echo "local alsolocal" >expected1 && | |
40 | try_local_xy >actual1 && | |
01d3a526 | 41 | test_cmp expected1 actual1 && |
8cb79803 DL |
42 | echo "notlocal alsonotlocal" >expected2 && |
43 | echo "$x $y" >actual2 && | |
01d3a526 MH |
44 | test_cmp expected2 actual2 |
45 | ' | |
46 | ||
e1970ce4 | 47 | ################################################################ |
5be60078 | 48 | # git init has been done in an empty repository. |
e1970ce4 JH |
49 | # make sure it is empty. |
50 | ||
1b5b2b64 SL |
51 | test_expect_success '.git/objects should be empty after git init in an empty repo' ' |
52 | find .git/objects -type f -print >should-be-empty && | |
53 | test_line_count = 0 should-be-empty | |
54 | ' | |
e1970ce4 | 55 | |
9106c097 LT |
56 | # also it should have 2 subdirectories; no fan-out anymore, pack, and info. |
57 | # 3 is counting "objects" itself | |
1b5b2b64 SL |
58 | test_expect_success '.git/objects should have 3 subdirectories' ' |
59 | find .git/objects -type d -print >full-of-directories && | |
60 | test_line_count = 3 full-of-directories | |
61 | ' | |
e1970ce4 | 62 | |
41ac414e JH |
63 | ################################################################ |
64 | # Test harness | |
65 | test_expect_success 'success is reported like this' ' | |
1b5b2b64 | 66 | : |
41ac414e | 67 | ' |
7b905119 | 68 | |
0445e6f0 IB |
69 | _run_sub_test_lib_test_common () { |
70 | neg="$1" name="$2" descr="$3" # stdin is the body of the test code | |
71 | shift 3 | |
565b6fa8 AS |
72 | mkdir "$name" && |
73 | ( | |
a63c12c9 JK |
74 | # Pretend we're not running under a test harness, whether we |
75 | # are or not. The test-lib output depends on the setting of | |
76 | # this variable, so we need a stable setting under which to run | |
77 | # the sub-test. | |
78 | sane_unset HARNESS_ACTIVE && | |
565b6fa8 AS |
79 | cd "$name" && |
80 | cat >"$name.sh" <<-EOF && | |
81 | #!$SHELL_PATH | |
82 | ||
83 | test_description='$descr (run in sub test-lib) | |
84 | ||
85 | This is run in a sub test-lib so that we do not get incorrect | |
86 | passing metrics | |
87 | ' | |
88 | ||
4231d1ba JH |
89 | # Tell the framework that we are self-testing to make sure |
90 | # it yields a stable result. | |
91 | GIT_TEST_FRAMEWORK_SELFTEST=t && | |
92 | ||
565b6fa8 AS |
93 | # Point to the t/test-lib.sh, which isn't in ../ as usual |
94 | . "\$TEST_DIRECTORY"/test-lib.sh | |
95 | EOF | |
96 | cat >>"$name.sh" && | |
97 | chmod +x "$name.sh" && | |
98 | export TEST_DIRECTORY && | |
68830470 JK |
99 | TEST_OUTPUT_DIRECTORY=$(pwd) && |
100 | export TEST_OUTPUT_DIRECTORY && | |
0445e6f0 IB |
101 | if test -z "$neg" |
102 | then | |
103 | ./"$name.sh" "$@" >out 2>err | |
104 | else | |
105 | ! ./"$name.sh" "$@" >out 2>err | |
106 | fi | |
565b6fa8 AS |
107 | ) |
108 | } | |
1b5b2b64 | 109 | |
0445e6f0 IB |
110 | run_sub_test_lib_test () { |
111 | _run_sub_test_lib_test_common '' "$@" | |
112 | } | |
113 | ||
114 | run_sub_test_lib_test_err () { | |
115 | _run_sub_test_lib_test_common '!' "$@" | |
116 | } | |
117 | ||
565b6fa8 AS |
118 | check_sub_test_lib_test () { |
119 | name="$1" # stdin is the expected output from the test | |
120 | ( | |
121 | cd "$name" && | |
ec10b018 | 122 | test_must_be_empty err && |
565b6fa8 AS |
123 | sed -e 's/^> //' -e 's/Z$//' >expect && |
124 | test_cmp expect out | |
125 | ) | |
126 | } | |
1b5b2b64 | 127 | |
0445e6f0 | 128 | check_sub_test_lib_test_err () { |
832c0e5e | 129 | name="$1" # stdin is the expected output from the test |
7a40cf15 | 130 | # expected error output is in descriptor 3 |
0445e6f0 IB |
131 | ( |
132 | cd "$name" && | |
133 | sed -e 's/^> //' -e 's/Z$//' >expect.out && | |
134 | test_cmp expect.out out && | |
135 | sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && | |
136 | test_cmp expect.err err | |
137 | ) | |
138 | } | |
139 | ||
5ebf89e8 AS |
140 | test_expect_success 'pretend we have a fully passing test suite' " |
141 | run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF && | |
142 | for i in 1 2 3 | |
143 | do | |
144 | test_expect_success \"passing test #\$i\" 'true' | |
145 | done | |
146 | test_done | |
147 | EOF | |
148 | check_sub_test_lib_test full-pass <<-\\EOF | |
149 | > ok 1 - passing test #1 | |
150 | > ok 2 - passing test #2 | |
151 | > ok 3 - passing test #3 | |
152 | > # passed all 3 test(s) | |
153 | > 1..3 | |
154 | EOF | |
155 | " | |
1b5b2b64 | 156 | |
5ebf89e8 | 157 | test_expect_success 'pretend we have a partially passing test suite' " |
77172420 | 158 | run_sub_test_lib_test_err \ |
5ebf89e8 AS |
159 | partial-pass '2/3 tests passing' <<-\\EOF && |
160 | test_expect_success 'passing test #1' 'true' | |
161 | test_expect_success 'failing test #2' 'false' | |
162 | test_expect_success 'passing test #3' 'true' | |
163 | test_done | |
164 | EOF | |
165 | check_sub_test_lib_test partial-pass <<-\\EOF | |
166 | > ok 1 - passing test #1 | |
167 | > not ok 2 - failing test #2 | |
168 | # false | |
169 | > ok 3 - passing test #3 | |
170 | > # failed 1 among 3 test(s) | |
171 | > 1..3 | |
172 | EOF | |
173 | " | |
1b5b2b64 | 174 | |
5ebf89e8 AS |
175 | test_expect_success 'pretend we have a known breakage' " |
176 | run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF && | |
177 | test_expect_success 'passing test' 'true' | |
178 | test_expect_failure 'pretend we have a known breakage' 'false' | |
179 | test_done | |
180 | EOF | |
181 | check_sub_test_lib_test failing-todo <<-\\EOF | |
182 | > ok 1 - passing test | |
183 | > not ok 2 - pretend we have a known breakage # TODO known breakage | |
184 | > # still have 1 known breakage(s) | |
185 | > # passed all remaining 1 test(s) | |
186 | > 1..2 | |
187 | EOF | |
188 | " | |
1b5b2b64 | 189 | |
565b6fa8 AS |
190 | test_expect_success 'pretend we have fixed a known breakage' " |
191 | run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF && | |
192 | test_expect_failure 'pretend we have fixed a known breakage' 'true' | |
1b5b2b64 SL |
193 | test_done |
194 | EOF | |
565b6fa8 | 195 | check_sub_test_lib_test passing-todo <<-\\EOF |
b73d9a23 AS |
196 | > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished |
197 | > # 1 known breakage(s) vanished; please update test(s) | |
1b5b2b64 SL |
198 | > 1..1 |
199 | EOF | |
7b905119 | 200 | " |
565b6fa8 | 201 | |
b73d9a23 AS |
202 | test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' " |
203 | run_sub_test_lib_test partially-passing-todos \ | |
204 | '2 TODO tests, one passing' <<-\\EOF && | |
205 | test_expect_failure 'pretend we have a known breakage' 'false' | |
206 | test_expect_success 'pretend we have a passing test' 'true' | |
207 | test_expect_failure 'pretend we have fixed another known breakage' 'true' | |
208 | test_done | |
209 | EOF | |
210 | check_sub_test_lib_test partially-passing-todos <<-\\EOF | |
211 | > not ok 1 - pretend we have a known breakage # TODO known breakage | |
212 | > ok 2 - pretend we have a passing test | |
213 | > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished | |
214 | > # 1 known breakage(s) vanished; please update test(s) | |
215 | > # still have 1 known breakage(s) | |
216 | > # passed all remaining 1 test(s) | |
217 | > 1..3 | |
218 | EOF | |
219 | " | |
220 | ||
5ebf89e8 | 221 | test_expect_success 'pretend we have a pass, fail, and known breakage' " |
77172420 | 222 | run_sub_test_lib_test_err \ |
5ebf89e8 AS |
223 | mixed-results1 'mixed results #1' <<-\\EOF && |
224 | test_expect_success 'passing test' 'true' | |
225 | test_expect_success 'failing test' 'false' | |
226 | test_expect_failure 'pretend we have a known breakage' 'false' | |
227 | test_done | |
228 | EOF | |
229 | check_sub_test_lib_test mixed-results1 <<-\\EOF | |
230 | > ok 1 - passing test | |
231 | > not ok 2 - failing test | |
232 | > # false | |
233 | > not ok 3 - pretend we have a known breakage # TODO known breakage | |
234 | > # still have 1 known breakage(s) | |
235 | > # failed 1 among remaining 2 test(s) | |
236 | > 1..3 | |
237 | EOF | |
238 | " | |
239 | ||
240 | test_expect_success 'pretend we have a mix of all possible results' " | |
77172420 | 241 | run_sub_test_lib_test_err \ |
5ebf89e8 AS |
242 | mixed-results2 'mixed results #2' <<-\\EOF && |
243 | test_expect_success 'passing test' 'true' | |
244 | test_expect_success 'passing test' 'true' | |
245 | test_expect_success 'passing test' 'true' | |
246 | test_expect_success 'passing test' 'true' | |
247 | test_expect_success 'failing test' 'false' | |
248 | test_expect_success 'failing test' 'false' | |
249 | test_expect_success 'failing test' 'false' | |
250 | test_expect_failure 'pretend we have a known breakage' 'false' | |
251 | test_expect_failure 'pretend we have a known breakage' 'false' | |
252 | test_expect_failure 'pretend we have fixed a known breakage' 'true' | |
253 | test_done | |
254 | EOF | |
255 | check_sub_test_lib_test mixed-results2 <<-\\EOF | |
256 | > ok 1 - passing test | |
257 | > ok 2 - passing test | |
258 | > ok 3 - passing test | |
259 | > ok 4 - passing test | |
260 | > not ok 5 - failing test | |
261 | > # false | |
262 | > not ok 6 - failing test | |
263 | > # false | |
264 | > not ok 7 - failing test | |
265 | > # false | |
266 | > not ok 8 - pretend we have a known breakage # TODO known breakage | |
267 | > not ok 9 - pretend we have a known breakage # TODO known breakage | |
b73d9a23 AS |
268 | > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished |
269 | > # 1 known breakage(s) vanished; please update test(s) | |
5ebf89e8 | 270 | > # still have 2 known breakage(s) |
b73d9a23 | 271 | > # failed 3 among remaining 7 test(s) |
5ebf89e8 AS |
272 | > 1..10 |
273 | EOF | |
274 | " | |
275 | ||
6cdccfce | 276 | test_expect_success C_LOCALE_OUTPUT 'test --verbose' ' |
77172420 | 277 | run_sub_test_lib_test_err \ |
96f3ccc2 | 278 | t1234-verbose "test verbose" --verbose <<-\EOF && |
517cd55f TR |
279 | test_expect_success "passing test" true |
280 | test_expect_success "test with output" "echo foo" | |
281 | test_expect_success "failing test" false | |
282 | test_done | |
283 | EOF | |
96f3ccc2 SG |
284 | mv t1234-verbose/out t1234-verbose/out+ && |
285 | grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out && | |
286 | check_sub_test_lib_test t1234-verbose <<-\EOF | |
ffe1afe6 | 287 | > expecting success of 1234.1 '\''passing test'\'': true |
517cd55f TR |
288 | > ok 1 - passing test |
289 | > Z | |
ffe1afe6 | 290 | > expecting success of 1234.2 '\''test with output'\'': echo foo |
517cd55f | 291 | > foo |
517cd55f TR |
292 | > ok 2 - test with output |
293 | > Z | |
ffe1afe6 | 294 | > expecting success of 1234.3 '\''failing test'\'': false |
517cd55f TR |
295 | > not ok 3 - failing test |
296 | > # false | |
297 | > Z | |
298 | > # failed 1 among 3 test(s) | |
299 | > 1..3 | |
300 | EOF | |
301 | ' | |
302 | ||
ff09af3f | 303 | test_expect_success 'test --verbose-only' ' |
77172420 | 304 | run_sub_test_lib_test_err \ |
96f3ccc2 | 305 | t2345-verbose-only-2 "test verbose-only=2" \ |
ff09af3f TR |
306 | --verbose-only=2 <<-\EOF && |
307 | test_expect_success "passing test" true | |
308 | test_expect_success "test with output" "echo foo" | |
309 | test_expect_success "failing test" false | |
310 | test_done | |
311 | EOF | |
96f3ccc2 | 312 | check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF |
ff09af3f TR |
313 | > ok 1 - passing test |
314 | > Z | |
ffe1afe6 | 315 | > expecting success of 2345.2 '\''test with output'\'': echo foo |
ff09af3f | 316 | > foo |
ff09af3f TR |
317 | > ok 2 - test with output |
318 | > Z | |
319 | > not ok 3 - failing test | |
320 | > # false | |
321 | > # failed 1 among 3 test(s) | |
322 | > 1..3 | |
323 | EOF | |
324 | ' | |
325 | ||
ef2ac68d | 326 | test_expect_success 'GIT_SKIP_TESTS' " |
7e28c16f RJ |
327 | ( |
328 | GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS && | |
ef2ac68d | 329 | run_sub_test_lib_test git-skip-tests-basic \ |
7e28c16f RJ |
330 | 'GIT_SKIP_TESTS' <<-\\EOF && |
331 | for i in 1 2 3 | |
332 | do | |
333 | test_expect_success \"passing test #\$i\" 'true' | |
334 | done | |
335 | test_done | |
336 | EOF | |
337 | check_sub_test_lib_test git-skip-tests-basic <<-\\EOF | |
338 | > ok 1 - passing test #1 | |
339 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
340 | > ok 3 - passing test #3 | |
341 | > # passed all 3 test(s) | |
342 | > 1..3 | |
343 | EOF | |
344 | ) | |
ef2ac68d IB |
345 | " |
346 | ||
347 | test_expect_success 'GIT_SKIP_TESTS several tests' " | |
7e28c16f RJ |
348 | ( |
349 | GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS && | |
ef2ac68d | 350 | run_sub_test_lib_test git-skip-tests-several \ |
7e28c16f RJ |
351 | 'GIT_SKIP_TESTS several tests' <<-\\EOF && |
352 | for i in 1 2 3 4 5 6 | |
353 | do | |
354 | test_expect_success \"passing test #\$i\" 'true' | |
355 | done | |
356 | test_done | |
357 | EOF | |
358 | check_sub_test_lib_test git-skip-tests-several <<-\\EOF | |
359 | > ok 1 - passing test #1 | |
360 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
361 | > ok 3 - passing test #3 | |
362 | > ok 4 - passing test #4 | |
363 | > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) | |
364 | > ok 6 - passing test #6 | |
365 | > # passed all 6 test(s) | |
366 | > 1..6 | |
367 | EOF | |
368 | ) | |
ef2ac68d IB |
369 | " |
370 | ||
371 | test_expect_success 'GIT_SKIP_TESTS sh pattern' " | |
7e28c16f RJ |
372 | ( |
373 | GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS && | |
ef2ac68d | 374 | run_sub_test_lib_test git-skip-tests-sh-pattern \ |
7e28c16f RJ |
375 | 'GIT_SKIP_TESTS sh pattern' <<-\\EOF && |
376 | for i in 1 2 3 4 5 6 | |
377 | do | |
378 | test_expect_success \"passing test #\$i\" 'true' | |
379 | done | |
380 | test_done | |
381 | EOF | |
382 | check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF | |
383 | > ok 1 - passing test #1 | |
384 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
385 | > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) | |
386 | > ok 4 # skip passing test #4 (GIT_SKIP_TESTS) | |
387 | > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) | |
388 | > ok 6 - passing test #6 | |
389 | > # passed all 6 test(s) | |
390 | > 1..6 | |
391 | EOF | |
392 | ) | |
ef2ac68d IB |
393 | " |
394 | ||
b05b4093 DL |
395 | test_expect_success 'GIT_SKIP_TESTS entire suite' " |
396 | ( | |
397 | GIT_SKIP_TESTS='git' && export GIT_SKIP_TESTS && | |
398 | run_sub_test_lib_test git-skip-tests-entire-suite \ | |
399 | 'GIT_SKIP_TESTS entire suite' <<-\\EOF && | |
400 | for i in 1 2 3 | |
401 | do | |
402 | test_expect_success \"passing test #\$i\" 'true' | |
403 | done | |
404 | test_done | |
405 | EOF | |
406 | check_sub_test_lib_test git-skip-tests-entire-suite <<-\\EOF | |
407 | > 1..0 # SKIP skip all tests in git | |
408 | EOF | |
409 | ) | |
410 | " | |
411 | ||
412 | test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' " | |
413 | ( | |
414 | GIT_SKIP_TESTS='notgit' && export GIT_SKIP_TESTS && | |
415 | run_sub_test_lib_test git-skip-tests-unmatched-suite \ | |
416 | 'GIT_SKIP_TESTS does not skip unmatched suite' <<-\\EOF && | |
417 | for i in 1 2 3 | |
418 | do | |
419 | test_expect_success \"passing test #\$i\" 'true' | |
420 | done | |
421 | test_done | |
422 | EOF | |
423 | check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\\EOF | |
424 | > ok 1 - passing test #1 | |
425 | > ok 2 - passing test #2 | |
426 | > ok 3 - passing test #3 | |
427 | > # passed all 3 test(s) | |
428 | > 1..3 | |
429 | EOF | |
430 | ) | |
431 | " | |
432 | ||
0445e6f0 IB |
433 | test_expect_success '--run basic' " |
434 | run_sub_test_lib_test run-basic \ | |
435 | '--run basic' --run='1 3 5' <<-\\EOF && | |
436 | for i in 1 2 3 4 5 6 | |
437 | do | |
438 | test_expect_success \"passing test #\$i\" 'true' | |
439 | done | |
440 | test_done | |
441 | EOF | |
442 | check_sub_test_lib_test run-basic <<-\\EOF | |
443 | > ok 1 - passing test #1 | |
444 | > ok 2 # skip passing test #2 (--run) | |
445 | > ok 3 - passing test #3 | |
446 | > ok 4 # skip passing test #4 (--run) | |
447 | > ok 5 - passing test #5 | |
448 | > ok 6 # skip passing test #6 (--run) | |
449 | > # passed all 6 test(s) | |
450 | > 1..6 | |
451 | EOF | |
452 | " | |
453 | ||
454 | test_expect_success '--run with a range' " | |
455 | run_sub_test_lib_test run-range \ | |
456 | '--run with a range' --run='1-3' <<-\\EOF && | |
457 | for i in 1 2 3 4 5 6 | |
458 | do | |
459 | test_expect_success \"passing test #\$i\" 'true' | |
460 | done | |
461 | test_done | |
462 | EOF | |
463 | check_sub_test_lib_test run-range <<-\\EOF | |
464 | > ok 1 - passing test #1 | |
465 | > ok 2 - passing test #2 | |
466 | > ok 3 - passing test #3 | |
467 | > ok 4 # skip passing test #4 (--run) | |
468 | > ok 5 # skip passing test #5 (--run) | |
469 | > ok 6 # skip passing test #6 (--run) | |
470 | > # passed all 6 test(s) | |
471 | > 1..6 | |
472 | EOF | |
473 | " | |
474 | ||
475 | test_expect_success '--run with two ranges' " | |
476 | run_sub_test_lib_test run-two-ranges \ | |
477 | '--run with two ranges' --run='1-2 5-6' <<-\\EOF && | |
478 | for i in 1 2 3 4 5 6 | |
479 | do | |
480 | test_expect_success \"passing test #\$i\" 'true' | |
481 | done | |
482 | test_done | |
483 | EOF | |
484 | check_sub_test_lib_test run-two-ranges <<-\\EOF | |
485 | > ok 1 - passing test #1 | |
486 | > ok 2 - passing test #2 | |
487 | > ok 3 # skip passing test #3 (--run) | |
488 | > ok 4 # skip passing test #4 (--run) | |
489 | > ok 5 - passing test #5 | |
490 | > ok 6 - passing test #6 | |
491 | > # passed all 6 test(s) | |
492 | > 1..6 | |
493 | EOF | |
494 | " | |
495 | ||
496 | test_expect_success '--run with a left open range' " | |
497 | run_sub_test_lib_test run-left-open-range \ | |
498 | '--run with a left open range' --run='-3' <<-\\EOF && | |
499 | for i in 1 2 3 4 5 6 | |
500 | do | |
501 | test_expect_success \"passing test #\$i\" 'true' | |
502 | done | |
503 | test_done | |
504 | EOF | |
505 | check_sub_test_lib_test run-left-open-range <<-\\EOF | |
506 | > ok 1 - passing test #1 | |
507 | > ok 2 - passing test #2 | |
508 | > ok 3 - passing test #3 | |
509 | > ok 4 # skip passing test #4 (--run) | |
510 | > ok 5 # skip passing test #5 (--run) | |
511 | > ok 6 # skip passing test #6 (--run) | |
512 | > # passed all 6 test(s) | |
513 | > 1..6 | |
514 | EOF | |
515 | " | |
516 | ||
517 | test_expect_success '--run with a right open range' " | |
518 | run_sub_test_lib_test run-right-open-range \ | |
519 | '--run with a right open range' --run='4-' <<-\\EOF && | |
520 | for i in 1 2 3 4 5 6 | |
521 | do | |
522 | test_expect_success \"passing test #\$i\" 'true' | |
523 | done | |
524 | test_done | |
525 | EOF | |
526 | check_sub_test_lib_test run-right-open-range <<-\\EOF | |
527 | > ok 1 # skip passing test #1 (--run) | |
528 | > ok 2 # skip passing test #2 (--run) | |
529 | > ok 3 # skip passing test #3 (--run) | |
530 | > ok 4 - passing test #4 | |
531 | > ok 5 - passing test #5 | |
532 | > ok 6 - passing test #6 | |
533 | > # passed all 6 test(s) | |
534 | > 1..6 | |
535 | EOF | |
536 | " | |
537 | ||
538 | test_expect_success '--run with basic negation' " | |
539 | run_sub_test_lib_test run-basic-neg \ | |
540 | '--run with basic negation' --run='"'!3'"' <<-\\EOF && | |
541 | for i in 1 2 3 4 5 6 | |
542 | do | |
543 | test_expect_success \"passing test #\$i\" 'true' | |
544 | done | |
545 | test_done | |
546 | EOF | |
547 | check_sub_test_lib_test run-basic-neg <<-\\EOF | |
548 | > ok 1 - passing test #1 | |
549 | > ok 2 - passing test #2 | |
550 | > ok 3 # skip passing test #3 (--run) | |
551 | > ok 4 - passing test #4 | |
552 | > ok 5 - passing test #5 | |
553 | > ok 6 - passing test #6 | |
554 | > # passed all 6 test(s) | |
555 | > 1..6 | |
556 | EOF | |
557 | " | |
558 | ||
559 | test_expect_success '--run with two negations' " | |
560 | run_sub_test_lib_test run-two-neg \ | |
561 | '--run with two negations' --run='"'!3 !6'"' <<-\\EOF && | |
562 | for i in 1 2 3 4 5 6 | |
563 | do | |
564 | test_expect_success \"passing test #\$i\" 'true' | |
565 | done | |
566 | test_done | |
567 | EOF | |
568 | check_sub_test_lib_test run-two-neg <<-\\EOF | |
569 | > ok 1 - passing test #1 | |
570 | > ok 2 - passing test #2 | |
571 | > ok 3 # skip passing test #3 (--run) | |
572 | > ok 4 - passing test #4 | |
573 | > ok 5 - passing test #5 | |
574 | > ok 6 # skip passing test #6 (--run) | |
575 | > # passed all 6 test(s) | |
576 | > 1..6 | |
577 | EOF | |
578 | " | |
579 | ||
580 | test_expect_success '--run a range and negation' " | |
581 | run_sub_test_lib_test run-range-and-neg \ | |
582 | '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF && | |
583 | for i in 1 2 3 4 5 6 | |
584 | do | |
585 | test_expect_success \"passing test #\$i\" 'true' | |
586 | done | |
587 | test_done | |
588 | EOF | |
589 | check_sub_test_lib_test run-range-and-neg <<-\\EOF | |
590 | > ok 1 - passing test #1 | |
591 | > ok 2 # skip passing test #2 (--run) | |
592 | > ok 3 - passing test #3 | |
593 | > ok 4 - passing test #4 | |
594 | > ok 5 # skip passing test #5 (--run) | |
595 | > ok 6 # skip passing test #6 (--run) | |
596 | > # passed all 6 test(s) | |
597 | > 1..6 | |
598 | EOF | |
599 | " | |
600 | ||
601 | test_expect_success '--run range negation' " | |
602 | run_sub_test_lib_test run-range-neg \ | |
603 | '--run range negation' --run='"'!1-3'"' <<-\\EOF && | |
604 | for i in 1 2 3 4 5 6 | |
605 | do | |
606 | test_expect_success \"passing test #\$i\" 'true' | |
607 | done | |
608 | test_done | |
609 | EOF | |
610 | check_sub_test_lib_test run-range-neg <<-\\EOF | |
611 | > ok 1 # skip passing test #1 (--run) | |
612 | > ok 2 # skip passing test #2 (--run) | |
613 | > ok 3 # skip passing test #3 (--run) | |
614 | > ok 4 - passing test #4 | |
615 | > ok 5 - passing test #5 | |
616 | > ok 6 - passing test #6 | |
617 | > # passed all 6 test(s) | |
618 | > 1..6 | |
619 | EOF | |
620 | " | |
621 | ||
622 | test_expect_success '--run include, exclude and include' " | |
623 | run_sub_test_lib_test run-inc-neg-inc \ | |
624 | '--run include, exclude and include' \ | |
625 | --run='"'1-5 !1-3 2'"' <<-\\EOF && | |
626 | for i in 1 2 3 4 5 6 | |
627 | do | |
628 | test_expect_success \"passing test #\$i\" 'true' | |
629 | done | |
630 | test_done | |
631 | EOF | |
632 | check_sub_test_lib_test run-inc-neg-inc <<-\\EOF | |
633 | > ok 1 # skip passing test #1 (--run) | |
634 | > ok 2 - passing test #2 | |
635 | > ok 3 # skip passing test #3 (--run) | |
636 | > ok 4 - passing test #4 | |
637 | > ok 5 - passing test #5 | |
638 | > ok 6 # skip passing test #6 (--run) | |
639 | > # passed all 6 test(s) | |
640 | > 1..6 | |
641 | EOF | |
642 | " | |
643 | ||
644 | test_expect_success '--run include, exclude and include, comma separated' " | |
645 | run_sub_test_lib_test run-inc-neg-inc-comma \ | |
646 | '--run include, exclude and include, comma separated' \ | |
647 | --run=1-5,\!1-3,2 <<-\\EOF && | |
648 | for i in 1 2 3 4 5 6 | |
649 | do | |
650 | test_expect_success \"passing test #\$i\" 'true' | |
651 | done | |
652 | test_done | |
653 | EOF | |
654 | check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF | |
655 | > ok 1 # skip passing test #1 (--run) | |
656 | > ok 2 - passing test #2 | |
657 | > ok 3 # skip passing test #3 (--run) | |
658 | > ok 4 - passing test #4 | |
659 | > ok 5 - passing test #5 | |
660 | > ok 6 # skip passing test #6 (--run) | |
661 | > # passed all 6 test(s) | |
662 | > 1..6 | |
663 | EOF | |
664 | " | |
665 | ||
666 | test_expect_success '--run exclude and include' " | |
667 | run_sub_test_lib_test run-neg-inc \ | |
668 | '--run exclude and include' \ | |
669 | --run='"'!3- 5'"' <<-\\EOF && | |
670 | for i in 1 2 3 4 5 6 | |
671 | do | |
672 | test_expect_success \"passing test #\$i\" 'true' | |
673 | done | |
674 | test_done | |
675 | EOF | |
676 | check_sub_test_lib_test run-neg-inc <<-\\EOF | |
677 | > ok 1 - passing test #1 | |
678 | > ok 2 - passing test #2 | |
679 | > ok 3 # skip passing test #3 (--run) | |
680 | > ok 4 # skip passing test #4 (--run) | |
681 | > ok 5 - passing test #5 | |
682 | > ok 6 # skip passing test #6 (--run) | |
683 | > # passed all 6 test(s) | |
684 | > 1..6 | |
685 | EOF | |
686 | " | |
687 | ||
688 | test_expect_success '--run empty selectors' " | |
689 | run_sub_test_lib_test run-empty-sel \ | |
690 | '--run empty selectors' \ | |
691 | --run='1,,3,,,5' <<-\\EOF && | |
692 | for i in 1 2 3 4 5 6 | |
693 | do | |
694 | test_expect_success \"passing test #\$i\" 'true' | |
695 | done | |
696 | test_done | |
697 | EOF | |
698 | check_sub_test_lib_test run-empty-sel <<-\\EOF | |
699 | > ok 1 - passing test #1 | |
700 | > ok 2 # skip passing test #2 (--run) | |
701 | > ok 3 - passing test #3 | |
702 | > ok 4 # skip passing test #4 (--run) | |
703 | > ok 5 - passing test #5 | |
704 | > ok 6 # skip passing test #6 (--run) | |
705 | > # passed all 6 test(s) | |
706 | > 1..6 | |
707 | EOF | |
708 | " | |
709 | ||
710 | test_expect_success '--run invalid range start' " | |
711 | run_sub_test_lib_test_err run-inv-range-start \ | |
712 | '--run invalid range start' \ | |
713 | --run='a-5' <<-\\EOF && | |
714 | test_expect_success \"passing test #1\" 'true' | |
715 | test_done | |
716 | EOF | |
717 | check_sub_test_lib_test_err run-inv-range-start \ | |
718 | <<-\\EOF_OUT 3<<-\\EOF_ERR | |
719 | > FATAL: Unexpected exit with code 1 | |
720 | EOF_OUT | |
721 | > error: --run: invalid non-numeric in range start: 'a-5' | |
722 | EOF_ERR | |
723 | " | |
724 | ||
725 | test_expect_success '--run invalid range end' " | |
726 | run_sub_test_lib_test_err run-inv-range-end \ | |
727 | '--run invalid range end' \ | |
728 | --run='1-z' <<-\\EOF && | |
729 | test_expect_success \"passing test #1\" 'true' | |
730 | test_done | |
731 | EOF | |
732 | check_sub_test_lib_test_err run-inv-range-end \ | |
733 | <<-\\EOF_OUT 3<<-\\EOF_ERR | |
734 | > FATAL: Unexpected exit with code 1 | |
735 | EOF_OUT | |
736 | > error: --run: invalid non-numeric in range end: '1-z' | |
737 | EOF_ERR | |
738 | " | |
739 | ||
740 | test_expect_success '--run invalid selector' " | |
741 | run_sub_test_lib_test_err run-inv-selector \ | |
742 | '--run invalid selector' \ | |
743 | --run='1?' <<-\\EOF && | |
744 | test_expect_success \"passing test #1\" 'true' | |
745 | test_done | |
746 | EOF | |
747 | check_sub_test_lib_test_err run-inv-selector \ | |
748 | <<-\\EOF_OUT 3<<-\\EOF_ERR | |
749 | > FATAL: Unexpected exit with code 1 | |
750 | EOF_OUT | |
751 | > error: --run: invalid non-numeric in test selector: '1?' | |
752 | EOF_ERR | |
753 | " | |
754 | ||
755 | ||
a7bb3940 JS |
756 | test_set_prereq HAVEIT |
757 | haveit=no | |
758 | test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' | |
1b5b2b64 SL |
759 | test_have_prereq HAVEIT && |
760 | haveit=yes | |
a7bb3940 JS |
761 | ' |
762 | donthaveit=yes | |
763 | test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' ' | |
1b5b2b64 | 764 | donthaveit=no |
a7bb3940 | 765 | ' |
c7400399 | 766 | if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit != yesyes |
a7bb3940 JS |
767 | then |
768 | say "bug in test framework: prerequisite tags do not work reliably" | |
93a57246 ÆAB |
769 | exit 1 |
770 | fi | |
771 | ||
772 | test_set_prereq HAVETHIS | |
773 | haveit=no | |
774 | test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' ' | |
1b5b2b64 SL |
775 | test_have_prereq HAVEIT && |
776 | test_have_prereq HAVETHIS && | |
777 | haveit=yes | |
93a57246 ÆAB |
778 | ' |
779 | donthaveit=yes | |
780 | test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' ' | |
1b5b2b64 | 781 | donthaveit=no |
93a57246 | 782 | ' |
ce60653e ÆAB |
783 | donthaveiteither=yes |
784 | test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' ' | |
1b5b2b64 | 785 | donthaveiteither=no |
ce60653e | 786 | ' |
c7400399 | 787 | if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit$donthaveiteither != yesyesyes |
93a57246 ÆAB |
788 | then |
789 | say "bug in test framework: multiple prerequisite tags do not work reliably" | |
a7bb3940 JS |
790 | exit 1 |
791 | fi | |
41ac414e | 792 | |
bdccd3c1 JK |
793 | test_lazy_prereq LAZY_TRUE true |
794 | havetrue=no | |
795 | test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' ' | |
796 | havetrue=yes | |
797 | ' | |
798 | donthavetrue=yes | |
799 | test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' ' | |
800 | donthavetrue=no | |
801 | ' | |
802 | ||
c7400399 | 803 | if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$havetrue$donthavetrue" != yesyes |
bdccd3c1 JK |
804 | then |
805 | say 'bug in test framework: lazy prerequisites do not work' | |
806 | exit 1 | |
807 | fi | |
808 | ||
809 | test_lazy_prereq LAZY_FALSE false | |
810 | nothavefalse=no | |
811 | test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' ' | |
812 | nothavefalse=yes | |
813 | ' | |
814 | havefalse=yes | |
815 | test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' ' | |
816 | havefalse=no | |
817 | ' | |
818 | ||
c7400399 | 819 | if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$nothavefalse$havefalse" != yesyes |
bdccd3c1 JK |
820 | then |
821 | say 'bug in test framework: negative lazy prerequisites do not work' | |
822 | exit 1 | |
823 | fi | |
824 | ||
b6b0afdc JN |
825 | clean=no |
826 | test_expect_success 'tests clean up after themselves' ' | |
1b5b2b64 | 827 | test_when_finished clean=yes |
b6b0afdc JN |
828 | ' |
829 | ||
c7400399 | 830 | if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes |
b6b0afdc | 831 | then |
892e6f7e | 832 | say "bug in test framework: basic cleanup command does not work reliably" |
b6b0afdc JN |
833 | exit 1 |
834 | fi | |
835 | ||
892e6f7e | 836 | test_expect_success 'tests clean up even on failures' " |
77172420 | 837 | run_sub_test_lib_test_err \ |
565b6fa8 | 838 | failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF && |
1b5b2b64 SL |
839 | test_expect_success 'tests clean up even after a failure' ' |
840 | touch clean-after-failure && | |
841 | test_when_finished rm clean-after-failure && | |
842 | (exit 1) | |
843 | ' | |
844 | test_expect_success 'failure to clean up causes the test to fail' ' | |
845 | test_when_finished \"(exit 2)\" | |
846 | ' | |
847 | test_done | |
1b5b2b64 | 848 | EOF |
565b6fa8 | 849 | check_sub_test_lib_test failing-cleanup <<-\\EOF |
5e5c006e | 850 | > not ok 1 - tests clean up even after a failure |
1b5b2b64 SL |
851 | > # Z |
852 | > # touch clean-after-failure && | |
853 | > # test_when_finished rm clean-after-failure && | |
854 | > # (exit 1) | |
855 | > # Z | |
5e5c006e | 856 | > not ok 2 - failure to clean up causes the test to fail |
1b5b2b64 SL |
857 | > # Z |
858 | > # test_when_finished \"(exit 2)\" | |
859 | > # Z | |
860 | > # failed 2 among 2 test(s) | |
861 | > 1..2 | |
862 | EOF | |
892e6f7e ÆAB |
863 | " |
864 | ||
900721e1 | 865 | test_expect_success 'test_atexit is run' " |
77172420 | 866 | run_sub_test_lib_test_err \ |
900721e1 JS |
867 | atexit-cleanup 'Run atexit commands' -i <<-\\EOF && |
868 | test_expect_success 'tests clean up even after a failure' ' | |
869 | > ../../clean-atexit && | |
870 | test_atexit rm ../../clean-atexit && | |
871 | > ../../also-clean-atexit && | |
872 | test_atexit rm ../../also-clean-atexit && | |
873 | > ../../dont-clean-atexit && | |
874 | (exit 1) | |
875 | ' | |
876 | test_done | |
877 | EOF | |
878 | test_path_is_file dont-clean-atexit && | |
879 | test_path_is_missing clean-atexit && | |
880 | test_path_is_missing also-clean-atexit | |
881 | " | |
882 | ||
2c02b110 | 883 | test_expect_success 'test_oid setup' ' |
884 | test_oid_init | |
885 | ' | |
886 | ||
887 | test_expect_success 'test_oid provides sane info by default' ' | |
888 | test_oid zero >actual && | |
889 | grep "^00*\$" actual && | |
890 | rawsz="$(test_oid rawsz)" && | |
891 | hexsz="$(test_oid hexsz)" && | |
892 | test "$hexsz" -eq $(wc -c <actual) && | |
893 | test $(( $rawsz * 2)) -eq "$hexsz" | |
894 | ' | |
895 | ||
896 | test_expect_success 'test_oid can look up data for SHA-1' ' | |
897 | test_when_finished "test_detect_hash" && | |
898 | test_set_hash sha1 && | |
899 | test_oid zero >actual && | |
900 | grep "^00*\$" actual && | |
901 | rawsz="$(test_oid rawsz)" && | |
902 | hexsz="$(test_oid hexsz)" && | |
903 | test $(wc -c <actual) -eq 40 && | |
904 | test "$rawsz" -eq 20 && | |
905 | test "$hexsz" -eq 40 | |
906 | ' | |
907 | ||
908 | test_expect_success 'test_oid can look up data for SHA-256' ' | |
909 | test_when_finished "test_detect_hash" && | |
910 | test_set_hash sha256 && | |
911 | test_oid zero >actual && | |
912 | grep "^00*\$" actual && | |
913 | rawsz="$(test_oid rawsz)" && | |
914 | hexsz="$(test_oid hexsz)" && | |
915 | test $(wc -c <actual) -eq 64 && | |
916 | test "$rawsz" -eq 32 && | |
917 | test "$hexsz" -eq 64 | |
918 | ' | |
919 | ||
43a2afee SG |
920 | test_expect_success 'test_bool_env' ' |
921 | ( | |
922 | sane_unset envvar && | |
923 | ||
924 | test_bool_env envvar true && | |
925 | ! test_bool_env envvar false && | |
926 | ||
927 | envvar= && | |
928 | export envvar && | |
929 | ! test_bool_env envvar true && | |
930 | ! test_bool_env envvar false && | |
931 | ||
932 | envvar=true && | |
933 | test_bool_env envvar true && | |
934 | test_bool_env envvar false && | |
935 | ||
936 | envvar=false && | |
937 | ! test_bool_env envvar true && | |
938 | ! test_bool_env envvar false && | |
939 | ||
940 | envvar=invalid && | |
941 | # When encountering an invalid bool value, test_bool_env | |
942 | # prints its error message to the original stderr of the | |
943 | # test script, hence the redirection of fd 7, and aborts | |
944 | # with "exit 1", hence the subshell. | |
945 | ! ( test_bool_env envvar true ) 7>err && | |
946 | grep "error: test_bool_env requires bool values" err && | |
947 | ||
948 | envvar=true && | |
949 | ! ( test_bool_env envvar invalid ) 7>err && | |
950 | grep "error: test_bool_env requires bool values" err | |
951 | ) | |
952 | ' | |
953 | ||
e1970ce4 JH |
954 | ################################################################ |
955 | # Basics of the basics | |
956 | ||
e483e144 | 957 | test_oid_cache <<\EOF |
958 | path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154 | |
959 | path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d | |
960 | ||
961 | path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01 | |
962 | path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363 | |
963 | ||
964 | path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7 | |
965 | path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f | |
966 | ||
967 | path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38 | |
968 | path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a | |
969 | ||
970 | path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe | |
971 | path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17 | |
972 | ||
973 | path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376 | |
974 | path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad | |
975 | ||
976 | path3s sha1:8599103969b43aff7e430efea79ca4636466794f | |
977 | path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0 | |
978 | ||
979 | path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3 | |
980 | path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1 | |
981 | ||
982 | subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f | |
983 | subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3 | |
984 | ||
985 | subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c | |
986 | subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10 | |
987 | ||
988 | subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2 | |
989 | subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7 | |
990 | ||
991 | root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b | |
992 | root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751 | |
993 | ||
994 | simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a | |
995 | simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5 | |
996 | EOF | |
997 | ||
e1970ce4 | 998 | # updating a new file without --add should fail. |
1b5b2b64 SL |
999 | test_expect_success 'git update-index without --add should fail adding' ' |
1000 | test_must_fail git update-index should-be-empty | |
41ac414e | 1001 | ' |
e1970ce4 JH |
1002 | |
1003 | # and with --add it should succeed, even if it is empty (it used to fail). | |
1b5b2b64 SL |
1004 | test_expect_success 'git update-index with --add should succeed' ' |
1005 | git update-index --add should-be-empty | |
1006 | ' | |
e1970ce4 | 1007 | |
1b5b2b64 SL |
1008 | test_expect_success 'writing tree out with git write-tree' ' |
1009 | tree=$(git write-tree) | |
1010 | ' | |
e1970ce4 JH |
1011 | |
1012 | # we know the shape and contents of the tree and know the object ID for it. | |
e483e144 | 1013 | test_expect_success 'validate object ID of a known tree' ' |
1014 | test "$tree" = "$(test_oid simpletree)" | |
1b5b2b64 | 1015 | ' |
e1970ce4 JH |
1016 | |
1017 | # Removing paths. | |
1b5b2b64 SL |
1018 | test_expect_success 'git update-index without --remove should fail removing' ' |
1019 | rm -f should-be-empty full-of-directories && | |
1020 | test_must_fail git update-index should-be-empty | |
41ac414e | 1021 | ' |
e1970ce4 | 1022 | |
1b5b2b64 SL |
1023 | test_expect_success 'git update-index with --remove should be able to remove' ' |
1024 | git update-index --remove should-be-empty | |
1025 | ' | |
e1970ce4 JH |
1026 | |
1027 | # Empty tree can be written with recent write-tree. | |
1b5b2b64 SL |
1028 | test_expect_success 'git write-tree should be able to write an empty tree' ' |
1029 | tree=$(git write-tree) | |
1030 | ' | |
e1970ce4 | 1031 | |
1b5b2b64 | 1032 | test_expect_success 'validate object ID of a known tree' ' |
f9e7d9f8 | 1033 | test "$tree" = $EMPTY_TREE |
1b5b2b64 | 1034 | ' |
e1970ce4 JH |
1035 | |
1036 | # Various types of objects | |
1b5b2b64 | 1037 | |
1b5b2b64 SL |
1038 | test_expect_success 'adding various types of objects with git update-index --add' ' |
1039 | mkdir path2 path3 path3/subp3 && | |
1040 | paths="path0 path2/file2 path3/file3 path3/subp3/file3" && | |
1041 | ( | |
1042 | for p in $paths | |
1043 | do | |
1044 | echo "hello $p" >$p || exit 1 | |
c723a76d | 1045 | test_ln_s_add "hello $p" ${p}sym || exit 1 |
1b5b2b64 SL |
1046 | done |
1047 | ) && | |
1048 | find path* ! -type d -print | xargs git update-index --add | |
1049 | ' | |
e1970ce4 JH |
1050 | |
1051 | # Show them and see that matches what we expect. | |
1b5b2b64 SL |
1052 | test_expect_success 'showing stage with git ls-files --stage' ' |
1053 | git ls-files --stage >current | |
1054 | ' | |
1055 | ||
e483e144 | 1056 | test_expect_success 'validate git ls-files output for a known tree' ' |
1057 | cat >expected <<-EOF && | |
1058 | 100644 $(test_oid path0f) 0 path0 | |
1059 | 120000 $(test_oid path0s) 0 path0sym | |
1060 | 100644 $(test_oid path2f) 0 path2/file2 | |
1061 | 120000 $(test_oid path2s) 0 path2/file2sym | |
1062 | 100644 $(test_oid path3f) 0 path3/file3 | |
1063 | 120000 $(test_oid path3s) 0 path3/file3sym | |
1064 | 100644 $(test_oid subp3f) 0 path3/subp3/file3 | |
1065 | 120000 $(test_oid subp3s) 0 path3/subp3/file3sym | |
1b5b2b64 SL |
1066 | EOF |
1067 | test_cmp expected current | |
1068 | ' | |
1069 | ||
1070 | test_expect_success 'writing tree out with git write-tree' ' | |
1071 | tree=$(git write-tree) | |
1072 | ' | |
1073 | ||
e483e144 | 1074 | test_expect_success 'validate object ID for a known tree' ' |
1075 | test "$tree" = "$(test_oid root)" | |
1b5b2b64 SL |
1076 | ' |
1077 | ||
1078 | test_expect_success 'showing tree with git ls-tree' ' | |
1079 | git ls-tree $tree >current | |
1080 | ' | |
1081 | ||
e483e144 | 1082 | test_expect_success 'git ls-tree output for a known tree' ' |
1083 | cat >expected <<-EOF && | |
1084 | 100644 blob $(test_oid path0f) path0 | |
1085 | 120000 blob $(test_oid path0s) path0sym | |
1086 | 040000 tree $(test_oid path2d) path2 | |
1087 | 040000 tree $(test_oid path3d) path3 | |
1b5b2b64 SL |
1088 | EOF |
1089 | test_cmp expected current | |
1090 | ' | |
e1970ce4 | 1091 | |
246cc52f JH |
1092 | # This changed in ls-tree pathspec change -- recursive does |
1093 | # not show tree nodes anymore. | |
1b5b2b64 SL |
1094 | test_expect_success 'showing tree with git ls-tree -r' ' |
1095 | git ls-tree -r $tree >current | |
1096 | ' | |
1097 | ||
e483e144 | 1098 | test_expect_success 'git ls-tree -r output for a known tree' ' |
1099 | cat >expected <<-EOF && | |
1100 | 100644 blob $(test_oid path0f) path0 | |
1101 | 120000 blob $(test_oid path0s) path0sym | |
1102 | 100644 blob $(test_oid path2f) path2/file2 | |
1103 | 120000 blob $(test_oid path2s) path2/file2sym | |
1104 | 100644 blob $(test_oid path3f) path3/file3 | |
1105 | 120000 blob $(test_oid path3s) path3/file3sym | |
1106 | 100644 blob $(test_oid subp3f) path3/subp3/file3 | |
1107 | 120000 blob $(test_oid subp3s) path3/subp3/file3sym | |
1b5b2b64 SL |
1108 | EOF |
1109 | test_cmp expected current | |
1110 | ' | |
e1970ce4 | 1111 | |
fdeb6bf5 | 1112 | # But with -r -t we can have both. |
1b5b2b64 SL |
1113 | test_expect_success 'showing tree with git ls-tree -r -t' ' |
1114 | git ls-tree -r -t $tree >current | |
1115 | ' | |
3d12d0cf | 1116 | |
e483e144 | 1117 | test_expect_success 'git ls-tree -r output for a known tree' ' |
1118 | cat >expected <<-EOF && | |
1119 | 100644 blob $(test_oid path0f) path0 | |
1120 | 120000 blob $(test_oid path0s) path0sym | |
1121 | 040000 tree $(test_oid path2d) path2 | |
1122 | 100644 blob $(test_oid path2f) path2/file2 | |
1123 | 120000 blob $(test_oid path2s) path2/file2sym | |
1124 | 040000 tree $(test_oid path3d) path3 | |
1125 | 100644 blob $(test_oid path3f) path3/file3 | |
1126 | 120000 blob $(test_oid path3s) path3/file3sym | |
1127 | 040000 tree $(test_oid subp3d) path3/subp3 | |
1128 | 100644 blob $(test_oid subp3f) path3/subp3/file3 | |
1129 | 120000 blob $(test_oid subp3s) path3/subp3/file3sym | |
1b5b2b64 SL |
1130 | EOF |
1131 | test_cmp expected current | |
1132 | ' | |
3d12d0cf | 1133 | |
1b5b2b64 SL |
1134 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' |
1135 | ptree=$(git write-tree --prefix=path3) | |
41ac414e | 1136 | ' |
3d12d0cf | 1137 | |
e483e144 | 1138 | test_expect_success 'validate object ID for a known tree' ' |
1139 | test "$ptree" = $(test_oid path3d) | |
1b5b2b64 SL |
1140 | ' |
1141 | ||
1142 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' | |
1143 | ptree=$(git write-tree --prefix=path3/subp3) | |
1144 | ' | |
1145 | ||
e483e144 | 1146 | test_expect_success 'validate object ID for a known tree' ' |
1147 | test "$ptree" = $(test_oid subp3d) | |
1b5b2b64 SL |
1148 | ' |
1149 | ||
1150 | test_expect_success 'put invalid objects into the index' ' | |
1151 | rm -f .git/index && | |
cdd1e17f | 1152 | suffix=$(echo $ZERO_OID | sed -e "s/^.//") && |
1153 | cat >badobjects <<-EOF && | |
1154 | 100644 blob $(test_oid 001) dir/file1 | |
1155 | 100644 blob $(test_oid 002) dir/file2 | |
1156 | 100644 blob $(test_oid 003) dir/file3 | |
1157 | 100644 blob $(test_oid 004) dir/file4 | |
1158 | 100644 blob $(test_oid 005) dir/file5 | |
1b5b2b64 SL |
1159 | EOF |
1160 | git update-index --index-info <badobjects | |
1161 | ' | |
1162 | ||
1163 | test_expect_success 'writing this tree without --missing-ok' ' | |
1164 | test_must_fail git write-tree | |
1165 | ' | |
1166 | ||
1167 | test_expect_success 'writing this tree with --missing-ok' ' | |
1168 | git write-tree --missing-ok | |
1169 | ' | |
3d12d0cf JS |
1170 | |
1171 | ||
e1970ce4 | 1172 | ################################################################ |
1b5b2b64 | 1173 | test_expect_success 'git read-tree followed by write-tree should be idempotent' ' |
99094a7a | 1174 | rm -f .git/index && |
1b5b2b64 SL |
1175 | git read-tree $tree && |
1176 | test -f .git/index && | |
1177 | newtree=$(git write-tree) && | |
1178 | test "$newtree" = "$tree" | |
1179 | ' | |
1180 | ||
e483e144 | 1181 | test_expect_success 'validate git diff-files output for a know cache/work tree state' ' |
1182 | cat >expected <<EOF && | |
1183 | :100644 100644 $(test_oid path0f) $ZERO_OID M path0 | |
1184 | :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym | |
1185 | :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2 | |
1186 | :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym | |
1187 | :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3 | |
1188 | :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym | |
1189 | :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3 | |
1190 | :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym | |
e1970ce4 | 1191 | EOF |
1b5b2b64 | 1192 | git diff-files >current && |
dcbaa0b3 | 1193 | test_cmp expected current |
1b5b2b64 | 1194 | ' |
e1970ce4 | 1195 | |
1b5b2b64 SL |
1196 | test_expect_success 'git update-index --refresh should succeed' ' |
1197 | git update-index --refresh | |
1198 | ' | |
e1970ce4 | 1199 | |
1b5b2b64 SL |
1200 | test_expect_success 'no diff after checkout and git update-index --refresh' ' |
1201 | git diff-files >current && | |
1202 | cmp -s current /dev/null | |
1203 | ' | |
e1970ce4 | 1204 | |
9af0b8db | 1205 | ################################################################ |
e483e144 | 1206 | P=$(test_oid root) |
1b5b2b64 | 1207 | |
e483e144 | 1208 | test_expect_success 'git commit-tree records the correct tree in a commit' ' |
1b5b2b64 SL |
1209 | commit0=$(echo NO | git commit-tree $P) && |
1210 | tree=$(git show --pretty=raw $commit0 | | |
1211 | sed -n -e "s/^tree //p" -e "/^author /q") && | |
1212 | test "z$tree" = "z$P" | |
1213 | ' | |
1214 | ||
e483e144 | 1215 | test_expect_success 'git commit-tree records the correct parent in a commit' ' |
1b5b2b64 SL |
1216 | commit1=$(echo NO | git commit-tree $P -p $commit0) && |
1217 | parent=$(git show --pretty=raw $commit1 | | |
1218 | sed -n -e "s/^parent //p" -e "/^author /q") && | |
1219 | test "z$commit0" = "z$parent" | |
1220 | ' | |
1221 | ||
e483e144 | 1222 | test_expect_success 'git commit-tree omits duplicated parent in a commit' ' |
1b5b2b64 SL |
1223 | commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && |
1224 | parent=$(git show --pretty=raw $commit2 | | |
1225 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
1226 | sort -u) && | |
1227 | test "z$commit0" = "z$parent" && | |
1228 | numparent=$(git show --pretty=raw $commit2 | | |
1229 | sed -n -e "s/^parent //p" -e "/^author /q" | | |
1230 | wc -l) && | |
1231 | test $numparent = 1 | |
1232 | ' | |
9af0b8db | 1233 | |
81a361be JH |
1234 | test_expect_success 'update-index D/F conflict' ' |
1235 | mv path0 tmp && | |
1236 | mv path2 path0 && | |
1237 | mv tmp path2 && | |
1238 | git update-index --add --replace path2 path0/file2 && | |
1239 | numpath0=$(git ls-files path0 | wc -l) && | |
1240 | test $numpath0 = 1 | |
1241 | ' | |
1242 | ||
7fec10b7 JH |
1243 | test_expect_success 'very long name in the index handled sanely' ' |
1244 | ||
1245 | a=a && # 1 | |
1246 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 | |
1247 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 | |
1248 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 | |
1249 | a=${a}q && | |
1250 | ||
1251 | >path4 && | |
1252 | git update-index --add path4 && | |
1253 | ( | |
1254 | git ls-files -s path4 | | |
1255 | sed -e "s/ .*/ /" | | |
75651fd7 | 1256 | tr -d "\012" && |
7fec10b7 JH |
1257 | echo "$a" |
1258 | ) | git update-index --index-info && | |
1259 | len=$(git ls-files "a*" | wc -c) && | |
1260 | test $len = 4098 | |
1261 | ' | |
1262 | ||
e1970ce4 | 1263 | test_done |