xref: /freebsd/usr.bin/find/tests/find_test.sh (revision abd87254)
1#
2# Copyright 2017, Conrad Meyer <cem@FreeBSD.org>.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8# * Redistributions of source code must retain the above copyright
9#   notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright
11#   notice, this list of conditions and the following disclaimer in the
12#   documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25#
26#
27
28atf_test_case find_newer_link
29find_newer_link_head()
30{
31	atf_set "descr" "Verifies that -newer correctly uses a symlink, " \
32	    "rather than its target, for comparison"
33}
34find_newer_link_body()
35{
36	atf_check -s exit:0 mkdir test
37	atf_check -s exit:0 ln -s file1 test/link
38	atf_check -s exit:0 touch -d 2017-12-31T10:00:00Z -h test/link
39	atf_check -s exit:0 touch -d 2017-12-31T11:00:00Z test/file2
40	atf_check -s exit:0 touch -d 2017-12-31T12:00:00Z test/file1
41
42	# find(1) should evaluate 'link' as a symlink rather than its target
43	# (with -P / without -L flags).  Since link was created first, the
44	# other two files should be newer.
45	echo -e "test\ntest/file1\ntest/file2" > expout
46	atf_check -s exit:0 -o save:output find test -newer test/link
47	atf_check -s exit:0 -o file:expout sort < output
48}
49
50atf_test_case find_samefile_link
51find_samefile_link_head()
52{
53	atf_set "descr" "Verifies that -samefile correctly uses a symlink, " \
54	    "rather than its target, for comparison"
55}
56find_samefile_link_body()
57{
58	atf_check -s exit:0 mkdir test
59	atf_check -s exit:0 touch test/file3
60	atf_check -s exit:0 ln -s file3 test/link2
61
62	# find(1) should evaluate 'link' as a symlink rather than its target
63	# (with -P / without -L flags).
64	atf_check -s exit:0 -o "inline:test/link2\n" find test -samefile test/link2
65}
66
67atf_init_test_cases()
68{
69	atf_add_test_case find_newer_link
70	atf_add_test_case find_samefile_link
71}
72