1#!/bin/sh 2# tests for printf %q 3 4# Copyright (C) 2015-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ printf 21 22prog='env printf' 23 24# Equivalent output to ls --quoting=shell-escape 25$prog '%q\n' '' "'" a 'a b' '~a' 'a~' "$($prog %b 'a\r')" > out 26cat <<\EOF > exp || framework_failure_ 27'' 28"'" 29a 30'a b' 31'~a' 32a~ 33'a'$'\r' 34EOF 35compare exp out || fail=1 36 37unset LC_ALL 38f=$LOCALE_FR_UTF8 39: ${LOCALE_FR_UTF8=none} 40if test "$LOCALE_FR_UTF8" != "none"; then 41 ( 42 #printable multi-byte 43 LC_ALL=$f $prog '%q\n' 'áḃç' > out 44 #non-printable multi-byte 45 LC_ALL=$f $prog '%q\n' "$($prog '\xc2\x81')" >> out 46 #printable multi-byte in C locale 47 LC_ALL=C $prog '%q\n' 'áḃç' >> out 48 ) 49 cat <<\EOF > exp || framework_failure_ 50áḃç 51''$'\302\201' 52''$'\303\241\341\270\203\303\247' 53EOF 54 compare exp out || fail=1 55fi 56 57Exit $fail 58