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 "-type l -a -type d -o -type p" \ 22 "find dir -type l -a -type d -o -type p" "dir/fifo\n" "" "" 23 testing "-type l -type d -o -type p" "find dir -type l -type d -o -type p" \ 24 "dir/fifo\n" "" "" 25 testing "-type l -o -type d -a -type p" \ 26 "find dir -type l -o -type d -a -type p" "dir/link\n" "" "" 27 testing "-type l -o -type d -type p" "find dir -type l -o -type d -type p" \ 28 "dir/link\n" "" "" 29 testing "-type l ( -type d -o -type l )" \ 30 "find dir -type l \( -type d -o -type l \)" "dir/link\n" "" "" 31 testing "extra parentheses" \ 32 "find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \ 33 "dir/link\n" "" "" 34 testing "( -type p -o -type d ) -type p" \ 35 "find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" "" 36 testing "-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 "-type f -a -print" \ 43 "find dir -type f -a -print" "dir/file\n" "" "" 44 testing "-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 "-type f -user -exec" \ 54 "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" "" 55 testing "-type l -newer -exec" \ 56 "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" "" 57 testing "-perm (exact success)" \ 58 "find perm -type f -perm 0444" "perm/all-read-only\n" "" "" 59 testing "-perm (exact failure)" \ 60 "find perm -type f -perm 0400" "" "" "" 61 testing "-perm (min success)" \ 62 "find perm -type f -perm -0400" "perm/all-read-only\n" "" "" 63 testing "-perm (min failure)" \ 64 "find perm -type f -perm -0600" "" "" "" 65 testing "-perm (any success)" \ 66 "find perm -type f -perm -0444" "perm/all-read-only\n" "" "" 67 testing "-perm (any failure)" \ 68 "find perm -type f -perm -0222" "" "" "" 69 70 # Still fails 71 72 testing "unterminated -exec {}" \ 73 "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" "" 74 testing "-exec {} +" \ 75 "find dir -type f -exec ls {} +" "dir/file\n" "" "" 76 77 # `find . -iname` was segfaulting 78 testing "-name file" \ 79 "find dir -name file" "dir/file\n" "" "" 80 testing "-name FILE" \ 81 "find dir -name FILE" "" "" "" 82 83 testing "-iname file" \ 84 "find dir -iname FILE" "dir/file\n" "" "" 85 testing "-iname FILE" \ 86 "find dir -iname FILE" "dir/file\n" "" "" 87 88 89 testing "-name (no arguments)" \ 90 "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" "" 91 testing "-iname (no arguments)" \ 92 "find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" "" 93 94 testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \ 95 "dir/file\n" "" "" 96 97 rm -rf dir 98