xref: /illumos-gate/usr/src/test/util-tests/tests/find/findtest.ksh (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
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
21export LC_ALL=C.UTF-8
22
23set -o pipefail
24unalias -a
25
26find_prog=/usr/bin/find
27find_prog_xpg4=/usr/xpg4/bin/find
28find_exit=0
29
30# make sure we don't end in 1 or 2, which breaks the tests
31find_dir=/tmp/findtest.$$.dir
32
33mkdir $find_dir
34
35testfind()
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
53mkdir -p $find_dir/1
54mkdir -p $find_dir/.2
55touch $find_dir/.2/1
56touch $find_dir/.2/c
57
58testfind "$find_dir/1,$find_dir/.2/1," \
59    $find_prog $find_dir -name \"1\"
60testfind "$find_dir/1,$find_dir/.2/1," \
61    $find_prog $find_dir -path \"*1\"
62
63cd $find_dir
64
65testfind "" $find_prog . -name \"*2\"
66testfind "./.2," $find_prog_xpg4 . -name \"*2\"
67testfind "./.2," $find_prog . -name \".*2\"
68testfind "./.2," $find_prog_xpg4 . -name \".*2\"
69testfind "./1,./.2/1," $find_prog . -path \"*1\"
70testfind "./.2," $find_prog . -path \"*2\"
71testfind "./.2,./.2/1,./.2/c," $find_prog . -path \"*2*\"
72
73cd -
74rm -rf $find_dir
75
76exit $find_exit
77