]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bin/ls/tests/ls_tests.sh
Start adding tests for bin/ls
[FreeBSD/FreeBSD.git] / bin / ls / tests / ls_tests.sh
1 #
2 # Copyright 2015 EMC Corp.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 #   notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 #   notice, this list of conditions and the following disclaimer in the
13 #   documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # $FreeBSD$
28 #
29
30 create_test_inputs()
31 {
32         ATF_TMPDIR=$(pwd)
33
34         # XXX: need to nest this because of how kyua creates $TMPDIR; otherwise
35         # it will run into EPERM issues later
36         TEST_INPUTS_DIR="${ATF_TMPDIR}/test/inputs"
37
38         atf_check -e empty -s exit:0 mkdir -m 0777 -p $TEST_INPUTS_DIR
39         cd $TEST_INPUTS_DIR
40         atf_check -e empty -s exit:0 mkdir -m 0755 -p a/b
41         atf_check -e empty -s exit:0 ln -s a/b c
42         atf_check -e empty -s exit:0 touch d
43         atf_check -e empty -s exit:0 ln d e
44         atf_check -e empty -s exit:0 touch .f
45         atf_check -e empty -s exit:0 mkdir .g
46         atf_check -e empty -s exit:0 mkfifo h
47 }
48
49 atf_test_case A_flag
50 A_flag_head()
51 {
52         atf_set "require.user" "unprivileged"
53 }
54
55 A_flag_body()
56 {
57         create_test_inputs
58
59         WITH_A=$PWD/../with_A.out
60         WITHOUT_A=$PWD/../without_A.out
61
62         atf_check -e empty -o save:$WITH_A -s exit:0 ls -A
63         atf_check -e empty -o save:$WITHOUT_A -s exit:0 ls
64
65         echo "-A usage"
66         cat $WITH_A
67         echo "No -A usage"
68         cat $WITHOUT_A
69
70         for dot_path in '\.f' '\.g'; do
71                 atf_check -e empty -o not-empty -s exit:0 grep "${dot_path}" \
72                     $WITH_A
73                 atf_check -e empty -o empty -s not-exit:0 grep "${dot_path}" \
74                     $WITHOUT_A
75         done
76 }
77
78 atf_test_case A_flag_implied_when_root
79 A_flag_implied_when_root_head()
80 {
81         atf_set "descr" "Verify that -A is implied for root"
82         atf_set "require.user" "root"
83 }
84
85 A_flag_implied_when_root_body()
86 {
87         create_test_inputs
88
89         WITH_EXPLICIT=$PWD/../with_explicit_A.out
90         WITH_IMPLIED=$PWD/../with_implied_A.out
91
92         atf_check -e empty -o save:$WITH_EXPLICIT -s exit:0 ls -A
93         atf_check -e empty -o save:$WITH_IMPLIED -s exit:0 ls
94
95         echo "Explicit -A usage"
96         cat $WITH_EXPLICIT
97         echo "Implicit -A usage"
98         cat $WITH_IMPLIED
99
100         atf_check_equal "$(cat $WITH_EXPLICIT)" "$(cat $WITH_IMPLIED)"
101 }
102
103 atf_init_test_cases()
104 {
105
106         atf_add_test_case A_flag
107         atf_add_test_case A_flag_implied_when_root
108 }