summaryrefslogtreecommitdiff
path: root/usr/src/test/util-tests/tests/find/findtest.ksh
blob: 9e321fb664cd19c6e0fa16f3bb71ff2b7724b460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2020 Joyent, Inc.
#

#
# Clearly, grossly incomplete.
#

export LC_ALL=C.UTF-8

set -o pipefail
unalias -a

find_prog=/usr/bin/find
find_prog_xpg4=/usr/xpg4/bin/find
find_dir="$(mktemp -d -p /tmp/)"
find_exit=0

testfind()
{
	exp=$1
	shift
	cmd="$@"

	echo "TEST: $cmd"

	out=$(eval $cmd | tr '\n' ',')

	[[ "$exp" = "$out" ]] || {
		echo "TEST FAILED: $cmd" >&2
		echo "expected: $exp" >&2
		echo "got: $out" >&2
		find_exit=1
	}
}

mkdir -p $find_dir/1
mkdir -p $find_dir/.2
touch $find_dir/.2/1
touch $find_dir/.2/c

testfind "$find_dir/1,$find_dir/.2/1," \
    $find_prog $find_dir -name \"1\"
testfind "$find_dir/1,$find_dir/.2/1," \
    $find_prog $find_dir -path \"*1\"

cd $find_dir

testfind "" $find_prog . -name \"*2\"
testfind "./.2," $find_prog_xpg4 . -name \"*2\"
testfind "./.2," $find_prog . -name \".*2\"
testfind "./.2," $find_prog_xpg4 . -name \".*2\"
testfind "./1,./.2/1," $find_prog . -path \"*1\"
testfind "./.2," $find_prog . -path \"*2\"
testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\"

cd -
rm -rf $find_dir

exit $find_exit