push: refactor refspec_append_mapped() for subsequent leak-fix
[git.git] / t / t0066-dir-iterator.sh
blob63a1a45cd30921a5b0d28b8d5db63046aeb2a3ea
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 mkdir -p dir5/a/b &&
110 mkdir -p dir5/a/c &&
111 ln -s ../c dir5/a/b/d &&
112 ln -s ../ dir5/a/b/e &&
113 ln -s ../../ dir5/a/b/f
116 test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default' '
117 cat >expected-no-follow-sorted-output <<-EOF &&
118 [d] (a) [a] ./dir4/a
119 [d] (b) [b] ./dir4/b
120 [d] (b/c) [c] ./dir4/b/c
121 [f] (a/d) [d] ./dir4/a/d
122 [s] (a/e) [e] ./dir4/a/e
123 [s] (a/f) [f] ./dir4/a/f
126 test-tool dir-iterator ./dir4 >out &&
127 sort out >actual-no-follow-sorted-output &&
129 test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output
132 test_expect_success SYMLINKS 'dir-iterator should follow symlinks w/ follow flag' '
133 cat >expected-follow-sorted-output <<-EOF &&
134 [d] (a) [a] ./dir4/a
135 [d] (a/f) [f] ./dir4/a/f
136 [d] (a/f/c) [c] ./dir4/a/f/c
137 [d] (b) [b] ./dir4/b
138 [d] (b/c) [c] ./dir4/b/c
139 [f] (a/d) [d] ./dir4/a/d
140 [f] (a/e) [e] ./dir4/a/e
143 test-tool dir-iterator --follow-symlinks ./dir4 >out &&
144 sort out >actual-follow-sorted-output &&
146 test_cmp expected-follow-sorted-output actual-follow-sorted-output
149 test_done