• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5mkdir dir
6cd dir
7touch file
8mkfifo fifo
9# fs timestamp granularity isn't always enough for -newer to tell, so wait
10sleep .1
11ln -s fifo link
12cd ..
13touch b
14
15mkdir perm
16touch perm/all-read-only
17chmod a=r perm/all-read-only
18
19#testing "name" "command" "result" "infile" "stdin"
20
21# Testing operators
22
23testing "-type l -a -type d -o -type p" \
24	"find dir -type l -a -type d -o -type p" "dir/fifo\n" "" ""
25testing "-type l -type d -o -type p" "find dir -type l -type d -o -type p" \
26	"dir/fifo\n" "" ""
27testing "-type l -o -type d -a -type p" \
28	"find dir -type l -o -type d -a -type p" "dir/link\n" "" ""
29testing "-type l -o -type d -type p" "find dir -type l -o -type d -type p" \
30	"dir/link\n" "" ""
31testing "-type l ( -type d -o -type l )" \
32	"find dir -type l \( -type d -o -type l \)" "dir/link\n" "" ""
33testing "extra parentheses" \
34	"find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \
35	"dir/link\n" "" ""
36testing "( -type p -o -type d ) -type p" \
37	"find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" ""
38testing "-type l -o -type d -type p -o -type f" \
39	"find dir -type l -o -type d -type p -o -type f | sort" \
40	"dir/file\ndir/link\n" "" ""
41
42# Testing short-circuit evaluations
43
44testing "-type f -a -print" \
45	"find dir -type f -a -print" "dir/file\n" "" ""
46testing "-print -o -print" \
47	"find dir -type f -a \( -print -o -print \)" "dir/file\n" "" ""
48
49# these were erroring or segfaulting:
50# find -type f -user nobody -exec : \;
51# find -type f -user nobody -exec : -exec : \;
52
53# Testing previous failures
54
55testing " " "cd perm; find" ".\n./all-read-only\n" "" ""
56testing "-type f -user -exec" \
57  "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" ""
58testing "-type l -newer -exec" \
59  "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" ""
60testing "-exec true \\; -print" \
61  "find dir/file -exec true \\; -print" "dir/file\n" "" ""
62testing "-exec false \\; -print" \
63  "find dir/file -exec false \\; -print" "" "" ""
64testing "-perm (exact success)" \
65  "find perm -type f -perm 0444" "perm/all-read-only\n" "" ""
66testing "-perm (exact failure)" \
67  "find perm -type f -perm 0400" "" "" ""
68testing "-perm (min success)" \
69  "find perm -type f -perm -0400" "perm/all-read-only\n" "" ""
70testing "-perm (min failure)" \
71  "find perm -type f -perm -0600" "" "" ""
72testing "-perm (any success)" \
73  "find perm -type f -perm -0444" "perm/all-read-only\n" "" ""
74testing "-perm (any failure)" \
75  "find perm -type f -perm -0222" "" "" ""
76
77testing "unterminated -exec {}" \
78  "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" ""
79testing "-exec {} +" \
80  "find dir -type f -exec ls {} +" "dir/file\n" "" ""
81
82# `find . -iname` was segfaulting
83testing "-name file" "find dir -name file" "dir/file\n" "" ""
84testing "-name FILE" "find dir -name FILE" "" "" ""
85
86testing "-iname file" "find dir -iname FILE" "dir/file\n" "" ""
87testing "-iname FILE" "find dir -iname FILE" "dir/file\n" "" ""
88
89
90testing "-name (no arguments)" \
91  "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" ""
92testing "-iname (no arguments)" \
93  "find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" ""
94
95testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \
96  "dir/file\n" "" ""
97
98testing "-path glob" "find dir -path 'dir*e'" "dir/file\n" "" ""
99testing "-wholename glob" "find dir -wholename 'dir*e'" "dir/file\n" "" ""
100testing "-ipath glob" "find dir -ipath 'dIr*E'" "dir/file\n" "" ""
101testing "-iwholename glob" "find dir -iwholename 'dIr*E'" "dir/file\n" "" ""
102testing "-printf" "find dir -name file -printf '%f %p %P %s'" \
103  "file dir/file file 0" "" ""
104testing "-printf .N" "find dir -name file -printf %.2f" "fi" "" ""
105# findutils find supports C letter escapes and \0 octal, but not \x or \u.
106testing "-printf escapes" \
107  "find dir -name file -printf '\0 \007 \t \079' | xxd -p" \
108  "0020072009200739\n" "" ""
109# findutils find treats \c as "no more output from this -printf", not "no more
110# output from find".
111testing "-printf \\c escape" "find dir -name f* -printf 'x\cy'" "xx" "" ""
112
113# No error message for a dangling link.
114ln -s does-not-exist dir/dangler
115testing "-L dangling symlink silent" \
116  "LANG=C find -L dir -name file 2>&1" "dir/file\n" "" ""
117rm -f dir/dangler
118
119# An error for a symlink loop.
120ln -s looper dir/looper
121testing "-L symlink loop noisy" \
122  "LANG=C find -L dir -name file 2>err ; grep -q dir/looper err || echo missing error" \
123  "dir/file\n" "" ""
124rm -f dir/looper err
125
126testing "-false" "find dir -false" "" "" ""
127testing "-true" "find dir/file -true" "dir/file\n" "" ""
128
129testing "missing root error" \
130  "LANG=C find -L dir/missing-root 2>err ; grep -q dir/missing-root err || echo missing error" \
131  "" "" ""
132
133testing "-path match root" "find dir/f* -path dir/file" "dir/file\n" "" ""
134testing "-name match root" "find dir/f* -name file" "dir/file\n" "" ""
135
136rm -rf dir
137