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 "-type f -user -exec" \ 56 "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" "" 57testing "-type l -newer -exec" \ 58 "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" "" 59testing "-exec true \\; -print" \ 60 "find dir/file -exec true \\; -print" "dir/file\n" "" "" 61testing "-exec false \\; -print" \ 62 "find dir/file -exec false \\; -print" "" "" "" 63testing "-perm (exact success)" \ 64 "find perm -type f -perm 0444" "perm/all-read-only\n" "" "" 65testing "-perm (exact failure)" \ 66 "find perm -type f -perm 0400" "" "" "" 67testing "-perm (min success)" \ 68 "find perm -type f -perm -0400" "perm/all-read-only\n" "" "" 69testing "-perm (min failure)" \ 70 "find perm -type f -perm -0600" "" "" "" 71testing "-perm (any success)" \ 72 "find perm -type f -perm -0444" "perm/all-read-only\n" "" "" 73testing "-perm (any failure)" \ 74 "find perm -type f -perm -0222" "" "" "" 75 76# Still fails 77 78testing "unterminated -exec {}" \ 79 "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" "" 80testing "-exec {} +" \ 81 "find dir -type f -exec ls {} +" "dir/file\n" "" "" 82 83# `find . -iname` was segfaulting 84testing "-name file" \ 85 "find dir -name file" "dir/file\n" "" "" 86testing "-name FILE" \ 87 "find dir -name FILE" "" "" "" 88 89testing "-iname file" \ 90 "find dir -iname FILE" "dir/file\n" "" "" 91testing "-iname FILE" \ 92 "find dir -iname FILE" "dir/file\n" "" "" 93 94 95testing "-name (no arguments)" \ 96 "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" "" 97testing "-iname (no arguments)" \ 98 "find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" "" 99 100testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \ 101 "dir/file\n" "" "" 102 103testing "-path glob" \ 104 "find dir -path 'dir*e'" "dir/file\n" "" "" 105testing "-wholename glob" \ 106 "find dir -wholename 'dir*e'" "dir/file\n" "" "" 107testing "-ipath glob" \ 108 "find dir -ipath 'dIr*E'" "dir/file\n" "" "" 109testing "-iwholename glob" \ 110 "find dir -iwholename 'dIr*E'" "dir/file\n" "" "" 111 112rm -rf dir 113