pwd: Add tests
MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D55153
This commit is contained in:
+6
-2
@@ -1,4 +1,8 @@
|
||||
PACKAGE=runtime
|
||||
PROG= pwd
|
||||
.include <src.opts.mk>
|
||||
|
||||
PACKAGE= runtime
|
||||
PROG= pwd
|
||||
HAS_TESTS=
|
||||
SUBDIR.${MK_TESTS}= tests
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
PACKAGE= tests
|
||||
ATF_TESTS_SH= pwd_test
|
||||
|
||||
.include <bsd.test.mk>
|
||||
@@ -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
|
||||
}
|
||||
@@ -49,6 +49,8 @@
|
||||
..
|
||||
pwait
|
||||
..
|
||||
pwd
|
||||
..
|
||||
rm
|
||||
..
|
||||
rmdir
|
||||
|
||||
Reference in New Issue
Block a user