Files
coreutils/tests/fold/fold-zero-width.sh
T
Collin Funk 98c8b158b6 tests: make checks for $LOCALE_FR and $LOCALE_FR_UTF8 consistent
* tests/cp/non-utf8-name.sh: Check for $LOCALE_FR and $LOCALE_FR_UTF8
being empty or the string "none".
* tests/date/percent-percent.sh: Likewise.
* tests/du/block-size.sh (test_unit): Likewise.
* tests/ls/non-utf8-hidden.sh: Likewise.
* tests/mktemp/bad-unicode.sh: Likewise.
* tests/sort/sort-unique.sh: Likewise.
* tests/df/problematic-chars.sh:  Check for $LOCALE_FR_UTF8 being empty
or the string "none".
* tests/expand/mb.sh: Likewise.
* tests/fold/fold-characters.sh: Likewise.
* tests/fold/fold-nbsp.sh: Likewise.
* tests/fold/fold-spaces.sh: Likewise.
* tests/fold/fold-zero-width.sh: Likewise.
* tests/join/join-utf8.sh: Likewise.
* tests/misc/sleep.sh: Likewise.
* tests/nl/multibyte.sh: Likewise.
* tests/paste/multi-byte.sh: Likewise.
* tests/printf/printf-mb.sh: Likewise.
* tests/printf/printf-quote.sh: Likewise.
* tests/sort/sort-debug-keys.sh: Likewise.
* tests/unexpand/mb.sh: Likewise.
2026-10-04 15:31:59 -07:00

70 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
# Test fold with zero width characters.
# Copyright (C) 2025-2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ fold printf
getlimits_
# Make sure we do not overflow the buffer.
IO_BUFSIZE_TIMES2=$(($IO_BUFSIZE * 2))
# Fold counts by columns by default.
head -c $IO_BUFSIZE_TIMES2 /dev/zero | fold > out || fail=1
test $(wc -l < out) -eq 0 || fail=1
# Check that zero width characters are counted with --characters.
head -c $IO_BUFSIZE_TIMES2 /dev/zero | fold --characters > out || fail=1
test $(wc -l < out) -eq $(($IO_BUFSIZE_TIMES2 / 80)) || fail=1
{ test -z "$LOCALE_FR_UTF8" || test "$LOCALE_FR_UTF8" = none; } &&
skip_ 'French UTF-8 locale not available'
# Only set LC_CTYPE so messages are not translated
# as we're verifying $ENOSPC below
unset LC_ALL
LC_CTYPE=$LOCALE_FR_UTF8
export LC_CTYPE
test $(env printf '\u200B' | wc -L) -eq 0 ||
skip_ "character width mismatch"
# Same thing, but using U+200B ZERO WIDTH SPACE.
yes $(env printf '\u200B') |
head -n $IO_BUFSIZE_TIMES2 | tr -d '\n' > inp || framework_failure_
fold inp > out || fail=1
test $(wc -l < out) -eq 0 || fail=1
fold --characters inp > out || fail=1
test $(wc -l < out) -eq $(($IO_BUFSIZE_TIMES2 / 80)) || fail=1
# Ensure bounded memory operation.
test -w /dev/full && test -c /dev/full &&
vm=$(get_min_ulimit_v_ timeout 10 fold /dev/null) && {
# \303 results in EILSEQ on input
for c in '\n' '\0' '\303'; do
tr '\0' "$c" < /dev/zero |
(ulimit -v $(($vm+6000)) && timeout 10 fold 2>err >/dev/full)
ret=$?
{ test $ret = 124 || ! grep "$ENOSPC" err >/dev/null; } &&
{ fail=1; cat err; echo "fold didn't diagnose ENOSPC" >&2; }
done
}
Exit $fail