Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Feb 2026 08:58:45 +0000
From:      Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 11a22ea28ecf - stable/14 - pwd: Add tests
Message-ID:  <69918ac5.1e0b1.12456846@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=11a22ea28ecf942c20db092ce99de34f2121f44a

commit 11a22ea28ecf942c20db092ce99de34f2121f44a
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-10 14:29:08 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-15 08:58:34 +0000

    pwd: Add tests
    
    MFC after:      1 week
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D55153
    
    (cherry picked from commit 36ec2b1c104f9e5383a160e21109e1308fce0364)
---
 bin/pwd/Makefile          |  8 ++++--
 bin/pwd/tests/Makefile    |  4 +++
 bin/pwd/tests/pwd_test.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 etc/mtree/BSD.tests.dist  |  2 ++
 4 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/bin/pwd/Makefile b/bin/pwd/Makefile
index 51e9c177c4f6..a46b52b9199a 100644
--- a/bin/pwd/Makefile
+++ b/bin/pwd/Makefile
@@ -1,6 +1,10 @@
 #	@(#)Makefile	8.1 (Berkeley) 5/31/93
 
-PACKAGE=runtime
-PROG=	pwd
+.include <src.opts.mk>
+
+PACKAGE=		runtime
+PROG=			pwd
+HAS_TESTS=
+SUBDIR.${MK_TESTS}=	tests
 
 .include <bsd.prog.mk>
diff --git a/bin/pwd/tests/Makefile b/bin/pwd/tests/Makefile
new file mode 100644
index 000000000000..8ce05fc4ae6f
--- /dev/null
+++ b/bin/pwd/tests/Makefile
@@ -0,0 +1,4 @@
+PACKAGE=	tests
+ATF_TESTS_SH=	pwd_test
+
+.include <bsd.test.mk>
diff --git a/bin/pwd/tests/pwd_test.sh b/bin/pwd/tests/pwd_test.sh
new file mode 100644
index 000000000000..e418e56a89fa
--- /dev/null
+++ b/bin/pwd/tests/pwd_test.sh
@@ -0,0 +1,73 @@
+#
+# Copyright (c) 2026 Dag-Erling Smørgrav
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_test_case logical
+logical_head()
+{
+	atf_set "descr" "Cases where pwd prints the " \
+		"logical working directory"
+}
+logical_body()
+{
+	root=$(realpath $PWD)
+	atf_check mkdir -p phy/baz
+	atf_check ln -s phy log
+	cd log/baz
+
+	# explicitly request logical
+	export PWD="$root/log/baz"
+	atf_check -o inline:"$root/log/baz\n" pwd -L
+	atf_check -o inline:"$root/log/baz\n" pwd -P -L
+
+	# logical is also the default
+	export PWD="$root/log/baz"
+	atf_check -o inline:"$root/log/baz\n" pwd
+}
+
+atf_test_case physical
+physical_head()
+{
+	atf_set "descr" "Cases where pwd prints the " \
+		"physical working directory"
+}
+physical_body()
+{
+	root=$(realpath $PWD)
+	atf_check mkdir -p phy/baz
+	atf_check ln -s phy log
+	cd log/baz
+
+	# explicitly request physical
+	export PWD="$root/log/baz"
+	atf_check -o inline:"$root/phy/baz\n" pwd -P
+	atf_check -o inline:"$root/phy/baz\n" pwd -L -P
+
+	# request logical but $PWD is relative
+	export PWD="log/baz"
+	atf_check -o inline:"$root/phy/baz\n" pwd -L
+
+	# request logical but $PWD contains dot
+	export PWD="$root/log/./baz"
+	atf_check -o inline:"$root/phy/baz\n" pwd -L
+
+	# request logical but $PWD contains dot-dot
+	export PWD="$root/log/../log/baz"
+	atf_check -o inline:"$root/phy/baz\n" pwd -L
+
+	# request logical but $PWD does not exist
+	export PWD="$root/baz"
+	atf_check -o inline:"$root/phy/baz\n" pwd -L
+
+	# request logical but $PWD does not match
+	export PWD="$root/log"
+	atf_check -o inline:"$root/phy/baz\n" pwd -L
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case logical
+	atf_add_test_case physical
+}
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 214d6f6162cb..eed5db1c806f 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -37,6 +37,8 @@
         ..
         pwait
         ..
+        pwd
+        ..
         rm
         ..
         rmdir


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69918ac5.1e0b1.12456846>