Start the 2.46 cycle
[git.git] / t / t0066-dir-iterator.sh
blob7d0a0da8c01b8b69a9d9ca607c55145d96e59ad1
1 #!/bin/sh
3 test_description='Test the dir-iterator functionality'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 mkdir -p dir &&
10 mkdir -p dir/a/b/c/ &&
11 >dir/b &&
12 >dir/c &&
13 mkdir -p dir/d/e/d/ &&
14 >dir/a/b/c/d &&
15 >dir/a/e &&
16 >dir/d/e/d/a &&
18 mkdir -p dir2/a/b/c/ &&
19 >dir2/a/b/c/d
22 test_expect_success 'dir-iterator should iterate through all files' '
23 cat >expected-iteration-sorted-output <<-EOF &&
24 [d] (a) [a] ./dir/a
25 [d] (a/b) [b] ./dir/a/b
26 [d] (a/b/c) [c] ./dir/a/b/c
27 [d] (d) [d] ./dir/d
28 [d] (d/e) [e] ./dir/d/e
29 [d] (d/e/d) [d] ./dir/d/e/d
30 [f] (a/b/c/d) [d] ./dir/a/b/c/d
31 [f] (a/e) [e] ./dir/a/e
32 [f] (b) [b] ./dir/b
33 [f] (c) [c] ./dir/c
34 [f] (d/e/d/a) [a] ./dir/d/e/d/a
35 EOF
37 test-tool dir-iterator ./dir >out &&
38 sort out >./actual-iteration-sorted-output &&
40 test_cmp expected-iteration-sorted-output actual-iteration-sorted-output
43 test_expect_success 'dir-iterator should list files in the correct order' '
44 cat >expected-pre-order-output <<-EOF &&
45 [d] (a) [a] ./dir2/a
46 [d] (a/b) [b] ./dir2/a/b
47 [d] (a/b/c) [c] ./dir2/a/b/c
48 [f] (a/b/c/d) [d] ./dir2/a/b/c/d
49 EOF
51 test-tool dir-iterator ./dir2 >actual-pre-order-output &&
53 test_cmp expected-pre-order-output actual-pre-order-output
56 test_expect_success 'begin should fail upon inexistent paths' '
57 test_must_fail test-tool dir-iterator ./inexistent-path \
58 >actual-inexistent-path-output &&
59 echo "dir_iterator_begin failure: ENOENT" >expected-inexistent-path-output &&
60 test_cmp expected-inexistent-path-output actual-inexistent-path-output
63 test_expect_success 'begin should fail upon non directory paths' '
64 test_must_fail test-tool dir-iterator ./dir/b >actual-non-dir-output &&
65 echo "dir_iterator_begin failure: ENOTDIR" >expected-non-dir-output &&
66 test_cmp expected-non-dir-output actual-non-dir-output
69 test_expect_success POSIXPERM,SANITY 'advance should not fail on errors by default' '
70 cat >expected-no-permissions-output <<-EOF &&
71 [d] (a) [a] ./dir3/a
72 EOF
74 mkdir -p dir3/a &&
75 >dir3/a/b &&
76 chmod 0 dir3/a &&
78 test-tool dir-iterator ./dir3 >actual-no-permissions-output &&
79 test_cmp expected-no-permissions-output actual-no-permissions-output &&
80 chmod 755 dir3/a &&
81 rm -rf dir3
84 test_expect_success POSIXPERM,SANITY 'advance should fail on errors, w/ pedantic flag' '
85 cat >expected-no-permissions-pedantic-output <<-EOF &&
86 [d] (a) [a] ./dir3/a
87 dir_iterator_advance failure
88 EOF
90 mkdir -p dir3/a &&
91 >dir3/a/b &&
92 chmod 0 dir3/a &&
94 test_must_fail test-tool dir-iterator --pedantic ./dir3 \
95 >actual-no-permissions-pedantic-output &&
96 test_cmp expected-no-permissions-pedantic-output \
97 actual-no-permissions-pedantic-output &&
98 chmod 755 dir3/a &&
99 rm -rf dir3
102 test_expect_success SYMLINKS 'setup dirs with symlinks' '
103 mkdir -p dir4/a &&
104 mkdir -p dir4/b/c &&
105 >dir4/a/d &&
106 ln -s d dir4/a/e &&
107 ln -s ../b dir4/a/f &&
109 ln -s dir4 dir5
112 test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default' '
113 cat >expected-no-follow-sorted-output <<-EOF &&
114 [d] (a) [a] ./dir4/a
115 [d] (b) [b] ./dir4/b
116 [d] (b/c) [c] ./dir4/b/c
117 [f] (a/d) [d] ./dir4/a/d
118 [s] (a/e) [e] ./dir4/a/e
119 [s] (a/f) [f] ./dir4/a/f
122 test-tool dir-iterator ./dir4 >out &&
123 sort out >actual-no-follow-sorted-output &&
125 test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output
128 test_expect_success SYMLINKS 'dir-iterator does not resolve top-level symlinks' '
129 test_must_fail test-tool dir-iterator ./dir5 >out &&
131 grep "ENOTDIR" out
134 test_done