OSDN Git Service

split pgrep/pkill tests.
[android-x86/external-toybox.git] / tests / find.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 mkdir dir
6 cd dir
7 touch file
8 mkfifo fifo
9 ln -s fifo link
10 cd ..
11 touch b
12
13 mkdir perm
14 touch perm/all-read-only
15 chmod a=r perm/all-read-only
16
17 #testing "name" "command" "result" "infile" "stdin"
18
19 # Testing operators
20
21 testing "find -type l -a -type d -o -type p" \
22         "find dir -type l -a -type d -o -type p" "dir/fifo\n" "" ""
23 testing "find -type l -type d -o -type p" "find dir -type l -type d -o -type p" \
24         "dir/fifo\n" "" ""
25 testing "find -type l -o -type d -a -type p" \
26         "find dir -type l -o -type d -a -type p" "dir/link\n" "" ""
27 testing "find -type l -o -type d -type p" "find dir -type l -o -type d -type p" \
28         "dir/link\n" "" ""
29 testing "find -type l ( -type d -o -type l )" \
30         "find dir -type l \( -type d -o -type l \)" "dir/link\n" "" ""
31 testing "find extra parentheses" \
32         "find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \
33         "dir/link\n" "" ""
34 testing "find ( -type p -o -type d ) -type p" \
35         "find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" ""
36 testing "find -type l -o -type d -type p -o -type f" \
37         "find dir -type l -o -type d -type p -o -type f | sort" \
38         "dir/file\ndir/link\n" "" ""
39
40 # Testing short-circuit evaluations
41
42 testing "find -type f -a -print" \
43         "find dir -type f -a -print" "dir/file\n" "" ""
44 testing "find -print -o -print" \
45         "find dir -type f -a \( -print -o -print \)" "dir/file\n" "" ""
46
47 # these were erroring or segfaulting:
48 # find -type f -user nobody -exec : \;
49 # find -type f -user nobody -exec : -exec : \;
50
51 # Testing previous failures
52
53 testing "find -type f -user -exec" \
54   "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" ""
55 testing "find -type l -newer -exec" \
56   "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" ""
57 testing "find -perm (exact success)" \
58   "find perm -type f -perm 0444" "perm/all-read-only\n" "" ""
59 testing "find -perm (exact failure)" \
60   "find perm -type f -perm 0400" "" "" ""
61 testing "find -perm (min success)" \
62   "find perm -type f -perm -0400" "perm/all-read-only\n" "" ""
63 testing "find -perm (min failure)" \
64   "find perm -type f -perm -0600" "" "" ""
65 testing "find -perm (any success)" \
66   "find perm -type f -perm -0444" "perm/all-read-only\n" "" ""
67 testing "find -perm (any failure)" \
68   "find perm -type f -perm -0222" "" "" ""
69
70 # Still fails
71
72 testing "find unterminated -exec {}" \
73   "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" ""
74 testing "find -exec {} +" \
75   "find dir -type f -exec ls {} +" "dir/file\n" "" ""
76
77 # `find . -iname` was segfaulting
78 testing "find -name file" \
79   "find dir -name file" "dir/file\n" "" ""
80 testing "find -name FILE" \
81   "find dir -name FILE" "" "" ""
82
83 testing "find -iname file" \
84   "find dir -iname FILE" "dir/file\n" "" ""
85 testing "find -iname FILE" \
86   "find dir -iname FILE" "dir/file\n" "" ""
87
88
89 testing "find -name (no arguments)" \
90   "find dir -name 2>&1" "find: '-name' needs 1 arg\n" "" ""
91 testing "find -iname (no arguments)" \
92   "find dir -iname 2>&1" "find: '-iname' needs 1 arg\n" "" ""
93 rm -rf dir