aboutsummaryrefslogtreecommitdiff
path: root/tests/sh.test
blob: 875a0df86d7d93ea4bcf39cfb7fa4917792c0ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

if [ -z "$(which bash)" ]
then
  echo "$SHOWSKIP: no bash alias"
  return 2>/dev/null
  exit
fi

shellit()
{
  EVAL="bash -c" testing "$2" "$1 printf %s $2" "$3" "$4" "$5"
}

# $'' expands special chars but doesn't do so inside double quotes.

shellit "" "\$'a\\tb'" "a\tb" "" ""
shellit "" "\"\$'a\\tb'\"" '$'"'"'a\\tb'"'" "" "" 

# $(( )) tests

shellit 'x=1;' '$((-x))' '-1' '' ''
shellit 'x=0;' '$((x++)); echo $x' '01\n' '' ''
shellit 'x=0;' '$((++x))' '1' '' ''
shellit 'x=0;' '$((~x))' '-1' '' ''
shellit 'x=1;' '$((!x))' '0' '' ''
shellit 'x=0;' '$((!x))' '1' '' ''
shellit 'x=2;' '$((2*x))' '4' '' ''
shellit 'x=9;' '$((x/4))' '2' '' ''
shellit 'x=9;' '$((x%4))' '1' '' ''
shellit 'x=4;' '$((x+2))' '6' '' ''
shellit 'x=4;' '$((x-2))' '2' '' ''
shellit 'x=4;' '$((1<<x))' '16' '' ''
shellit 'x=4;' '$((x>>1))' '2' '' ''
shellit '' '$((3**4))' '81' '' ''
shellit '' '$((3<=4))' '1' '' ''
shellit '' '$((3>=4))' '0' '' ''
shellit '' '$((3<4))' '1' '' ''
shellit '' '$((3>4))' '0' '' ''
shellit '' '$((3==4))' '0' '' ''
shellit '' '$((3!=4))' '1' '' ''
shellit '' '$((6&4))' '4' '' ''
shellit '' '$((4|2))' '6' '' ''
shellit '' '$((6&&2))' '1' '' ''
shellit '' '$((6||4))' '1' '' ''
shellit '' '$((1?2:3))' '2' '' ''
shellit 'x=2;' '$((x=3)); echo $x' '33\n' '' ''
shellit 'x=2;' '$((x*=3)); echo $x' '66\n' '' ''
shellit 'x=5;' '$((x/=2)); echo $x' '22\n' '' ''
shellit 'x=9;' '$((x%=5)); echo $x' '44\n' '' ''
shellit 'x=9;' '$((x-=3)); echo $x' '66\n' '' ''
shellit 'x=3;' '$((x+=2)); echo $x' '55\n' '' ''
shellit 'x=7;' '$((x&=13)); echo $x' '55\n' '' ''
shellit 'x=5;' '$((x|=12)); echo $x' '1313\n' '' ''
shellit 'x=5;' '$((x^=12)); echo $x' '99\n' '' ''
shellit 'x=2;' '$((x<<=2)); echo $x' '88\n' '' ''
shellit 'x=12;' '$((x>>=2)); echo $x' '33\n' '' ''
shellit 'x=2;' '$((x++,5)); echo $x' '53\n' '' ''

# echo $(ls -l #comment)
# cat -</dev/null
# cat -|xargs echo
# cat -(ls)
# echo -!
# echo -{
# echo -(
# (echo -)
# echo $
# "echo \$(echo \"hello\nworld\")"
# "echo \"one ;\ntwo\""
# echo $(ls -l &)
# echo one < /dev/null two