aboutsummaryrefslogtreecommitdiff
path: root/tests/sh.test
blob: 4f1ecb2cd5eb22c542adc43895c302a7eab8e83d (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
#!/bin/bash

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

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

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' '' ''