diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-05 00:27:50 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-05 00:27:50 +0000 |
commit | 88dcc573bed32d0f4e5dd7bd2d4547ebcad05a37 (patch) | |
tree | 5b2f2c8676d13bc132fdac4506049facd3475235 /shell | |
parent | 4cdf737a63e23fd5f33fcd90c253c12eb5a890fe (diff) | |
download | busybox-w32-88dcc573bed32d0f4e5dd7bd2d4547ebcad05a37.tar.gz busybox-w32-88dcc573bed32d0f4e5dd7bd2d4547ebcad05a37.tar.bz2 busybox-w32-88dcc573bed32d0f4e5dd7bd2d4547ebcad05a37.zip |
small ash testsuite, adapted from bash
(only a small part of it, actually)
git-svn-id: svn://busybox.net/trunk/busybox@18005 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash_test/ash-alias/alias.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-alias/alias.tests | 37 | ||||
-rw-r--r-- | shell/ash_test/ash-arith/README.ash | 1 | ||||
-rw-r--r-- | shell/ash_test/ash-arith/arith-for.right | 74 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith-for.testsx | 94 | ||||
-rw-r--r-- | shell/ash_test/ash-arith/arith.right | 138 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith.tests | 302 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith1.sub | 40 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith2.sub | 57 | ||||
-rw-r--r-- | shell/ash_test/printenv.c | 67 | ||||
-rw-r--r-- | shell/ash_test/recho.c | 63 | ||||
-rwxr-xr-x | shell/ash_test/run-all | 62 | ||||
-rw-r--r-- | shell/ash_test/zecho.c | 39 |
13 files changed, 978 insertions, 0 deletions
diff --git a/shell/ash_test/ash-alias/alias.right b/shell/ash_test/ash-alias/alias.right new file mode 100644 index 000000000..0667b2187 --- /dev/null +++ b/shell/ash_test/ash-alias/alias.right | |||
@@ -0,0 +1,4 @@ | |||
1 | alias: 0 | ||
2 | alias: 0 | ||
3 | ./alias.tests: line 25: qfoo: not found | ||
4 | quux | ||
diff --git a/shell/ash_test/ash-alias/alias.tests b/shell/ash_test/ash-alias/alias.tests new file mode 100755 index 000000000..8d07b0b28 --- /dev/null +++ b/shell/ash_test/ash-alias/alias.tests | |||
@@ -0,0 +1,37 @@ | |||
1 | # place holder for future alias testing | ||
2 | #ash# shopt -s expand_aliases | ||
3 | |||
4 | # alias/unalias tests originally in builtins.tests | ||
5 | |||
6 | unalias -a | ||
7 | # this should return success, according to POSIX.2 | ||
8 | alias | ||
9 | echo alias: $? | ||
10 | alias foo=bar | ||
11 | unalias foo | ||
12 | # this had better return success, according to POSIX.2 | ||
13 | alias | ||
14 | echo alias: $? | ||
15 | |||
16 | # bug in all versions through bash-2.05b | ||
17 | |||
18 | unalias qfoo qbar qbaz quux 2>/dev/null | ||
19 | |||
20 | alias qfoo=qbar | ||
21 | alias qbar=qbaz | ||
22 | alias qbaz=quux | ||
23 | alias quux=qfoo | ||
24 | |||
25 | qfoo | ||
26 | |||
27 | unalias qfoo qbar qbaz quux | ||
28 | |||
29 | unalias -a | ||
30 | |||
31 | alias foo='echo ' | ||
32 | alias bar=baz | ||
33 | alias baz=quux | ||
34 | |||
35 | foo bar | ||
36 | |||
37 | unalias foo bar baz | ||
diff --git a/shell/ash_test/ash-arith/README.ash b/shell/ash_test/ash-arith/README.ash new file mode 100644 index 000000000..7da22ef73 --- /dev/null +++ b/shell/ash_test/ash-arith/README.ash | |||
@@ -0,0 +1 @@ | |||
there is no support for (( )) constructs in ash | |||
diff --git a/shell/ash_test/ash-arith/arith-for.right b/shell/ash_test/ash-arith/arith-for.right new file mode 100644 index 000000000..44941103f --- /dev/null +++ b/shell/ash_test/ash-arith/arith-for.right | |||
@@ -0,0 +1,74 @@ | |||
1 | 0 | ||
2 | 1 | ||
3 | 2 | ||
4 | 0 | ||
5 | 1 | ||
6 | 2 | ||
7 | 0 | ||
8 | 1 | ||
9 | 2 | ||
10 | 0 | ||
11 | 2 | ||
12 | 4 | ||
13 | fx is a function | ||
14 | fx () | ||
15 | { | ||
16 | i=0; | ||
17 | for ((1; i < 3; i++ )) | ||
18 | do | ||
19 | echo $i; | ||
20 | done; | ||
21 | for ((i=0; 1; i++ )) | ||
22 | do | ||
23 | if (( i >= 3 )); then | ||
24 | break; | ||
25 | fi; | ||
26 | echo $i; | ||
27 | done; | ||
28 | for ((i=0; i<3; 1)) | ||
29 | do | ||
30 | echo $i; | ||
31 | (( i++ )); | ||
32 | done; | ||
33 | i=0; | ||
34 | for ((1; 1; 1)) | ||
35 | do | ||
36 | if (( i > 2 )); then | ||
37 | break; | ||
38 | fi; | ||
39 | echo $i; | ||
40 | (( i++ )); | ||
41 | done; | ||
42 | i=0; | ||
43 | for ((1; 1; 1)) | ||
44 | do | ||
45 | if (( i > 2 )); then | ||
46 | break; | ||
47 | fi; | ||
48 | echo $i; | ||
49 | (( i++ )); | ||
50 | done | ||
51 | } | ||
52 | 0 | ||
53 | 1 | ||
54 | 2 | ||
55 | 0 | ||
56 | 1 | ||
57 | 2 | ||
58 | 0 | ||
59 | 1 | ||
60 | 2 | ||
61 | 0 | ||
62 | 1 | ||
63 | 2 | ||
64 | 0 | ||
65 | 1 | ||
66 | 2 | ||
67 | ./arith-for.tests: line 77: syntax error: arithmetic expression required | ||
68 | ./arith-for.tests: line 77: syntax error: `(( i=0; "i < 3" ))' | ||
69 | 2 | ||
70 | ./arith-for.tests: line 83: syntax error: `;' unexpected | ||
71 | ./arith-for.tests: line 83: syntax error: `(( i=0; i < 3; i++; 7 ))' | ||
72 | 2 | ||
73 | 20 | ||
74 | 20 | ||
diff --git a/shell/ash_test/ash-arith/arith-for.testsx b/shell/ash_test/ash-arith/arith-for.testsx new file mode 100755 index 000000000..585aa5133 --- /dev/null +++ b/shell/ash_test/ash-arith/arith-for.testsx | |||
@@ -0,0 +1,94 @@ | |||
1 | fx() | ||
2 | { | ||
3 | i=0 | ||
4 | for (( ; i < 3; i++ )) | ||
5 | do | ||
6 | echo $i | ||
7 | done | ||
8 | |||
9 | for (( i=0; ; i++ )) | ||
10 | do | ||
11 | if (( i >= 3 )); then | ||
12 | break; | ||
13 | fi | ||
14 | echo $i | ||
15 | done | ||
16 | |||
17 | for (( i=0; i<3; )) | ||
18 | do | ||
19 | echo $i | ||
20 | (( i++ )) | ||
21 | done | ||
22 | |||
23 | i=0 | ||
24 | for (( ; ; )) | ||
25 | do | ||
26 | if (( i > 2 )); then | ||
27 | break; | ||
28 | fi | ||
29 | echo $i; | ||
30 | (( i++ )) | ||
31 | done | ||
32 | |||
33 | i=0 | ||
34 | for ((;;)) | ||
35 | do | ||
36 | if (( i > 2 )); then | ||
37 | break; | ||
38 | fi | ||
39 | echo $i; | ||
40 | (( i++ )) | ||
41 | done | ||
42 | } | ||
43 | |||
44 | for (( i=0; "i < 3" ; i++ )) | ||
45 | do | ||
46 | echo $i | ||
47 | done | ||
48 | |||
49 | i=0 | ||
50 | for (( ; "i < 3"; i++ )) | ||
51 | do | ||
52 | echo $i | ||
53 | done | ||
54 | |||
55 | for (( i=0; ; i++ )) | ||
56 | do | ||
57 | if (( i >= 3 )); then | ||
58 | break; | ||
59 | fi | ||
60 | echo $i | ||
61 | done | ||
62 | |||
63 | for ((i = 0; ;i++ )) | ||
64 | do | ||
65 | echo $i | ||
66 | if (( i < 3 )); then | ||
67 | (( i++ )) | ||
68 | continue; | ||
69 | fi | ||
70 | break | ||
71 | done | ||
72 | |||
73 | type fx | ||
74 | fx | ||
75 | |||
76 | # errors | ||
77 | for (( i=0; "i < 3" )) | ||
78 | do | ||
79 | echo $i | ||
80 | done | ||
81 | echo $? | ||
82 | |||
83 | for (( i=0; i < 3; i++; 7 )) | ||
84 | do | ||
85 | echo $i | ||
86 | done | ||
87 | echo $? | ||
88 | |||
89 | # one-liners added in post-bash-2.04 | ||
90 | for ((i=0; i < 20; i++)) do : ; done | ||
91 | echo $i | ||
92 | |||
93 | for ((i=0; i < 20; i++)) { : ; } | ||
94 | echo $i | ||
diff --git a/shell/ash_test/ash-arith/arith.right b/shell/ash_test/ash-arith/arith.right new file mode 100644 index 000000000..3ea7ce680 --- /dev/null +++ b/shell/ash_test/ash-arith/arith.right | |||
@@ -0,0 +1,138 @@ | |||
1 | Format: 'expected actual' | ||
2 | 163 163 | ||
3 | 4 4 | ||
4 | 16 16 | ||
5 | 8 8 | ||
6 | 2 2 | ||
7 | 4 4 | ||
8 | 2 2 | ||
9 | 2 2 | ||
10 | 1 1 | ||
11 | 0 0 | ||
12 | 0 0 | ||
13 | 0 0 | ||
14 | 1 1 | ||
15 | 1 1 | ||
16 | 2 2 | ||
17 | -3 -3 | ||
18 | -2 -2 | ||
19 | 1 1 | ||
20 | 0 0 | ||
21 | 2 2 | ||
22 | 131072 131072 | ||
23 | 29 29 | ||
24 | 33 33 | ||
25 | 49 49 | ||
26 | 1 1 | ||
27 | 1 1 | ||
28 | 0 0 | ||
29 | 0 0 | ||
30 | 1 1 | ||
31 | 1 1 | ||
32 | 1 1 | ||
33 | 2 2 | ||
34 | 3 3 | ||
35 | 1 1 | ||
36 | 58 58 | ||
37 | 2 2 | ||
38 | 60 60 | ||
39 | 1 1 | ||
40 | 256 256 | ||
41 | 16 16 | ||
42 | 62 62 | ||
43 | 4 4 | ||
44 | 29 29 | ||
45 | 5 5 | ||
46 | -4 -4 | ||
47 | 4 4 | ||
48 | 1 1 | ||
49 | 32 32 | ||
50 | 32 32 | ||
51 | 1 1 | ||
52 | 1 1 | ||
53 | 32 32 | ||
54 | 20 20 | ||
55 | 30 30 | ||
56 | 20 20 | ||
57 | 30 30 | ||
58 | ./arith.tests: line 117: syntax error: 1 ? 20 : x+=2 | ||
59 | 6 6 | ||
60 | 6,5,3 6,5,3 | ||
61 | 263 263 | ||
62 | 255 255 | ||
63 | 40 40 | ||
64 | ./arith.tests: line 163: syntax error: 7 = 43 | ||
65 | ./arith.tests: line 165: divide by zero | ||
66 | ./arith.tests: let: line 166: syntax error: jv += $iv | ||
67 | ./arith.tests: line 167: syntax error: jv += $iv | ||
68 | ./arith.tests: let: line 168: syntax error: rv = 7 + (43 * 6 | ||
69 | abc | ||
70 | def | ||
71 | ghi | ||
72 | ./arith.tests: line 191: syntax error: ( 4 + A ) + 4 | ||
73 | 16 16 | ||
74 | ./arith.tests: line 196: syntax error: 4 ? : 3 + 5 | ||
75 | ./arith.tests: line 197: syntax error: 1 ? 20 | ||
76 | ./arith.tests: line 198: syntax error: 4 ? 20 : | ||
77 | 9 9 | ||
78 | ./arith.tests: line 205: syntax error: 0 && B=42 | ||
79 | ./arith.tests: line 208: syntax error: 1 || B=88 | ||
80 | 9 9 | ||
81 | 9 9 | ||
82 | 9 9 | ||
83 | 7 7 | ||
84 | 7 | ||
85 | 4 4 | ||
86 | 32767 32767 | ||
87 | 32768 32768 | ||
88 | 131072 131072 | ||
89 | 2147483647 2147483647 | ||
90 | 1 1 | ||
91 | 4 4 | ||
92 | 4 4 | ||
93 | 5 5 | ||
94 | 5 5 | ||
95 | 4 4 | ||
96 | 3 3 | ||
97 | 3 3 | ||
98 | 4 4 | ||
99 | 4 4 | ||
100 | ./arith.tests: line 257: syntax error: 7-- | ||
101 | ./arith.tests: line 259: syntax error: --x=7 | ||
102 | ./arith.tests: line 260: syntax error: ++x=7 | ||
103 | ./arith.tests: line 262: syntax error: x++=7 | ||
104 | ./arith.tests: line 263: syntax error: x--=7 | ||
105 | 4 4 | ||
106 | 7 7 | ||
107 | -7 -7 | ||
108 | ./arith1.sub: line 2: syntax error: 4-- | ||
109 | ./arith1.sub: line 3: syntax error: 4++ | ||
110 | ./arith1.sub: line 4: syntax error: 4 -- | ||
111 | ./arith1.sub: line 5: syntax error: 4 ++ | ||
112 | 6 6 | ||
113 | 3 3 | ||
114 | 7 7 | ||
115 | 4 4 | ||
116 | 0 0 | ||
117 | 3 3 | ||
118 | 7 7 | ||
119 | 2 2 | ||
120 | -2 -2 | ||
121 | 1 1 | ||
122 | ./arith1.sub: line 37: syntax error: +++7 | ||
123 | ./arith2.sub: line 2: syntax error: --7 | ||
124 | ./arith2.sub: line 3: syntax error: ++7 | ||
125 | ./arith2.sub: line 4: syntax error: -- 7 | ||
126 | ./arith2.sub: line 5: syntax error: ++ 7 | ||
127 | 5 5 | ||
128 | 1 1 | ||
129 | 4 4 | ||
130 | 0 0 | ||
131 | ./arith2.sub: line 42: syntax error: -- - 7 | ||
132 | ./arith2.sub: line 47: syntax error: ++ + 7 | ||
133 | 8 12 | ||
134 | ./arith.tests: line 290: syntax error: a b | ||
135 | 42 | ||
136 | 42 | ||
137 | 42 | ||
138 | ./arith.tests: line 302: a[b[c]d]=e: not found | ||
diff --git a/shell/ash_test/ash-arith/arith.tests b/shell/ash_test/ash-arith/arith.tests new file mode 100755 index 000000000..272fc3487 --- /dev/null +++ b/shell/ash_test/ash-arith/arith.tests | |||
@@ -0,0 +1,302 @@ | |||
1 | #ash# set +o posix | ||
2 | #ash# declare -i iv jv | ||
3 | |||
4 | echo "Format: 'expected actual'" | ||
5 | |||
6 | iv=$(( 3 + 5 * 32 )) | ||
7 | echo 163 $iv | ||
8 | #ash# iv=iv+3 | ||
9 | #ash# echo 166 $iv | ||
10 | iv=2 | ||
11 | jv=iv | ||
12 | |||
13 | let "jv *= 2" | ||
14 | echo 4 $jv | ||
15 | jv=$(( $jv << 2 )) | ||
16 | echo 16 $jv | ||
17 | |||
18 | let jv="$jv / 2" | ||
19 | echo 8 $jv | ||
20 | #ash# jv="jv >> 2" | ||
21 | let jv="jv >> 2" | ||
22 | echo 2 $jv | ||
23 | |||
24 | iv=$((iv+ $jv)) | ||
25 | echo 4 $iv | ||
26 | echo 2 $((iv -= jv)) | ||
27 | echo 2 $iv | ||
28 | echo 1 $(( iv == jv )) | ||
29 | echo 0 $(( iv != $jv )) | ||
30 | echo 0 $(( iv < jv )) | ||
31 | echo 0 $(( $iv > $jv )) | ||
32 | echo 1 $(( iv <= $jv )) | ||
33 | echo 1 $(( $iv >= jv )) | ||
34 | |||
35 | echo 2 $jv | ||
36 | echo -3 $(( ~$jv )) | ||
37 | echo -2 $(( ~1 )) | ||
38 | echo 1 $(( ! 0 )) | ||
39 | |||
40 | echo 0 $(( jv % 2 )) | ||
41 | echo 2 $(( $iv % 4 )) | ||
42 | |||
43 | echo 131072 $(( iv <<= 16 )) | ||
44 | echo 29 $(( iv %= 33 )) | ||
45 | |||
46 | echo 33 $(( 33 & 55 )) | ||
47 | echo 49 $(( 33 | 17 )) | ||
48 | |||
49 | echo 1 $(( iv && $jv )) | ||
50 | echo 1 $(( $iv || jv )) | ||
51 | |||
52 | echo 0 $(( iv && 0 )) | ||
53 | echo 0 $(( iv & 0 )) | ||
54 | echo 1 $(( iv && 1 )) | ||
55 | echo 1 $(( iv & 1 )) | ||
56 | |||
57 | echo 1 $(( $jv || 0 )) | ||
58 | echo 2 $(( jv | 0 )) | ||
59 | echo 3 $(( jv | 1 )) | ||
60 | echo 1 $(( $jv || 1 )) | ||
61 | |||
62 | let 'iv *= jv' | ||
63 | echo 58 $iv | ||
64 | echo 2 $jv | ||
65 | let "jv += $iv" | ||
66 | echo 60 $jv | ||
67 | |||
68 | echo 1 $(( jv /= iv )) | ||
69 | echo 256 $(( jv <<= 8 )) | ||
70 | echo 16 $(( jv >>= 4 )) | ||
71 | |||
72 | echo 62 $(( iv |= 4 )) | ||
73 | echo 4 $(( iv &= 4 )) | ||
74 | |||
75 | echo 29 $(( iv += (jv + 9))) | ||
76 | echo 5 $(( (iv + 4) % 7 )) | ||
77 | |||
78 | # unary plus, minus | ||
79 | echo -4 $(( +4 - 8 )) | ||
80 | echo 4 $(( -4 + 8 )) | ||
81 | |||
82 | # conditional expressions | ||
83 | echo 1 $(( 4<5 ? 1 : 32)) | ||
84 | echo 32 $(( 4>5 ? 1 : 32)) | ||
85 | echo 32 $(( 4>(2+3) ? 1 : 32)) | ||
86 | echo 1 $(( 4<(2+3) ? 1 : 32)) | ||
87 | echo 1 $(( (2+2)<(2+3) ? 1 : 32)) | ||
88 | echo 32 $(( (2+2)>(2+3) ? 1 : 32)) | ||
89 | |||
90 | # check that the unevaluated part of the ternary operator does not do | ||
91 | # evaluation or assignment | ||
92 | x=i+=2 | ||
93 | y=j+=2 | ||
94 | #ash# declare -i i=1 j=1 | ||
95 | i=1 | ||
96 | j=1 | ||
97 | echo 20 $((1 ? 20 : (x+=2))) | ||
98 | #ash# echo $i,$x # ash mishandles this | ||
99 | echo 30 $((0 ? (y+=2) : 30)) | ||
100 | #ash# echo $j,$y # ash mishandles this | ||
101 | |||
102 | x=i+=2 | ||
103 | y=j+=2 | ||
104 | #ash# declare -i i=1 j=1 | ||
105 | i=1 | ||
106 | j=1 | ||
107 | echo 20 $((1 ? 20 : (x+=2))) | ||
108 | #ash# echo $i,$x # ash mishandles this | ||
109 | echo 30 $((0 ? (y+=2) : 30)) | ||
110 | #ash# echo $i,$y # ash mishandles this | ||
111 | |||
112 | # check precedence of assignment vs. conditional operator | ||
113 | # should be an error | ||
114 | #ash# declare -i x=2 | ||
115 | x=2 | ||
116 | #ashnote# bash reports error but continues, ash aborts - using subshell to 'emulate' bash: | ||
117 | ( y=$((1 ? 20 : x+=2)) ) | ||
118 | |||
119 | # check precedence of assignment vs. conditional operator | ||
120 | #ash# declare -i x=2 | ||
121 | x=2 | ||
122 | # ash says "line NNN: syntax error: 0 ? x+=2 : 20" | ||
123 | #ash# echo 20 $((0 ? x+=2 : 20)) | ||
124 | |||
125 | # associativity of assignment-operator operator | ||
126 | #ash# declare -i i=1 j=2 k=3 | ||
127 | i=1 | ||
128 | j=2 | ||
129 | k=3 | ||
130 | echo 6 $((i += j += k)) | ||
131 | echo 6,5,3 $i,$j,$k | ||
132 | |||
133 | # octal, hex | ||
134 | echo 263 $(( 0x100 | 007 )) | ||
135 | echo 255 $(( 0xff )) | ||
136 | #ash# echo 255 $(( 16#ff )) | ||
137 | #ash# echo 127 $(( 16#FF/2 )) | ||
138 | #ash# echo 36 $(( 8#44 )) | ||
139 | |||
140 | echo 40 $(( 8 ^ 32 )) | ||
141 | |||
142 | #ash# # other bases | ||
143 | #ash# echo 10 $(( 16#a )) | ||
144 | #ash# echo 10 $(( 32#a )) | ||
145 | #ash# echo 10 $(( 56#a )) | ||
146 | #ash# echo 10 $(( 64#a )) | ||
147 | #ash# | ||
148 | #ash# echo 10 $(( 16#A )) | ||
149 | #ash# echo 10 $(( 32#A )) | ||
150 | #ash# echo 36 $(( 56#A )) | ||
151 | #ash# echo 36 $(( 64#A )) | ||
152 | #ash# | ||
153 | #ash# echo 62 $(( 64#@ )) | ||
154 | #ash# echo 63 $(( 64#_ )) | ||
155 | |||
156 | #ash# # weird bases (error) | ||
157 | #ash# echo $(( 3425#56 )) | ||
158 | |||
159 | #ash# # missing number after base | ||
160 | #ash# echo 0 $(( 2# )) | ||
161 | |||
162 | # these should generate errors | ||
163 | ( echo $(( 7 = 43 )) ) | ||
164 | #ash# echo $(( 2#44 )) | ||
165 | ( echo $(( 44 / 0 )) ) | ||
166 | ( let 'jv += $iv' ) | ||
167 | ( echo $(( jv += \$iv )) ) | ||
168 | ( let 'rv = 7 + (43 * 6' ) | ||
169 | |||
170 | #ash# # more errors | ||
171 | #ash# declare -i i | ||
172 | #ash# i=0#4 | ||
173 | #ash# i=2#110#11 | ||
174 | |||
175 | ((echo abc; echo def;); echo ghi) | ||
176 | |||
177 | #ash# if (((4+4) + (4 + 7))); then | ||
178 | #ash# echo ok | ||
179 | #ash# fi | ||
180 | |||
181 | #ash# (()) # make sure the null expression works OK | ||
182 | |||
183 | #ash# a=(0 2 4 6) | ||
184 | #ash# echo 6 $(( a[1] + a[2] )) | ||
185 | #ash# echo 1 $(( (a[1] + a[2]) == a[3] )) | ||
186 | #ash# (( (a[1] + a[2]) == a[3] )) ; echo 0 $? | ||
187 | |||
188 | # test pushing and popping the expression stack | ||
189 | unset A | ||
190 | A="4 + " | ||
191 | ( echo A $(( ( 4 + A ) + 4 )) ) | ||
192 | A="3 + 5" | ||
193 | echo 16 $(( ( 4 + A ) + 4 )) | ||
194 | |||
195 | # badly-formed conditional expressions | ||
196 | ( echo $(( 4 ? : $A )) ) | ||
197 | ( echo $(( 1 ? 20 )) ) | ||
198 | ( echo $(( 4 ? 20 : )) ) | ||
199 | |||
200 | # precedence and short-circuit evaluation | ||
201 | B=9 | ||
202 | echo 9 $B | ||
203 | |||
204 | # error | ||
205 | ( echo $(( 0 && B=42 )); echo 9 $B ) | ||
206 | |||
207 | # error | ||
208 | ( echo $(( 1 || B=88 )); echo 9 $B ) | ||
209 | |||
210 | # ash mistakenly evaluates B=... below | ||
211 | #ash# echo 0 $(( 0 && (B=42) )) | ||
212 | echo 9 $B | ||
213 | #ash# echo 0 $(( (${$} - $$) && (B=42) )) | ||
214 | echo 9 $B | ||
215 | #ash# echo 1 $(( 1 || (B=88) )) | ||
216 | echo 9 $B | ||
217 | |||
218 | |||
219 | # until command with (( )) command | ||
220 | x=7 | ||
221 | |||
222 | echo 7 $x | ||
223 | #ash# until (( x == 4 )) | ||
224 | until test "$x" = 4 | ||
225 | do | ||
226 | echo $x | ||
227 | x=4 | ||
228 | done | ||
229 | |||
230 | echo 4 $x | ||
231 | |||
232 | # exponentiation | ||
233 | echo 32767 $(( 2**15 - 1)) | ||
234 | echo 32768 $(( 2**(16-1))) | ||
235 | echo 131072 $(( 2**16*2 )) | ||
236 | echo 2147483647 $(( 2**31-1)) | ||
237 | echo 1 $(( 2**0 )) | ||
238 | |||
239 | # {pre,post}-{inc,dec}rement and associated errors | ||
240 | |||
241 | x=4 | ||
242 | |||
243 | echo 4 $x | ||
244 | echo 4 $(( x++ )) | ||
245 | echo 5 $x | ||
246 | echo 5 $(( x-- )) | ||
247 | echo 4 $x | ||
248 | |||
249 | echo 3 $(( --x )) | ||
250 | echo 3 $x | ||
251 | |||
252 | echo 4 $(( ++x )) | ||
253 | echo 4 $x | ||
254 | |||
255 | # bash 3.2 apparently thinks that ++7 is 7 | ||
256 | #ash# echo 7 $(( ++7 )) | ||
257 | ( echo $(( 7-- )) ) | ||
258 | |||
259 | ( echo $(( --x=7 )) ) | ||
260 | ( echo $(( ++x=7 )) ) | ||
261 | |||
262 | ( echo $(( x++=7 )) ) | ||
263 | ( echo $(( x--=7 )) ) | ||
264 | |||
265 | echo 4 $x | ||
266 | |||
267 | echo 7 $(( +7 )) | ||
268 | echo -7 $(( -7 )) | ||
269 | |||
270 | # bash 3.2 apparently thinks that ++7 is 7 | ||
271 | #ash# echo $(( ++7 )) | ||
272 | #ash# echo $(( --7 )) | ||
273 | |||
274 | ${THIS_SH} ./arith1.sub | ||
275 | ${THIS_SH} ./arith2.sub | ||
276 | |||
277 | x=4 | ||
278 | y=7 | ||
279 | |||
280 | #ash# (( x=8 , y=12 )) | ||
281 | x=8 | ||
282 | y=12 | ||
283 | echo $x $y | ||
284 | |||
285 | #ash# # should be an error | ||
286 | #ash# (( x=9 y=41 )) | ||
287 | |||
288 | # These are errors | ||
289 | unset b | ||
290 | ( echo $((a b)) ) | ||
291 | #ash# ((a b)) | ||
292 | |||
293 | n=42 | ||
294 | printf "%d\n" $n | ||
295 | printf "%i\n" $n | ||
296 | #ash# echo $(( 8#$(printf "%o\n" $n) )) | ||
297 | printf "%u\n" $n | ||
298 | #ash# echo $(( 16#$(printf "%x\n" $n) )) | ||
299 | #ash# echo $(( 16#$(printf "%X\n" $n) )) | ||
300 | |||
301 | # causes longjmp botches through bash-2.05b | ||
302 | a[b[c]d]=e | ||
diff --git a/shell/ash_test/ash-arith/arith1.sub b/shell/ash_test/ash-arith/arith1.sub new file mode 100755 index 000000000..80aa99922 --- /dev/null +++ b/shell/ash_test/ash-arith/arith1.sub | |||
@@ -0,0 +1,40 @@ | |||
1 | # test of redone post-increment and post-decrement code | ||
2 | ( echo $(( 4-- )) ) | ||
3 | ( echo $(( 4++ )) ) | ||
4 | ( echo $(( 4 -- )) ) | ||
5 | ( echo $(( 4 ++ )) ) | ||
6 | |||
7 | #ash# (( array[0]++ )) | ||
8 | #ash# echo ${array} | ||
9 | |||
10 | #ash# (( array[0] ++ )) | ||
11 | #ash# echo ${array} | ||
12 | |||
13 | #ash# (( a++ )) | ||
14 | #ash# echo $a | ||
15 | #ash# (( a ++ )) | ||
16 | #ash# echo $a | ||
17 | a=2 | ||
18 | |||
19 | echo 6 $(( a ++ + 4 )) | ||
20 | echo 3 $a | ||
21 | |||
22 | echo 7 $(( a+++4 )) | ||
23 | echo 4 $a | ||
24 | |||
25 | echo 0 $(( a---4 )) | ||
26 | echo 3 $a | ||
27 | |||
28 | echo 7 $(( a -- + 4 )) | ||
29 | echo 2 $a | ||
30 | |||
31 | echo -2 $(( a -- - 4 )) | ||
32 | echo 1 $a | ||
33 | |||
34 | #ash# (( ++ + 7 )) | ||
35 | |||
36 | #ash# (( ++ )) | ||
37 | ( echo $(( +++7 )) ) | ||
38 | # bash 3.2 apparently thinks that ++ +7 is 7 | ||
39 | #ash# echo $(( ++ + 7 )) | ||
40 | #ash# (( -- )) | ||
diff --git a/shell/ash_test/ash-arith/arith2.sub b/shell/ash_test/ash-arith/arith2.sub new file mode 100755 index 000000000..f7e3c9235 --- /dev/null +++ b/shell/ash_test/ash-arith/arith2.sub | |||
@@ -0,0 +1,57 @@ | |||
1 | # bash 3.2 apparently thinks that ++7 is 7 etc | ||
2 | ( echo $(( --7 )) ) | ||
3 | ( echo $(( ++7 )) ) | ||
4 | ( echo $(( -- 7 )) ) | ||
5 | ( echo $(( ++ 7 )) ) | ||
6 | |||
7 | #ash# ((++array[0] )) | ||
8 | #ash# echo 1 $array | ||
9 | #ash# (( ++ array[0] )) | ||
10 | #ash# echo 2 $array | ||
11 | |||
12 | #ash# (( ++a )) | ||
13 | #ash# echo 1 $a | ||
14 | #ash# (( ++ a )) | ||
15 | #ash# echo 2 $a | ||
16 | |||
17 | #ash# (( --a )) | ||
18 | #ash# echo 1 $a | ||
19 | #ash# (( -- a )) | ||
20 | #ash# echo 0 $a | ||
21 | a=0 | ||
22 | |||
23 | echo 5 $(( 4 + ++a )) | ||
24 | echo 1 $a | ||
25 | |||
26 | # ash doesn't handle it right... | ||
27 | #ash# echo 6 $(( 4+++a )) | ||
28 | #ash# echo 2 $a | ||
29 | a=2 | ||
30 | |||
31 | # ash doesn't handle it right... | ||
32 | #ash# echo 3 $(( 4---a )) | ||
33 | #ash# echo 1 $a | ||
34 | a=1 | ||
35 | |||
36 | echo 4 $(( 4 - -- a )) | ||
37 | echo 0 $a | ||
38 | |||
39 | #ash# (( -- )) | ||
40 | # bash 3.2 apparently thinks that ---7 is -7 | ||
41 | #ash# echo $(( ---7 )) | ||
42 | ( echo $(( -- - 7 )) ) | ||
43 | |||
44 | #ash# (( ++ )) | ||
45 | # bash 3.2: 7 | ||
46 | #ash# echo 7 $(( ++7 )) | ||
47 | ( echo $(( ++ + 7 )) ) | ||
48 | |||
49 | # bash 3.2: -7 | ||
50 | #ash# echo -7 $(( ++-7 )) | ||
51 | # bash 3.2: -7 | ||
52 | #ash# echo -7 $(( ++ - 7 )) | ||
53 | |||
54 | # bash 3.2: 7 | ||
55 | #ash# echo 7 $(( +--7 )) | ||
56 | # bash 3.2: 7 | ||
57 | #ash# echo 7 $(( -- + 7 )) | ||
diff --git a/shell/ash_test/printenv.c b/shell/ash_test/printenv.c new file mode 100644 index 000000000..07ea2a9f0 --- /dev/null +++ b/shell/ash_test/printenv.c | |||
@@ -0,0 +1,67 @@ | |||
1 | /* printenv -- minimal clone of BSD printenv(1). | ||
2 | |||
3 | usage: printenv [varname] | ||
4 | |||
5 | Chet Ramey | ||
6 | chet@po.cwru.edu | ||
7 | */ | ||
8 | |||
9 | /* Copyright (C) 1997-2002 Free Software Foundation, Inc. | ||
10 | |||
11 | This file is part of GNU Bash, the Bourne Again SHell. | ||
12 | |||
13 | Bash is free software; you can redistribute it and/or modify it under | ||
14 | the terms of the GNU General Public License as published by the Free | ||
15 | Software Foundation; either version 2, or (at your option) any later | ||
16 | version. | ||
17 | |||
18 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY | ||
19 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
21 | for more details. | ||
22 | |||
23 | You should have received a copy of the GNU General Public License along | ||
24 | with Bash; see the file COPYING. If not, write to the Free Software | ||
25 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ | ||
26 | |||
27 | #include <stdlib.h> | ||
28 | #include <string.h> | ||
29 | |||
30 | extern char **environ; | ||
31 | |||
32 | int | ||
33 | main (argc, argv) | ||
34 | int argc; | ||
35 | char **argv; | ||
36 | { | ||
37 | register char **envp, *eval; | ||
38 | int len; | ||
39 | |||
40 | argv++; | ||
41 | argc--; | ||
42 | |||
43 | /* printenv */ | ||
44 | if (argc == 0) | ||
45 | { | ||
46 | for (envp = environ; *envp; envp++) | ||
47 | puts (*envp); | ||
48 | exit (0); | ||
49 | } | ||
50 | |||
51 | /* printenv varname */ | ||
52 | len = strlen (*argv); | ||
53 | for (envp = environ; *envp; envp++) | ||
54 | { | ||
55 | if (**argv == **envp && strncmp (*envp, *argv, len) == 0) | ||
56 | { | ||
57 | eval = *envp + len; | ||
58 | /* If the environment variable doesn't have an `=', ignore it. */ | ||
59 | if (*eval == '=') | ||
60 | { | ||
61 | puts (eval + 1); | ||
62 | exit (0); | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | exit (1); | ||
67 | } | ||
diff --git a/shell/ash_test/recho.c b/shell/ash_test/recho.c new file mode 100644 index 000000000..02be0d760 --- /dev/null +++ b/shell/ash_test/recho.c | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | recho -- really echo args, bracketed with <> and with invisible chars | ||
3 | made visible. | ||
4 | |||
5 | Chet Ramey | ||
6 | chet@po.cwru.edu | ||
7 | */ | ||
8 | |||
9 | /* Copyright (C) 2002-2005 Free Software Foundation, Inc. | ||
10 | |||
11 | This file is part of GNU Bash, the Bourne Again SHell. | ||
12 | |||
13 | Bash is free software; you can redistribute it and/or modify it under | ||
14 | the terms of the GNU General Public License as published by the Free | ||
15 | Software Foundation; either version 2, or (at your option) any later | ||
16 | version. | ||
17 | |||
18 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY | ||
19 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
20 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
21 | for more details. | ||
22 | |||
23 | You should have received a copy of the GNU General Public License along | ||
24 | with Bash; see the file COPYING. If not, write to the Free Software | ||
25 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ | ||
26 | |||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | |||
30 | void strprint(); | ||
31 | |||
32 | int | ||
33 | main(argc, argv) | ||
34 | int argc; | ||
35 | char **argv; | ||
36 | { | ||
37 | register int i; | ||
38 | |||
39 | for (i = 1; i < argc; i++) { | ||
40 | printf("argv[%d] = <", i); | ||
41 | strprint(argv[i]); | ||
42 | printf(">\n"); | ||
43 | } | ||
44 | exit(0); | ||
45 | } | ||
46 | |||
47 | void | ||
48 | strprint(str) | ||
49 | char *str; | ||
50 | { | ||
51 | register unsigned char *s; | ||
52 | |||
53 | for (s = (unsigned char *)str; s && *s; s++) { | ||
54 | if (*s < ' ') { | ||
55 | putchar('^'); | ||
56 | putchar(*s+64); | ||
57 | } else if (*s == 127) { | ||
58 | putchar('^'); | ||
59 | putchar('?'); | ||
60 | } else | ||
61 | putchar(*s); | ||
62 | } | ||
63 | } | ||
diff --git a/shell/ash_test/run-all b/shell/ash_test/run-all new file mode 100755 index 000000000..ba1756e7d --- /dev/null +++ b/shell/ash_test/run-all | |||
@@ -0,0 +1,62 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | test -x ash || { echo "No ./ash?!"; exit; } | ||
4 | test -x printenv || gcc -O2 -o printenv printenv.c || exit $? | ||
5 | test -x recho || gcc -O2 -o recho recho.c || exit $? | ||
6 | test -x zecho || gcc -O2 -o zecho zecho.c || exit $? | ||
7 | |||
8 | PATH="$PWD:$PATH" # for ash and recho/zecho/printenv | ||
9 | export PATH | ||
10 | |||
11 | THIS_SH="$PWD/ash" | ||
12 | export THIS_SH | ||
13 | |||
14 | do_test() | ||
15 | { | ||
16 | test -d "$1" || return 0 | ||
17 | ( | ||
18 | cd "$1" || { echo "cannot cd $1!"; exit 1; } | ||
19 | for x in run-*; do | ||
20 | test -f "$x" || continue | ||
21 | case "$x" in | ||
22 | "$0"|run-minimal|run-gprof) ;; | ||
23 | *.orig|*~) ;; | ||
24 | #*) echo $x ; sh $x ;; | ||
25 | *) | ||
26 | sh "$x" >"../$1-$x.fail" 2>&1 && \ | ||
27 | { echo "$1/$x: ok"; rm "../$1-$x.fail"; } || echo "$1/$x: fail"; | ||
28 | ;; | ||
29 | esac | ||
30 | done | ||
31 | # Many bash run-XXX scripts just do this, | ||
32 | # no point in duplication it all over the place | ||
33 | for x in *.tests; do | ||
34 | test -x "$x" || continue | ||
35 | name="${x%%.tests}" | ||
36 | test -f "$name.right" || continue | ||
37 | { | ||
38 | "$THIS_SH" "./$x" >"$name.xx" 2>&1 | ||
39 | diff -u "$name.xx" "$name.right" >"../$1-$x.fail" && rm -f "$name.xx" "../$1-$x.fail" | ||
40 | } && echo "$1/$x: ok" || echo "$1/$x: fail" | ||
41 | done | ||
42 | ) | ||
43 | } | ||
44 | |||
45 | # main part of this script | ||
46 | # Usage: run-all [directories] | ||
47 | |||
48 | if [ $# -lt 1 ]; then | ||
49 | # All sub directories | ||
50 | modules=`ls -d ash-*` | ||
51 | |||
52 | for module in $modules; do | ||
53 | do_test $module | ||
54 | done | ||
55 | else | ||
56 | while [ $# -ge 1 ]; do | ||
57 | if [ -d $1 ]; then | ||
58 | do_test $1 | ||
59 | fi | ||
60 | shift | ||
61 | done | ||
62 | fi | ||
diff --git a/shell/ash_test/zecho.c b/shell/ash_test/zecho.c new file mode 100644 index 000000000..621d06d28 --- /dev/null +++ b/shell/ash_test/zecho.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* zecho - bare-bones echo */ | ||
2 | |||
3 | /* Copyright (C) 1996-2002 Free Software Foundation, Inc. | ||
4 | |||
5 | This file is part of GNU Bash, the Bourne Again SHell. | ||
6 | |||
7 | Bash is free software; you can redistribute it and/or modify it under | ||
8 | the terms of the GNU General Public License as published by the Free | ||
9 | Software Foundation; either version 2, or (at your option) any later | ||
10 | version. | ||
11 | |||
12 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY | ||
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
15 | for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License along | ||
18 | with Bash; see the file COPYING. If not, write to the Free Software | ||
19 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | int | ||
25 | main(argc, argv) | ||
26 | int argc; | ||
27 | char **argv; | ||
28 | { | ||
29 | argv++; | ||
30 | |||
31 | while (*argv) { | ||
32 | (void)printf("%s", *argv); | ||
33 | if (*++argv) | ||
34 | putchar(' '); | ||
35 | } | ||
36 | |||
37 | putchar('\n'); | ||
38 | exit(0); | ||
39 | } | ||