OSDN Git Service

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