sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

0002-printf.sh (638B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 exp1=exp1.$$
      6 exp2=exp2.$$
      7 res1=res1.$$
      8 res2=res2.$$
      9 
     10 cleanup()
     11 {
     12 	st=$?
     13 	rm -f $exp1 $exp2 $res1 $res2
     14 	exit $st
     15 }
     16 
     17 trap cleanup EXIT HUP INT TERM
     18 
     19 cat <<'EOF' > $exp1
     20 123
     21 0
     22 foo
     23 bar
     24 +001   +2 +003 -400 
     25 Expected failure
     26 EOF
     27 
     28 cat <<'EOF' > $exp2
     29 ../printf: Missing format specifier.
     30 EOF
     31 
     32 (
     33 	../printf '123\n'
     34 	../printf '%d\n'
     35 	../printf '%b' 'foo\nbar\n'
     36 
     37 	# Two flags used simulatenously, + and 0
     38 	../printf '%+04d %+4d ' 1 2 3 -400; ../printf "\n"
     39 	# Missing format specifier; should have sane error message
     40 	../printf '%000' FOO || echo "Expected failure"
     41 ) > $res1 2> $res2
     42 
     43 diff -u $exp1 $res1
     44 diff -u $exp2 $res2