]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - tests/printf.tests
Bash-4.3 distribution sources and documentation
[thirdparty/bash.git] / tests / printf.tests
index 5654ea487b1c5f993b8e1398ccd217e7297f64d5..e72f5c8bb29702de7c58ace09a793cea8e067015 100644 (file)
@@ -9,6 +9,13 @@ printf --
 printf ""
 printf -- ""
 
+# in the future this may mean to put the output into VAR, but for
+# now it is an error
+# 2005-03-15 no longer an error
+unset var
+printf -v var "%10d" $RANDOM
+echo ${#var}
+
 # this should expand escape sequences in the format string, nothing else
 printf "\tone\n"
 
@@ -60,12 +67,12 @@ printf -- "--%b--\n" '\t\0101'
 printf -- "--%b--\n" '\t\101'
 
 # these should all display `A7'
-echo -e "\1017"
-echo -e "\x0417"
+echo -e "\01017"
+echo -e "\x417"
 
 printf "%b\n" '\01017'
 printf "%b\n" '\1017'
-printf "%b\n" '\x0417'
+printf "%b\n" '\x417'
 
 printf -- "--%b--\n" '\"abcd\"'
 printf -- "--%b--\n" "\'abcd\'"
@@ -196,15 +203,117 @@ printf "%d\n" 26
 # happily ignore overflow conditions in strtol(3)
 #printf "%ld\n" 4294967296
 
-# in the future this may mean to put the output into VAR, but for
-# now it is an error
-printf -v var "%10d" $RANDOM
-
 printf "%10"
 printf "ab%Mcd\n"
 
 # this caused an infinite loop in older versions of printf
 printf "%y" 0
 
+# these should print a warning and `0', according to POSIX.2
 printf "%d\n" GNU
 printf "%o\n" GNU
+
+# failures in all bash versions through bash-2.05
+printf "%.0s" foo
+printf "%.*s" 0 foo
+
+printf '%.0b-%.0s\n' foo bar
+printf '(%*b)(%*s)\n' -4 foo -4 bar
+
+format='%'`printf '%0100384d' 0`'d\n' 
+printf $format 0
+
+# failures in all bash versions through bash-3.0 - undercounted characters
+unset vv
+printf "  %s %s %s  \n%n" ab cd ef vv
+echo "$vv"
+
+# this doesn't work with printf(3) on all systems
+#printf "%'s\n" foo
+
+# test cases from an austin-group list discussion
+# prints ^G as an extension
+printf '%b\n' '\7'
+
+# prints ^G
+printf '%b\n' '\0007'
+
+# prints NUL then 7
+printf '\0007\n'
+
+# prints no more than two hex digits
+printf '\x07e\n'
+
+# additional backslash escapes
+printf '\"\?\n'
+
+# failures with decimal precisions until after bash-3.1
+printf '%0.5d\n' 1
+
+printf '%05d\n' 1
+printf '%5d\n' 1
+printf '%0d\n' 1
+
+# failures with various floating point formats and 0 after bash-3.2
+
+printf "%G\n" 0
+printf "%g\n" 0
+printf "%4.2G\n" 0
+printf "%4.2g\n" 0
+
+printf "%G\n" 4
+printf "%g\n" 4
+printf "%4.2G\n" 4
+printf "%4.2g\n" 4
+
+printf "%F\n" 0
+printf "%f\n" 0
+printf "%4.2F\n" 0
+printf "%4.2f\n" 0
+
+printf "%F\n" 4
+printf "%f\n" 4
+printf "%4.2F\n" 4
+printf "%4.2f\n" 4
+
+printf "%E\n" 0
+printf "%e\n" 0
+printf "%4.2E\n" 0
+printf "%4.2e\n" 0
+
+printf "%E\n" 4
+printf "%e\n" 4
+printf "%4.2E\n" 4
+printf "%4.2e\n" 4
+
+printf "%08X\n" 2604292517
+
+# make sure these format specifiers all output '' for empty string arguments
+echo q
+printf "%q\n" ""
+printf "%q\n"
+
+echo s
+printf "%s\n" ''
+printf "%s\n"
+
+echo b
+printf "%b\n" ''
+printf "%b\n"
+
+# bug in bash versions up to and including bash-3.2
+v=yyy
+printf -v var "%s" '/current/working/directory/*.@(m3|i3|ig|mg)'
+shopt -s nullglob extglob
+echo "x$(printf "%b" @(hugo))x"
+printf -v var "%b" @(hugo); echo "x${var}x"
+
+# tests variable assignment with -v
+${THIS_SH} ./printf1.sub
+
+${THIS_SH} ./printf2.sub
+
+${THIS_SH} ./printf3.sub
+
+${THIS_SH} ./printf4.sub
+