Print this page
4854 printf(1) doesn't support %b and \c properly

Split Close
Expand all
Collapse all
          --- old/usr/src/test/util-tests/tests/printf/printf_test.ksh
          +++ new/usr/src/test/util-tests/tests/printf/printf_test.ksh
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11  # http://www.illumos.org/license/CDDL.
  12   12  #
  13   13  
  14   14  #
  15   15  # Copyright 2014 Garrett D'Amore <garrett@damore.org>
  16   16  #
  17   17  
  18   18  PRINTF=${PRINTF:=/usr/bin/printf}
  19   19  
  20   20  test_start() {
  21      -        print "TEST STARTING ${1}: ${2}"
       21 +        print "TEST STARTING ${1}: ${2}"
  22   22  }
  23   23  
  24   24  test_pass() {
  25      -        print "TEST PASS: ${1}"
       25 +        print "TEST PASS: ${1}"
  26   26  }
  27   27  
  28   28  test_fail() {
  29      -        print "TEST FAIL: ${1}: ${2}"
  30      -#        exit -1
       29 +        print "TEST FAIL: ${1}: ${2}"
       30 +        exit -1
  31   31  }
  32   32  
  33   33  checkrv() {
  34   34          if [[ $? -ne 0 ]]; then
  35   35                  test_fail $1 "exit failure"
  36   36          fi
  37   37  }
  38   38  
  39   39  compare() {
  40   40          if [[ "$2" != "$3" ]]; then
↓ open down ↓ 95 lines elided ↑ open up ↑
 136  136  tests[14][result]='one
 137  137  two
 138  138  three'
 139  139  
 140  140  typeset -A tests[15]=()
 141  141  tests[15][desc]="embedded octal escape"
 142  142  tests[15][format]='%s\41%s'
 143  143  tests[15][args]="one two"
 144  144  tests[15][result]='one!two'
 145  145  
 146      -# this is not yet supported
 147      -#typeset -A tests[16]=()
 148      -#tests[16][desc]="backslash string (%b)"
 149      -#tests[16][format]='%b'
 150      -#tests[16][args]='\0101\0102\0103'
 151      -#tests[16][result]='ABC'
      146 +typeset -A tests[16]=()
      147 +tests[16][desc]="backslash string (%b)"
      148 +tests[16][format]='%b'
      149 +tests[16][args]='\0101\0102\0103'
      150 +tests[16][result]='ABC'
 152  151  
 153      -# nor is this
 154      -#typeset -A tests[17]=()
 155      -#tests[17][desc]="backslash c in %b"
 156      -#tests[17][format]='%b%s'
 157      -#tests[17][args]='\0101\cone two'
 158      -#tests[17][result]='A'
      152 +typeset -A tests[17]=()
      153 +tests[17][desc]="backslash c in %b"
      154 +tests[17][format]='%b%s'
      155 +tests[17][args]='\0101\cone two'
      156 +tests[17][result]='A'
 159  157  
      158 +typeset -A tests[18]=()
      159 +tests[18][desc]="backslash octal in format"
      160 +tests[18][format]='HI\1120K\0112tabbed\11again'
      161 +tests[18][args]=
      162 +tests[18][result]='HIJ0K        2tabbed again'
      163 +
      164 +typeset -A tests[19]=()
      165 +tests[19][desc]="backslash octal in %b"
      166 +tests[19][format]="%b"
      167 +tests[19][args]='HI\0112K\011tabbed'
      168 +tests[19][result]='HIJK tabbed'
      169 +
      170 +typeset -A tests[20]=()
      171 +tests[20][desc]="numeric %d and ASCII conversions"
      172 +tests[20][format]='%d '
      173 +tests[20][args]="3 +3 -3 \"3 \"+ '-"
      174 +tests[20][result]='3 3 -3 51 43 45 '
      175 +
 160  176  #debug=yes
 161  177  
 162  178  for i in "${!tests[@]}"; do
 163  179          t=test_$i
 164  180          desc=${tests[$i][desc]}
 165  181          format=${tests[$i][format]}
 166  182          args="${tests[$i][args]}"
 167  183          result=${tests[$i][result]}
 168  184          
 169  185          test_start $t "${tests[$i][desc]}"
 170  186          [[ -n "$debug" ]] && echo $PRINTF "$format" "${args[@]}"
 171  187          comp=$($PRINTF "$format" ${args[@]})
 172  188          checkrv $t 
 173  189          [[ -n "$debug" ]] && echo "got [$comp]"
 174  190          good=$result
 175  191          compare $t "$comp" "$good"
 176  192          test_pass $t
 177  193  done
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX