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_dir="$(mktemp -d -p /tmp/)"
  29 find_exit=0
  30 
  31 testfind()
  32 {
  33         exp=$1
  34         shift
  35         cmd="$@"
  36 
  37         echo "TEST: $cmd"
  38 
  39         out=$(eval $cmd | tr '\n' ',')
  40 
  41         [[ "$exp" = "$out" ]] || {
  42                 echo "TEST FAILED: $cmd" >&2
  43                 echo "expected: $exp" >&2
  44                 echo "got: $out" >&2
  45                 find_exit=1
  46         }
  47 }
  48 
  49 mkdir -p $find_dir/1
  50 mkdir -p $find_dir/.2
  51 touch $find_dir/.2/1
  52 touch $find_dir/.2/c
  53 
  54 testfind "$find_dir/1,$find_dir/.2/1," \
  55     $find_prog $find_dir -name \"1\"
  56 testfind "$find_dir/1,$find_dir/.2/1," \
  57     $find_prog $find_dir -path \"*1\"
  58 
  59 cd $find_dir
  60 
  61 testfind "" $find_prog . -name \"*2\"
  62 testfind "./.2," $find_prog_xpg4 . -name \"*2\"
  63 testfind "./.2," $find_prog . -name \".*2\"
  64 testfind "./.2," $find_prog_xpg4 . -name \".*2\"
  65 testfind "./1,./.2/1," $find_prog . -path \"*1\"
  66 testfind "./.2," $find_prog . -path \"*2\"
  67 testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\"
  68 
  69 cd -
  70 rm -rf $find_dir
  71 
  72 exit $find_exit