1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5mkdir dir 6cd dir 7touch file 8mkfifo fifo 9ln -s fifo link 10cd .. 11touch b 12 13mkdir perm 14touch perm/all-read-only 15chmod a=r perm/all-read-only 16 17#testing "name" "command" "result" "infile" "stdin" 18 19# Testing operators 20 21testing "-type l -a -type d -o -type p" \ 22 "find dir -type l -a -type d -o -type p" "dir/fifo\n" "" "" 23testing "-type l -type d -o -type p" "find dir -type l -type d -o -type p" \ 24 "dir/fifo\n" "" "" 25testing "-type l -o -type d -a -type p" \ 26 "find dir -type l -o -type d -a -type p" "dir/link\n" "" "" 27testing "-type l -o -type d -type p" "find dir -type l -o -type d -type p" \ 28 "dir/link\n" "" "" 29testing "-type l ( -type d -o -type l )" \ 30 "find dir -type l \( -type d -o -type l \)" "dir/link\n" "" "" 31testing "extra parentheses" \ 32 "find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \ 33 "dir/link\n" "" "" 34testing "( -type p -o -type d ) -type p" \ 35 "find dir \( -type p -o -type d \) -type p" "dir/fifo\n" "" "" 36testing "-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 42testing "-type f -a -print" \ 43 "find dir -type f -a -print" "dir/file\n" "" "" 44testing "-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 53testing "-type f -user -exec" \ 54 "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" "" 55testing "-type l -newer -exec" \ 56 "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" "" 57testing "-perm (exact success)" \ 58 "find perm -type f -perm 0444" "perm/all-read-only\n" "" "" 59testing "-perm (exact failure)" \ 60 "find perm -type f -perm 0400" "" "" "" 61testing "-perm (min success)" \ 62 "find perm -type f -perm -0400" "perm/all-read-only\n" "" "" 63testing "-perm (min failure)" \ 64 "find perm -type f -perm -0600" "" "" "" 65testing "-perm (any success)" \ 66 "find perm -type f -perm -0444" "perm/all-read-only\n" "" "" 67testing "-perm (any failure)" \ 68 "find perm -type f -perm -0222" "" "" "" 69 70# Still fails 71 72testing "unterminated -exec {}" \ 73 "find dir -type f -exec ls {} 2>/dev/null || echo bad" "bad\n" "" "" 74testing "-exec {} +" \ 75 "find dir -type f -exec ls {} +" "dir/file\n" "" "" 76 77# `find . -iname` was segfaulting 78testing "-name file" \ 79 "find dir -name file" "dir/file\n" "" "" 80testing "-name FILE" \ 81 "find dir -name FILE" "" "" "" 82 83testing "-iname file" \ 84 "find dir -iname FILE" "dir/file\n" "" "" 85testing "-iname FILE" \ 86 "find dir -iname FILE" "dir/file\n" "" "" 87 88 89testing "-name (no arguments)" \ 90 "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" "" 91testing "-iname (no arguments)" \ 92 "find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" "" 93 94testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \ 95 "dir/file\n" "" "" 96 97rm -rf dir 98