From nobody Wed Mar 27 11:26:22 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V4PWL51Lmz5FHyh; Wed, 27 Mar 2024 11:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V4PWL3Cvgz4c9G; Wed, 27 Mar 2024 11:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hvHn1975vmA3xTjCGsb2gQne6heWQthtLQNjDYCJW90=; b=vAqEriDkLLt6ojVYJKlT7KPcALj7MSYnZJPCGprTwJAxv8uHO+zOfg45M7RWBGr2NDf/of cqp3/W7EFwaKEIlxI41VDQzV000Js5ByHe/nIu7ZWD0Bg2oD8mKJIdai+jbMRn2o5x1Alq vbfIfI9izvgoDmxXdxg/9mc8WPpRz+EhSW3o8Chy9GqM6zxV5LCZD2DwwOC5rtT5TAEcYg LKR/vA2+t0sEt4QtrWp/11sxxzCAiRyexcjEs6E0YYO+MJ++qNstmRvXnJpLaOnUPkwvTA 3ANy+mTp7ej1PZME2IAuyI4ejCyKDkjb+bDcorqkl+CFP0XkV3VVOKrbbHF5zQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711538782; a=rsa-sha256; cv=none; b=Q5vxoOYNj+q3sp8wADNJ8RO95fnxwYrD0g/VGIDWEjevcmPXmHkRsa3MIv/TBy9A+OJgCE uspV3uHyWB0JHRVvFXS1xhzBTQtaqaHqNoJ4Z3CUEcB4Vw9Ik4z/yWxWjM6TlhWeozH5qu YidsKbBOiwrFmCqMkXGzTq0MF7Xt/GSYUj32G8OQQ72qezP1wbd09Ye4C9YSe8mwbgRMQR Nimn6Bp9JCeDSKaEOU56ZZUvnB5gspsL1eb22fxcq/x4/HKYeSsNIDx0mhnvZJL7dTxssu YKbe66+ThWiGmFFLhncrP8aATStEF3FDtdqcXnr3IPvbIfDtQ9hUJExdjWtytg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hvHn1975vmA3xTjCGsb2gQne6heWQthtLQNjDYCJW90=; b=hCF+mYHyvYjQjYXuMzlO1fF/y/D7OlmAgHYs1cyp7vogz4G+3FaRc9CQSBPdWhqOB9/YkA EzYQwsW9o/5+4N1fJfaFqc9q5wuj8cJSSjpr93ZGt6b3/NpBN7BCX/+5J35zHEFjaKV8Sv d9qGQt9Jkyi+mRxTEhZW96gL1we4UgCjnRoVVSwDuhq5dnwOCJXG8fUKnw57Jf2S+RwVXw HLYt7xgOine3m0Qg7fKqG9c+UZJ6LoQf4iwej+dXIjV7U6APAecIN1xThK4SLCmMWbKNKf Kg5W/Omdjz93Q1d1eaPWefqmFv18o7V4RrGA2He6VxsB1E+/vPC0RJENmYu1cw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V4PWL2YN9zhSs; Wed, 27 Mar 2024 11:26:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42RBQM8F003937; Wed, 27 Mar 2024 11:26:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42RBQMWh003934; Wed, 27 Mar 2024 11:26:22 GMT (envelope-from git) Date: Wed, 27 Mar 2024 11:26:22 GMT Message-Id: <202403271126.42RBQMWh003934@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e0afcbc85690 - main - ln: Clean up and simplify tests. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e0afcbc85690b6464706ead57103baa0493fdfb2 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e0afcbc85690b6464706ead57103baa0493fdfb2 commit e0afcbc85690b6464706ead57103baa0493fdfb2 Author: Dag-Erling Smørgrav AuthorDate: 2024-03-27 10:03:52 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-03-27 10:03:52 +0000 ln: Clean up and simplify tests. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D44512 --- bin/ln/tests/ln_test.sh | 68 +++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/bin/ln/tests/ln_test.sh b/bin/ln/tests/ln_test.sh index 75fda4ce2dd7..7daf5c5cdec0 100644 --- a/bin/ln/tests/ln_test.sh +++ b/bin/ln/tests/ln_test.sh @@ -1,4 +1,6 @@ # +# SPDX-License-Identifier: BSD-2-Clause +# # Copyright 2017 Shivansh Rai # All rights reserved. # @@ -23,13 +25,15 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# -set_umask() +atf_check_same_file() +{ + atf_check_equal "$(stat -f %d,%i "$1")" "$(stat -f %d,%i "$2")" +} + +atf_check_symlink_to() { - if ! umask 022; then - atf_fail "setting umask failed" - fi + atf_check -o inline:"$1\n" readlink "$2" } atf_test_case L_flag @@ -39,18 +43,13 @@ L_flag_head() "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 - stat_A=$(stat -f %i A) - stat_C=$(stat -f %i C) - atf_check_equal "$stat_A" "$stat_C" - atf_check -o inline:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_same_file A C + atf_check_symlink_to A B } atf_test_case P_flag @@ -60,16 +59,12 @@ P_flag_head() "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 - stat_B=$(stat -f %i B) - stat_C=$(stat -f %i C) - atf_check_equal "$stat_B" "$stat_C" + atf_check_same_file B C } atf_test_case f_flag @@ -78,15 +73,11 @@ 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 - stat_A=$(stat -f %i A) - stat_B=$(stat -f %i B) - atf_check_equal "$stat_A" "$stat_B" + atf_check_same_file A B } atf_test_case target_exists_hard @@ -95,10 +86,8 @@ target_exists_hard_head() atf_set "descr" "Verify whether creating a hard link fails if the " \ "target file already exists" } - target_exists_hard_body() { - set_umask atf_check touch A B atf_check -s exit:1 -e inline:'ln: B: File exists\n' \ ln A B @@ -110,10 +99,8 @@ target_exists_symbolic_head() atf_set "descr" "Verify whether creating a symbolic link fails if " \ "the target file already exists" } - target_exists_symbolic_body() { - set_umask atf_check touch A B atf_check -s exit:1 -e inline:'ln: B: File exists\n' \ ln -s A B @@ -124,13 +111,12 @@ 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:'Symbolic Link\n' stat -f %SHT C + atf_check test -L C atf_check -o inline:'B\n' readlink C } @@ -139,14 +125,12 @@ 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:'Symbolic Link\n' stat -f %SHT C - atf_check -o inline:'B\n' readlink C + atf_check_symlink_to B C } atf_test_case sF_flag @@ -156,13 +140,11 @@ sF_flag_head() "and is a directory, then '-sF' option removes " \ "it so that the link may occur" } - sF_flag_body() { atf_check mkdir A B atf_check ln -sF A B - atf_check -o inline:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_symlink_to A B } atf_test_case sf_flag @@ -172,14 +154,11 @@ sf_flag_head() "'-sf' option unlinks it and creates a symbolic link " \ "to the source file" } - sf_flag_body() { - set_umask atf_check touch A B atf_check ln -sf A B - atf_check -o inline:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_symlink_to A B } atf_test_case s_flag @@ -187,14 +166,11 @@ 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:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_symlink_to A B } atf_test_case s_flag_broken @@ -203,12 +179,10 @@ s_flag_broken_head() atf_set "descr" "Verify that if the source file does not exists, '-s' " \ "option creates a broken symbolic link to the source file" } - s_flag_broken_body() { atf_check ln -s A B - atf_check -o inline:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_symlink_to A B } atf_test_case sw_flag @@ -217,13 +191,11 @@ sw_flag_head() atf_set "descr" "Verify that '-sw' option produces a warning if the " \ "source of a symbolic link does not currently exist" } - sw_flag_body() { atf_check -s exit:0 -e inline:'ln: warning: A: No such file or directory\n' \ ln -sw A B - atf_check -o inline:'Symbolic Link\n' stat -f %SHT B - atf_check -o inline:'A\n' readlink B + atf_check_symlink_to A B } atf_init_test_cases()