xref: /freebsd/usr.bin/find/tests/find_test.sh (revision e796cc77c586c2955b2f3940dbf4991b31e8d289)
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# $FreeBSD$
27#
28
29atf_test_case find_newer_link
30find_newer_link_head()
31{
32	atf_set "descr" "Verifies that -newer correctly uses a symlink, " \
33	    "rather than its target, for comparison"
34}
35find_newer_link_body()
36{
37	atf_check -s exit:0 mkdir test
38	atf_check -s exit:0 ln -s file1 test/link
39	atf_check -s exit:0 touch -d 2017-12-31T10:00:00Z -h test/link
40	atf_check -s exit:0 touch -d 2017-12-31T11:00:00Z test/file2
41	atf_check -s exit:0 touch -d 2017-12-31T12:00:00Z test/file1
42
43	# find(1) should evaluate 'link' as a symlink rather than its target
44	# (with -P / without -L flags).  Since link was created first, the
45	# other two files should be newer.
46	echo -e "test\ntest/file1\ntest/file2" > expout
47	atf_check -s exit:0 -o save:output find test -newer test/link
48	atf_check -s exit:0 -o file:expout sort < output
49}
50
51atf_test_case find_samefile_link
52find_samefile_link_head()
53{
54	atf_set "descr" "Verifies that -samefile correctly uses a symlink, " \
55	    "rather than its target, for comparison"
56}
57find_samefile_link_body()
58{
59	atf_check -s exit:0 mkdir test
60	atf_check -s exit:0 touch test/file3
61	atf_check -s exit:0 ln -s file3 test/link2
62
63	# find(1) should evaluate 'link' as a symlink rather than its target
64	# (with -P / without -L flags).
65	atf_check -s exit:0 -o "inline:test/link2\n" find test -samefile test/link2
66}
67
68atf_init_test_cases()
69{
70	atf_add_test_case find_newer_link
71	atf_add_test_case find_samefile_link
72}
73