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