midx: honor the MIDX_PROGRESS flag in midx_repack
[git.git] / t / t0066-dir-iterator.sh
blob92910e4e6c13ce381dddefcf197dea26a07efd88
1 #!/bin/sh
3 test_description='Test the dir-iterator functionality'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 mkdir -p dir &&
9 mkdir -p dir/a/b/c/ &&
10 >dir/b &&
11 >dir/c &&
12 mkdir -p dir/d/e/d/ &&
13 >dir/a/b/c/d &&
14 >dir/a/e &&
15 >dir/d/e/d/a &&
17 mkdir -p dir2/a/b/c/ &&
18 >dir2/a/b/c/d
21 test_expect_success 'dir-iterator should iterate through all files' '
22 cat >expected-iteration-sorted-output <<-EOF &&
23 [d] (a) [a] ./dir/a
24 [d] (a/b) [b] ./dir/a/b
25 [d] (a/b/c) [c] ./dir/a/b/c
26 [d] (d) [d] ./dir/d
27 [d] (d/e) [e] ./dir/d/e
28 [d] (d/e/d) [d] ./dir/d/e/d
29 [f] (a/b/c/d) [d] ./dir/a/b/c/d
30 [f] (a/e) [e] ./dir/a/e
31 [f] (b) [b] ./dir/b
32 [f] (c) [c] ./dir/c
33 [f] (d/e/d/a) [a] ./dir/d/e/d/a
34 EOF
36 test-tool dir-iterator ./dir >out &&
37 sort out >./actual-iteration-sorted-output &&
39 test_cmp expected-iteration-sorted-output actual-iteration-sorted-output
42 test_expect_success 'dir-iterator should list files in the correct order' '
43 cat >expected-pre-order-output <<-EOF &&
44 [d] (a) [a] ./dir2/a
45 [d] (a/b) [b] ./dir2/a/b
46 [d] (a/b/c) [c] ./dir2/a/b/c
47 [f] (a/b/c/d) [d] ./dir2/a/b/c/d
48 EOF
50 test-tool dir-iterator ./dir2 >actual-pre-order-output &&
52 test_cmp expected-pre-order-output actual-pre-order-output
55 test_expect_success 'begin should fail upon inexistent paths' '
56 test_must_fail test-tool dir-iterator ./inexistent-path \
57 >actual-inexistent-path-output &&
58 echo "dir_iterator_begin failure: ENOENT" >expected-inexistent-path-output &&
59 test_cmp expected-inexistent-path-output actual-inexistent-path-output
62 test_expect_success 'begin should fail upon non directory paths' '
63 test_must_fail test-tool dir-iterator ./dir/b >actual-non-dir-output &&
64 echo "dir_iterator_begin failure: ENOTDIR" >expected-non-dir-output &&
65 test_cmp expected-non-dir-output actual-non-dir-output
68 test_expect_success POSIXPERM,SANITY 'advance should not fail on errors by default' '
69 cat >expected-no-permissions-output <<-EOF &&
70 [d] (a) [a] ./dir3/a
71 EOF
73 mkdir -p dir3/a &&
74 >dir3/a/b &&
75 chmod 0 dir3/a &&
77 test-tool dir-iterator ./dir3 >actual-no-permissions-output &&
78 test_cmp expected-no-permissions-output actual-no-permissions-output &&
79 chmod 755 dir3/a &&
80 rm -rf dir3
83 test_expect_success POSIXPERM,SANITY 'advance should fail on errors, w/ pedantic flag' '
84 cat >expected-no-permissions-pedantic-output <<-EOF &&
85 [d] (a) [a] ./dir3/a
86 dir_iterator_advance failure
87 EOF
89 mkdir -p dir3/a &&
90 >dir3/a/b &&
91 chmod 0 dir3/a &&
93 test_must_fail test-tool dir-iterator --pedantic ./dir3 \
94 >actual-no-permissions-pedantic-output &&
95 test_cmp expected-no-permissions-pedantic-output \
96 actual-no-permissions-pedantic-output &&
97 chmod 755 dir3/a &&
98 rm -rf dir3
101 test_expect_success SYMLINKS 'setup dirs with symlinks' '
102 mkdir -p dir4/a &&
103 mkdir -p dir4/b/c &&
104 >dir4/a/d &&
105 ln -s d dir4/a/e &&
106 ln -s ../b dir4/a/f &&
108 mkdir -p dir5/a/b &&
109 mkdir -p dir5/a/c &&
110 ln -s ../c dir5/a/b/d &&
111 ln -s ../ dir5/a/b/e &&
112 ln -s ../../ dir5/a/b/f
115 test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default' '
116 cat >expected-no-follow-sorted-output <<-EOF &&
117 [d] (a) [a] ./dir4/a
118 [d] (b) [b] ./dir4/b
119 [d] (b/c) [c] ./dir4/b/c
120 [f] (a/d) [d] ./dir4/a/d
121 [s] (a/e) [e] ./dir4/a/e
122 [s] (a/f) [f] ./dir4/a/f
125 test-tool dir-iterator ./dir4 >out &&
126 sort out >actual-no-follow-sorted-output &&
128 test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output
131 test_expect_success SYMLINKS 'dir-iterator should follow symlinks w/ follow flag' '
132 cat >expected-follow-sorted-output <<-EOF &&
133 [d] (a) [a] ./dir4/a
134 [d] (a/f) [f] ./dir4/a/f
135 [d] (a/f/c) [c] ./dir4/a/f/c
136 [d] (b) [b] ./dir4/b
137 [d] (b/c) [c] ./dir4/b/c
138 [f] (a/d) [d] ./dir4/a/d
139 [f] (a/e) [e] ./dir4/a/e
142 test-tool dir-iterator --follow-symlinks ./dir4 >out &&
143 sort out >actual-follow-sorted-output &&
145 test_cmp expected-follow-sorted-output actual-follow-sorted-output
148 test_done