3 test_description
='Test the dir-iterator functionality'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' '
10 mkdir -p dir/a/b/c/ &&
13 mkdir -p dir/d/e/d/ &&
18 mkdir -p dir2/a/b/c/ &&
22 test_expect_success
'dir-iterator should iterate through all files' '
23 cat >expected-iteration-sorted-output <<-EOF &&
25 [d] (a/b) [b] ./dir/a/b
26 [d] (a/b/c) [c] ./dir/a/b/c
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
34 [f] (d/e/d/a) [a] ./dir/d/e/d/a
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 &&
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
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 &&
78 test-tool dir-iterator ./dir3 >actual-no-permissions-output &&
79 test_cmp expected-no-permissions-output actual-no-permissions-output &&
84 test_expect_success POSIXPERM
,SANITY
'advance should fail on errors, w/ pedantic flag' '
85 cat >expected-no-permissions-pedantic-output <<-EOF &&
87 dir_iterator_advance failure
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 &&
102 test_expect_success SYMLINKS
'setup dirs with symlinks' '
107 ln -s ../b dir4/a/f &&
112 test_expect_success SYMLINKS
'dir-iterator should not follow symlinks by default' '
113 cat >expected-no-follow-sorted-output <<-EOF &&
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 &&