tests/stat: test the left-aligned and right-aligned 'S' format

This commit is contained in:
rillig 2024-03-14 21:00:32 +00:00
parent cdaa157c5b
commit 897cdf26ba
5 changed files with 79 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1309 2024/03/03 00:50:41 rillig Exp $
# $NetBSD: mi,v 1.1310 2024/03/14 21:00:33 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6473,6 +6473,10 @@
./usr/tests/usr.bin/sort/d_any_char_iflag_out.txt tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/sort/d_any_char_in.txt tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/sort/t_sort tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/stat tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/stat/Atffile tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/stat/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua
./usr/tests/usr.bin/stat/t_stat tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/tar tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/tar/Atffile tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/tar/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua

View File

@ -1,4 +1,4 @@
# $NetBSD: NetBSD.dist.tests,v 1.202 2024/01/25 00:30:57 riastradh Exp $
# $NetBSD: NetBSD.dist.tests,v 1.203 2024/03/14 21:00:32 rillig Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@ -476,6 +476,7 @@
./usr/tests/usr.bin/sed
./usr/tests/usr.bin/shmif_dumpbus
./usr/tests/usr.bin/sort
./usr/tests/usr.bin/stat
./usr/tests/usr.bin/tar
./usr/tests/usr.bin/tmux
./usr/tests/usr.bin/tr

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.39 2024/01/25 00:30:57 riastradh Exp $
# $NetBSD: Makefile,v 1.40 2024/03/14 21:00:33 rillig Exp $
#
.include <bsd.own.mk>
@ -9,7 +9,7 @@ TESTS_SUBDIRS= awk basename bzip2 cc cmp compress config cpio col cut \
diff dirname error find fstat gdb grep gzip id indent \
infocmp jot ld locale m4 make mixerctl mkdep mtree nbperf \
netpgpverify patch pkill pr printf pwhash realpath rump_server \
shmif_dumpbus sdiff sed sort tar tmux tr unifdef uniq \
shmif_dumpbus sdiff sed sort stat tar tmux tr unifdef uniq \
vmstat xlint ztest
.if ${MKCXX} != "no"

View File

@ -0,0 +1,7 @@
# $NetBSD: Makefile,v 1.1 2024/03/14 21:00:33 rillig Exp $
TESTSDIR= ${TESTSBASE}/usr.bin/stat
TESTS_SH= t_stat
.include <bsd.test.mk>

View File

@ -0,0 +1,63 @@
# $NetBSD: t_stat.sh,v 1.1 2024/03/14 21:00:33 rillig Exp $
#
# Copyright (c) 2024 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Roland Illig.
#
# 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
#
atf_test_case string_format
string_format_head() {
atf_set "descr" "Tests the string output format 'S'"
}
string_format_body() {
echo 'äöü' > './Ümläute'
atf_check -o 'inline:plain <Ümläute>\n' \
stat -f 'plain <%SN>' 'Ümläute'
atf_check -o 'inline:right-aligned < Ümläute>\n' \
stat -f 'right-aligned <%20SN>' 'Ümläute'
atf_check -o 'inline:left-aligned <Ümläute >\n' \
stat -f 'left-aligned <%-20SN>' 'Ümläute'
# FIXME: invokes undefined behavior in snprintf "%+s"
atf_check -o 'inline:string-plus <Ümläute>\n' \
stat -f 'string-plus <%+SN>' 'Ümläute'
atf_check -o 'inline:vis <\303\234ml\303\244ute>\n' \
stat -f 'vis <%#SN>' 'Ümläute'
atf_check -o 'inline:vis left-aligned <\303\234ml\303\244ute >\n' \
stat -f 'vis left-aligned <%#-30SN>' 'Ümläute'
atf_check -o 'inline:vis right-aligned < \303\234ml\303\244ute>\n' \
stat -f 'vis right-aligned <%#30SN>' 'Ümläute'
}
atf_init_test_cases() {
atf_add_test_case string_format
}