1 #!/bin/ksh 2 # 3 # This file and its contents are supplied under the terms of the 4 # Common Development and Distribution License ("CDDL"), version 1.0. 5 # You may only use this file in accordance with the terms of version 6 # 1.0 of the CDDL. 7 # 8 # A full copy of the text of the CDDL should have accompanied this 9 # source. A copy of the CDDL is also available via the Internet at 10 # http://www.illumos.org/license/CDDL. 11 # 12 13 # 14 # Copyright 2020 Joyent, Inc. 15 # 16 17 # 18 # Clearly, grossly incomplete. 19 # 20 21 export LC_ALL=C.UTF-8 22 23 set -o pipefail 24 unalias -a 25 26 find_prog=/usr/bin/find 27 find_prog_xpg4=/usr/xpg4/bin/find 28 find_exit=0 29 30 # make sure we don't end in 1 or 2, which breaks the tests 31 find_dir=/tmp/findtest.$$.dir 32 33 mkdir $find_dir 34 35 testfind() 36 { 37 exp=$1 38 shift 39 cmd="$@" 40 41 echo "TEST: $cmd" 42 43 out=$(eval $cmd | tr '\n' ',') 44 45 [[ "$exp" = "$out" ]] || { 46 echo "TEST FAILED: $cmd" >&2 47 echo "expected: $exp" >&2 48 echo "got: $out" >&2 49 find_exit=1 50 } 51 } 52 53 mkdir -p $find_dir/1 54 mkdir -p $find_dir/.2 55 touch $find_dir/.2/1 56 touch $find_dir/.2/c 57 58 testfind "$find_dir/1,$find_dir/.2/1," \ 59 $find_prog $find_dir -name \"1\" 60 testfind "$find_dir/1,$find_dir/.2/1," \ 61 $find_prog $find_dir -path \"*1\" 62 63 cd $find_dir 64 65 testfind "" $find_prog . -name \"*2\" 66 testfind "./.2," $find_prog_xpg4 . -name \"*2\" 67 testfind "./.2," $find_prog . -name \".*2\" 68 testfind "./.2," $find_prog_xpg4 . -name \".*2\" 69 testfind "./1,./.2/1," $find_prog . -path \"*1\" 70 testfind "./.2," $find_prog . -path \"*2\" 71 testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\" 72 73 cd - 74 rm -rf $find_dir 75 76 exit $find_exit