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