xref: /freebsd/usr.bin/stat/tests/readlink_test.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
121860bf9SEnji Cooper#
221860bf9SEnji Cooper# Copyright (c) 2017 Dell EMC
321860bf9SEnji Cooper# All rights reserved.
421860bf9SEnji Cooper#
521860bf9SEnji Cooper# Redistribution and use in source and binary forms, with or without
621860bf9SEnji Cooper# modification, are permitted provided that the following conditions
721860bf9SEnji Cooper# are met:
821860bf9SEnji Cooper# 1. Redistributions of source code must retain the above copyright
921860bf9SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1021860bf9SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1121860bf9SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1221860bf9SEnji Cooper#    documentation and/or other materials provided with the distribution.
1321860bf9SEnji Cooper#
1421860bf9SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1521860bf9SEnji Cooper# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1621860bf9SEnji Cooper# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1721860bf9SEnji Cooper# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1821860bf9SEnji Cooper# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1921860bf9SEnji Cooper# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2021860bf9SEnji Cooper# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2121860bf9SEnji Cooper# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2221860bf9SEnji Cooper# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2321860bf9SEnji Cooper# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2421860bf9SEnji Cooper# SUCH DAMAGE.
2521860bf9SEnji Cooper#
2621860bf9SEnji Cooper
27*0e73b834SKyle Evansatf_test_case basic
2821860bf9SEnji Cooperbasic_head()
2921860bf9SEnji Cooper{
3021860bf9SEnji Cooper	atf_set	"descr" "Verify that calling readlink without any flags " \
3121860bf9SEnji Cooper			"prints out the symlink target for a file"
3221860bf9SEnji Cooper}
3321860bf9SEnji Cooperbasic_body()
3421860bf9SEnji Cooper{
3521860bf9SEnji Cooper	atf_check ln -s foo bar
3621860bf9SEnji Cooper	atf_check -o inline:'foo\n' readlink bar
3721860bf9SEnji Cooper}
3821860bf9SEnji Cooper
3921860bf9SEnji Cooperatf_test_case f_flag
4021860bf9SEnji Cooperf_flag_head()
4121860bf9SEnji Cooper{
4221860bf9SEnji Cooper	atf_set	"descr" "Verify that calling readlink with -f will not emit " \
4321860bf9SEnji Cooper			"an error message/exit with a non-zero code"
4421860bf9SEnji Cooper}
4521860bf9SEnji Cooperf_flag_body()
4621860bf9SEnji Cooper{
4721860bf9SEnji Cooper	atf_check touch A.file
4821860bf9SEnji Cooper	atf_check ln -s nonexistent A.link
4921860bf9SEnji Cooper	atf_check -o inline:"nonexistent\n" \
5021860bf9SEnji Cooper	    -s exit:1 readlink A.file A.link
5121860bf9SEnji Cooper	atf_check -o inline:"$(realpath A.file)\n$PWD/nonexistent\n" \
5221860bf9SEnji Cooper	    -s exit:1 readlink -f A.file A.link
5321860bf9SEnji Cooper}
5421860bf9SEnji Cooper
5521860bf9SEnji Cooperatf_test_case n_flag
5621860bf9SEnji Coopern_flag_head()
5721860bf9SEnji Cooper{
5821860bf9SEnji Cooper}
5921860bf9SEnji Coopern_flag_body()
6021860bf9SEnji Cooper{
6121860bf9SEnji Cooper	atf_check ln -s nonexistent.A A
6221860bf9SEnji Cooper	atf_check ln -s nonexistent.B B
6321860bf9SEnji Cooper	atf_check -o 'inline:nonexistent.A\nnonexistent.B\n' readlink A B
6421860bf9SEnji Cooper	atf_check -o 'inline:nonexistent.Anonexistent.B' readlink -n A B
6521860bf9SEnji Cooper}
6621860bf9SEnji Cooper
6721860bf9SEnji Cooperatf_init_test_cases()
6821860bf9SEnji Cooper{
6921860bf9SEnji Cooper	atf_add_test_case basic
7021860bf9SEnji Cooper	atf_add_test_case f_flag
7121860bf9SEnji Cooper	atf_add_test_case n_flag
7221860bf9SEnji Cooper}
73