Page MenuHomeFreeBSD

D11084.id29301.diff
No OneTemporary

D11084.id29301.diff

Index: bin/ln/Makefile
===================================================================
--- bin/ln/Makefile
+++ bin/ln/Makefile
@@ -1,6 +1,8 @@
# @(#)Makefile 8.2 (Berkeley) 5/31/93
# $FreeBSD$
+.include <src.opts.mk>
+
PACKAGE=runtime
PROG= ln
MAN= ln.1 symlink.7
@@ -8,4 +10,8 @@
LINKS= ${BINDIR}/ln ${BINDIR}/link
MLINKS= ln.1 link.1
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
Index: bin/ln/tests/Makefile
===================================================================
--- /dev/null
+++ bin/ln/tests/Makefile
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+ATF_TESTS_SH+= ln_test
+
+.include <bsd.test.mk>
Index: bin/ln/tests/ln_test.sh
===================================================================
--- /dev/null
+++ bin/ln/tests/ln_test.sh
@@ -0,0 +1,179 @@
+#
+# Copyright 2017 Shivansh Rai
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+set_umask()
+{
+ atf_check -e empty -s exit:0 umask 022
+}
+
+atf_test_case L_flag
+L_flag_head()
+{
+ atf_set "descr" "Verify that when creating a hard link to a " \
+ "symbolic link, '-L' option creates a hard" \
+ "link to the target of the symbolic link"
+}
+
+L_flag_body()
+{
+ set_umask
+ atf_check touch A
+ atf_check ln -s A B
+ atf_check ln -L B C
+ atf_check -o inline:'100644\n120755\n100644\n' stat -f '%p' A B C
+}
+
+atf_test_case P_flag
+P_flag_head()
+{
+ atf_set "descr" "Verify that when creating a hard link to a " \
+ "symbolic link, '-P' option creates a hard " \
+ "link to the symbolic link itself"
+}
+
+P_flag_body()
+{
+ set_umask
+ atf_check touch A
+ atf_check ln -s A B
+ atf_check ln -P B C
+ atf_check -o inline:'100644\n120755\n120755\n' stat -f '%p' A B C
+}
+
+atf_test_case f_flag
+f_flag_head()
+{
+ atf_set "descr" "Verify that if the target file already exists, " \
+ "'-f' option unlinks it so that link may occur"
+}
+
+f_flag_body()
+{
+ set_umask
+ atf_check touch A B
+ atf_check ln -f A B
+ atf_check -o inline:'100644\n100644\n' stat -f '%p' A B
+}
+
+atf_test_case shf_flag_dir
+shf_flag_dir_head() {
+ atf_set "descr" "Verify that if the target directory is a symbolic "\
+ "link, '-shf' option prevents following the link"
+}
+
+shf_flag_dir_body()
+{
+ atf_check mkdir -m 0777 A B
+ atf_check ln -s A C
+ atf_check ln -shf B C
+ atf_check -o inline:'40777\n40777\n120755\n' stat -f '%p' A B C
+}
+
+atf_test_case shf_flag_file
+shf_flag_file_head() {
+ atf_set "descr" "Verify that if the target file is a symbolic "\
+ "link, '-shf' option prevents following the link"
+}
+
+shf_flag_file_body()
+{
+ set_umask
+ atf_check touch A B
+ atf_check ln -s A C
+ atf_check ln -shf B C
+ atf_check -o inline:'100644\n100644\n120755\n' stat -f '%p' A B C
+}
+
+atf_test_case snf_flag_dir
+snf_flag_dir_head() {
+ atf_set "descr" "Verify that if the target directory is a symbolic "\
+ "link, '-snf' option prevents following the link"
+}
+
+snf_flag_dir_body()
+{
+ atf_check mkdir -m 0777 A B
+ atf_check ln -s A C
+ atf_check ln -snf B C
+ atf_check -o inline:'40777\n40777\n120755\n' stat -f '%p' A B C
+}
+
+atf_test_case snf_flag_file
+snf_flag_file_head() {
+ atf_set "descr" "Verify that if the target file is a symbolic "\
+ "link, '-snf' option prevents following the link"
+}
+
+snf_flag_file_body()
+{
+ set_umask
+ atf_check touch A B
+ atf_check ln -s A C
+ atf_check ln -snf B C
+ atf_check -o inline:'100644\n100644\n120755\n' stat -f '%p' A B C
+}
+
+atf_test_case s_flag
+s_flag_head()
+{
+ atf_set "descr" "Verify that '-s' option creates a symbolic link"
+}
+
+s_flag_body()
+{
+ set_umask
+ atf_check touch A
+ atf_check ln -s A B
+ atf_check -o inline:'100644\n120755\n' stat -f '%p' A B
+}
+
+atf_test_case w_flag
+w_flag_head()
+{
+ atf_set "descr" "Verify that '-w' option produces a warning if the "\
+ "source of a symbolic link does not currently exist"
+}
+
+w_flag_body()
+{
+ atf_check -s exit:1 -e inline:'ln: A: No such file or directory\n' \
+ ln -w A B
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case L_flag
+ atf_add_test_case P_flag
+ atf_add_test_case f_flag
+ atf_add_test_case shf_flag_file
+ atf_add_test_case shf_flag_dir
+ atf_add_test_case snf_flag_file
+ atf_add_test_case snf_flag_dir
+ atf_add_test_case s_flag
+ atf_add_test_case w_flag
+}
Index: etc/mtree/BSD.tests.dist
===================================================================
--- etc/mtree/BSD.tests.dist
+++ etc/mtree/BSD.tests.dist
@@ -20,6 +20,8 @@
..
ls
..
+ ln
+ ..
mv
..
pax

File Metadata

Mime Type
text/plain
Expires
Sun, Jan 18, 4:25 AM (19 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27700563
Default Alt Text
D11084.id29301.diff (6 KB)

Event Timeline