2 # Copyright 2017 Shivansh Rai
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. 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.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 atf_fail "setting umask failed"
39 atf_set "descr" "Verify that when creating a hard link to a " \
40 "symbolic link, '-L' option creates a hard" \
41 "link to the target of the symbolic link"
50 stat_A=$(stat -f %i A)
51 stat_C=$(stat -f %i C)
52 atf_check_equal "$stat_A" "$stat_C"
53 atf_check -o inline:'B: symbolic link to A\n' file B
59 atf_set "descr" "Verify that when creating a hard link to a " \
60 "symbolic link, '-P' option creates a hard " \
61 "link to the symbolic link itself"
70 stat_B=$(stat -f %i B)
71 stat_C=$(stat -f %i C)
72 atf_check_equal "$stat_B" "$stat_C"
78 atf_set "descr" "Verify that if the target file already exists, " \
79 "'-f' option unlinks it so that link may occur"
87 stat_A=$(stat -f %i A)
88 stat_B=$(stat -f %i B)
89 atf_check_equal "$stat_A" "$stat_B"
92 atf_test_case target_exists_hard
93 target_exists_hard_head()
95 atf_set "descr" "Verify whether creating a hard link fails if the " \
96 "target file already exists"
99 target_exists_hard_body()
102 atf_check -s exit:1 -e inline:'ln: B: File exists\n' \
106 atf_test_case target_exists_symbolic
107 target_exists_symbolic_head()
109 atf_set "descr" "Verify whether creating a symbolic link fails if " \
110 "the target file already exists"
113 target_exists_symbolic_body()
116 atf_check -s exit:1 -e inline:'ln: B: File exists\n' \
120 atf_test_case shf_flag_dir
121 shf_flag_dir_head() {
122 atf_set "descr" "Verify that if the target directory is a symbolic " \
123 "link, '-shf' option prevents following the link"
128 atf_check mkdir -m 0777 A B
130 atf_check ln -shf B C
131 atf_check -o inline:'C: symbolic link to B\n' file C
134 atf_test_case snf_flag_dir
135 snf_flag_dir_head() {
136 atf_set "descr" "Verify that if the target directory is a symbolic " \
137 "link, '-snf' option prevents following the link"
142 atf_check mkdir -m 0777 A B
144 atf_check ln -snf B C
145 atf_check -o inline:'C: symbolic link to B\n' file C
148 atf_test_case sf_flag
151 atf_set "descr" "Verify that if the target file already exists, " \
152 "'-sf' option unlinks it and creates a symbolic link " \
160 atf_check -o inline:'B: symbolic link to A\n' file B
166 atf_set "descr" "Verify that '-s' option creates a symbolic link"
174 atf_check -o inline:'B: symbolic link to A\n' file B
177 atf_test_case s_flag_broken
180 atf_set "descr" "Verify that if the source file does not exists, '-s' " \
181 "option creates a broken symbolic link to the source file"
187 atf_check -o inline:'B: broken symbolic link to A\n' file B
190 atf_test_case sw_flag
193 atf_set "descr" "Verify that '-sw' option produces a warning if the " \
194 "source of a symbolic link does not currently exist"
199 atf_check -s exit:0 -e inline:'ln: warning: A: No such file or directory\n' \
201 atf_check -o inline:'B: broken symbolic link to A\n' file B
204 atf_init_test_cases()
206 atf_add_test_case L_flag
207 atf_add_test_case P_flag
208 atf_add_test_case f_flag
209 atf_add_test_case target_exists_hard
210 atf_add_test_case target_exists_symbolic
211 atf_add_test_case shf_flag_dir
212 atf_add_test_case snf_flag_dir
213 atf_add_test_case sf_flag
214 atf_add_test_case s_flag
215 atf_add_test_case s_flag_broken
216 atf_add_test_case sw_flag