Commit | Line | Data |
---|---|---|
150791ad DF |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test the dir-iterator functionality' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
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 && | |
16 | ||
17 | mkdir -p dir2/a/b/c/ && | |
18 | >dir2/a/b/c/d | |
19 | ' | |
20 | ||
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 | |
35 | ||
36 | test-tool dir-iterator ./dir >out && | |
37 | sort out >./actual-iteration-sorted-output && | |
38 | ||
39 | test_cmp expected-iteration-sorted-output actual-iteration-sorted-output | |
40 | ' | |
41 | ||
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 | |
49 | ||
50 | test-tool dir-iterator ./dir2 >actual-pre-order-output && | |
51 | ||
52 | test_cmp expected-pre-order-output actual-pre-order-output | |
53 | ' | |
54 | ||
3012397e MT |
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: 2" >expected-inexistent-path-output && | |
59 | test_cmp expected-inexistent-path-output actual-inexistent-path-output | |
60 | ' | |
61 | ||
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: 20" >expected-non-dir-output && | |
65 | test_cmp expected-non-dir-output actual-non-dir-output | |
66 | ' | |
67 | ||
150791ad | 68 | test_done |