Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 #testing "name" "command" "result" "infile" "stdin"
      6 
      7 shellit()
      8 {
      9   EVAL="bash -c" testing "$2" "$1 printf %s $2" "$3" "$4" "$5"
     10 }
     11 
     12 # $'' expands special chars but doesn't do so inside double quotes.
     13 
     14 shellit "" "\$'a\\tb'" "a\tb" "" ""
     15 shellit "" "\"\$'a\\tb'\"" '$'"'"'a\\tb'"'" "" "" 
     16 
     17 # $(( )) tests
     18 
     19 shellit 'x=1;' '$((-x))' '-1' '' ''
     20 shellit 'x=0;' '$((x++)); echo $x' '01\n' '' ''
     21 shellit 'x=0;' '$((++x))' '1' '' ''
     22 shellit 'x=0;' '$((~x))' '-1' '' ''
     23 shellit 'x=1;' '$((!x))' '0' '' ''
     24 shellit 'x=0;' '$((!x))' '1' '' ''
     25 shellit 'x=2;' '$((2*x))' '4' '' ''
     26 shellit 'x=9;' '$((x/4))' '2' '' ''
     27 shellit 'x=9;' '$((x%4))' '1' '' ''
     28 shellit 'x=4;' '$((x+2))' '6' '' ''
     29 shellit 'x=4;' '$((x-2))' '2' '' ''
     30 shellit 'x=4;' '$((1<<x))' '16' '' ''
     31 shellit 'x=4;' '$((x>>1))' '2' '' ''
     32 shellit '' '$((3**4))' '81' '' ''
     33 shellit '' '$((3<=4))' '1' '' ''
     34 shellit '' '$((3>=4))' '0' '' ''
     35 shellit '' '$((3<4))' '1' '' ''
     36 shellit '' '$((3>4))' '0' '' ''
     37 shellit '' '$((3==4))' '0' '' ''
     38 shellit '' '$((3!=4))' '1' '' ''
     39 shellit '' '$((6&4))' '4' '' ''
     40 shellit '' '$((4|2))' '6' '' ''
     41 shellit '' '$((6&&2))' '1' '' ''
     42 shellit '' '$((6||4))' '1' '' ''
     43 shellit '' '$((1?2:3))' '2' '' ''
     44 shellit 'x=2;' '$((x=3)); echo $x' '33\n' '' ''
     45 shellit 'x=2;' '$((x*=3)); echo $x' '66\n' '' ''
     46 shellit 'x=5;' '$((x/=2)); echo $x' '22\n' '' ''
     47 shellit 'x=9;' '$((x%=5)); echo $x' '44\n' '' ''
     48 shellit 'x=9;' '$((x-=3)); echo $x' '66\n' '' ''
     49 shellit 'x=3;' '$((x+=2)); echo $x' '55\n' '' ''
     50 shellit 'x=7;' '$((x&=13)); echo $x' '55\n' '' ''
     51 shellit 'x=5;' '$((x|=12)); echo $x' '1313\n' '' ''
     52 shellit 'x=5;' '$((x^=12)); echo $x' '99\n' '' ''
     53 shellit 'x=2;' '$((x<<=2)); echo $x' '88\n' '' ''
     54 shellit 'x=12;' '$((x>>=2)); echo $x' '33\n' '' ''
     55 shellit 'x=2;' '$((x++,5)); echo $x' '53\n' '' ''
     56 
     57 # echo $(ls -l #comment)
     58 # cat -</dev/null
     59 # cat -|xargs echo
     60 # cat -(ls)
     61 # echo -!
     62 # echo -{
     63 # echo -(
     64 # (echo -)
     65 # echo $
     66 # "echo \$(echo \"hello\nworld\")"
     67 # "echo \"one ;\ntwo\""
     68 # echo $(ls -l &)
     69 # echo one < /dev/null two
     70