summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko2007-03-05 00:27:50 +0000
committerDenis Vlasenko2007-03-05 00:27:50 +0000
commit1c660b4bd2c303fcb829bc93143fc454693afab4 (patch)
tree5b2f2c8676d13bc132fdac4506049facd3475235 /shell
parent3af3e5b4b0d12dffbe7bd144092f8cb140ff74a4 (diff)
downloadbusybox-1c660b4bd2c303fcb829bc93143fc454693afab4.zip
busybox-1c660b4bd2c303fcb829bc93143fc454693afab4.tar.gz
small ash testsuite, adapted from bash
(only a small part of it, actually)
Diffstat (limited to 'shell')
-rw-r--r--shell/ash_test/ash-alias/alias.right4
-rwxr-xr-xshell/ash_test/ash-alias/alias.tests37
-rw-r--r--shell/ash_test/ash-arith/README.ash1
-rw-r--r--shell/ash_test/ash-arith/arith-for.right74
-rwxr-xr-xshell/ash_test/ash-arith/arith-for.testsx94
-rw-r--r--shell/ash_test/ash-arith/arith.right138
-rwxr-xr-xshell/ash_test/ash-arith/arith.tests302
-rwxr-xr-xshell/ash_test/ash-arith/arith1.sub40
-rwxr-xr-xshell/ash_test/ash-arith/arith2.sub57
-rw-r--r--shell/ash_test/printenv.c67
-rw-r--r--shell/ash_test/recho.c63
-rwxr-xr-xshell/ash_test/run-all62
-rw-r--r--shell/ash_test/zecho.c39
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 0000000..0667b21
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias.right
@@ -0,0 +1,4 @@
+alias: 0
+alias: 0
+./alias.tests: line 25: qfoo: not found
+quux
diff --git a/shell/ash_test/ash-alias/alias.tests b/shell/ash_test/ash-alias/alias.tests
new file mode 100755
index 0000000..8d07b0b
--- /dev/null
+++ b/shell/ash_test/ash-alias/alias.tests
@@ -0,0 +1,37 @@
+# place holder for future alias testing
+#ash# shopt -s expand_aliases
+
+# alias/unalias tests originally in builtins.tests
+
+unalias -a
+# this should return success, according to POSIX.2
+alias
+echo alias: $?
+alias foo=bar
+unalias foo
+# this had better return success, according to POSIX.2
+alias
+echo alias: $?
+
+# bug in all versions through bash-2.05b
+
+unalias qfoo qbar qbaz quux 2>/dev/null
+
+alias qfoo=qbar
+alias qbar=qbaz
+alias qbaz=quux
+alias quux=qfoo
+
+qfoo
+
+unalias qfoo qbar qbaz quux
+
+unalias -a
+
+alias foo='echo '
+alias bar=baz
+alias baz=quux
+
+foo bar
+
+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 0000000..7da22ef
--- /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 0000000..4494110
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-for.right
@@ -0,0 +1,74 @@
+0
+1
+2
+0
+1
+2
+0
+1
+2
+0
+2
+4
+fx is a function
+fx ()
+{
+ i=0;
+ for ((1; i < 3; i++ ))
+ do
+ echo $i;
+ done;
+ for ((i=0; 1; i++ ))
+ do
+ if (( i >= 3 )); then
+ break;
+ fi;
+ echo $i;
+ done;
+ for ((i=0; i<3; 1))
+ do
+ echo $i;
+ (( i++ ));
+ done;
+ i=0;
+ for ((1; 1; 1))
+ do
+ if (( i > 2 )); then
+ break;
+ fi;
+ echo $i;
+ (( i++ ));
+ done;
+ i=0;
+ for ((1; 1; 1))
+ do
+ if (( i > 2 )); then
+ break;
+ fi;
+ echo $i;
+ (( i++ ));
+ done
+}
+0
+1
+2
+0
+1
+2
+0
+1
+2
+0
+1
+2
+0
+1
+2
+./arith-for.tests: line 77: syntax error: arithmetic expression required
+./arith-for.tests: line 77: syntax error: `(( i=0; "i < 3" ))'
+2
+./arith-for.tests: line 83: syntax error: `;' unexpected
+./arith-for.tests: line 83: syntax error: `(( i=0; i < 3; i++; 7 ))'
+2
+20
+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 0000000..585aa51
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-for.testsx
@@ -0,0 +1,94 @@
+fx()
+{
+i=0
+for (( ; i < 3; i++ ))
+do
+ echo $i
+done
+
+for (( i=0; ; i++ ))
+do
+ if (( i >= 3 )); then
+ break;
+ fi
+ echo $i
+done
+
+for (( i=0; i<3; ))
+do
+ echo $i
+ (( i++ ))
+done
+
+i=0
+for (( ; ; ))
+do
+ if (( i > 2 )); then
+ break;
+ fi
+ echo $i;
+ (( i++ ))
+done
+
+i=0
+for ((;;))
+do
+ if (( i > 2 )); then
+ break;
+ fi
+ echo $i;
+ (( i++ ))
+done
+}
+
+for (( i=0; "i < 3" ; i++ ))
+do
+ echo $i
+done
+
+i=0
+for (( ; "i < 3"; i++ ))
+do
+ echo $i
+done
+
+for (( i=0; ; i++ ))
+do
+ if (( i >= 3 )); then
+ break;
+ fi
+ echo $i
+done
+
+for ((i = 0; ;i++ ))
+do
+ echo $i
+ if (( i < 3 )); then
+ (( i++ ))
+ continue;
+ fi
+ break
+done
+
+type fx
+fx
+
+# errors
+for (( i=0; "i < 3" ))
+do
+ echo $i
+done
+echo $?
+
+for (( i=0; i < 3; i++; 7 ))
+do
+ echo $i
+done
+echo $?
+
+# one-liners added in post-bash-2.04
+for ((i=0; i < 20; i++)) do : ; done
+echo $i
+
+for ((i=0; i < 20; i++)) { : ; }
+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 0000000..3ea7ce6
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith.right
@@ -0,0 +1,138 @@
+Format: 'expected actual'
+163 163
+4 4
+16 16
+8 8
+2 2
+4 4
+2 2
+2 2
+1 1
+0 0
+0 0
+0 0
+1 1
+1 1
+2 2
+-3 -3
+-2 -2
+1 1
+0 0
+2 2
+131072 131072
+29 29
+33 33
+49 49
+1 1
+1 1
+0 0
+0 0
+1 1
+1 1
+1 1
+2 2
+3 3
+1 1
+58 58
+2 2
+60 60
+1 1
+256 256
+16 16
+62 62
+4 4
+29 29
+5 5
+-4 -4
+4 4
+1 1
+32 32
+32 32
+1 1
+1 1
+32 32
+20 20
+30 30
+20 20
+30 30
+./arith.tests: line 117: syntax error: 1 ? 20 : x+=2
+6 6
+6,5,3 6,5,3
+263 263
+255 255
+40 40
+./arith.tests: line 163: syntax error: 7 = 43
+./arith.tests: line 165: divide by zero
+./arith.tests: let: line 166: syntax error: jv += $iv
+./arith.tests: line 167: syntax error: jv += $iv
+./arith.tests: let: line 168: syntax error: rv = 7 + (43 * 6
+abc
+def
+ghi
+./arith.tests: line 191: syntax error: ( 4 + A ) + 4
+16 16
+./arith.tests: line 196: syntax error: 4 ? : 3 + 5
+./arith.tests: line 197: syntax error: 1 ? 20
+./arith.tests: line 198: syntax error: 4 ? 20 :
+9 9
+./arith.tests: line 205: syntax error: 0 && B=42
+./arith.tests: line 208: syntax error: 1 || B=88
+9 9
+9 9
+9 9
+7 7
+7
+4 4
+32767 32767
+32768 32768
+131072 131072
+2147483647 2147483647
+1 1
+4 4
+4 4
+5 5
+5 5
+4 4
+3 3
+3 3
+4 4
+4 4
+./arith.tests: line 257: syntax error: 7--
+./arith.tests: line 259: syntax error: --x=7
+./arith.tests: line 260: syntax error: ++x=7
+./arith.tests: line 262: syntax error: x++=7
+./arith.tests: line 263: syntax error: x--=7
+4 4
+7 7
+-7 -7
+./arith1.sub: line 2: syntax error: 4--
+./arith1.sub: line 3: syntax error: 4++
+./arith1.sub: line 4: syntax error: 4 --
+./arith1.sub: line 5: syntax error: 4 ++
+6 6
+3 3
+7 7
+4 4
+0 0
+3 3
+7 7
+2 2
+-2 -2
+1 1
+./arith1.sub: line 37: syntax error: +++7
+./arith2.sub: line 2: syntax error: --7
+./arith2.sub: line 3: syntax error: ++7
+./arith2.sub: line 4: syntax error: -- 7
+./arith2.sub: line 5: syntax error: ++ 7
+5 5
+1 1
+4 4
+0 0
+./arith2.sub: line 42: syntax error: -- - 7
+./arith2.sub: line 47: syntax error: ++ + 7
+8 12
+./arith.tests: line 290: syntax error: a b
+42
+42
+42
+./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 0000000..272fc34
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith.tests
@@ -0,0 +1,302 @@
+#ash# set +o posix
+#ash# declare -i iv jv
+
+echo "Format: 'expected actual'"
+
+iv=$(( 3 + 5 * 32 ))
+echo 163 $iv
+#ash# iv=iv+3
+#ash# echo 166 $iv
+iv=2
+jv=iv
+
+let "jv *= 2"
+echo 4 $jv
+jv=$(( $jv << 2 ))
+echo 16 $jv
+
+let jv="$jv / 2"
+echo 8 $jv
+#ash# jv="jv >> 2"
+ let jv="jv >> 2"
+echo 2 $jv
+
+iv=$((iv+ $jv))
+echo 4 $iv
+echo 2 $((iv -= jv))
+echo 2 $iv
+echo 1 $(( iv == jv ))
+echo 0 $(( iv != $jv ))
+echo 0 $(( iv < jv ))
+echo 0 $(( $iv > $jv ))
+echo 1 $(( iv <= $jv ))
+echo 1 $(( $iv >= jv ))
+
+echo 2 $jv
+echo -3 $(( ~$jv ))
+echo -2 $(( ~1 ))
+echo 1 $(( ! 0 ))
+
+echo 0 $(( jv % 2 ))
+echo 2 $(( $iv % 4 ))
+
+echo 131072 $(( iv <<= 16 ))
+echo 29 $(( iv %= 33 ))
+
+echo 33 $(( 33 & 55 ))
+echo 49 $(( 33 | 17 ))
+
+echo 1 $(( iv && $jv ))
+echo 1 $(( $iv || jv ))
+
+echo 0 $(( iv && 0 ))
+echo 0 $(( iv & 0 ))
+echo 1 $(( iv && 1 ))
+echo 1 $(( iv & 1 ))
+
+echo 1 $(( $jv || 0 ))
+echo 2 $(( jv | 0 ))
+echo 3 $(( jv | 1 ))
+echo 1 $(( $jv || 1 ))
+
+let 'iv *= jv'
+echo 58 $iv
+echo 2 $jv
+let "jv += $iv"
+echo 60 $jv
+
+echo 1 $(( jv /= iv ))
+echo 256 $(( jv <<= 8 ))
+echo 16 $(( jv >>= 4 ))
+
+echo 62 $(( iv |= 4 ))
+echo 4 $(( iv &= 4 ))
+
+echo 29 $(( iv += (jv + 9)))
+echo 5 $(( (iv + 4) % 7 ))
+
+# unary plus, minus
+echo -4 $(( +4 - 8 ))
+echo 4 $(( -4 + 8 ))
+
+# conditional expressions
+echo 1 $(( 4<5 ? 1 : 32))
+echo 32 $(( 4>5 ? 1 : 32))
+echo 32 $(( 4>(2+3) ? 1 : 32))
+echo 1 $(( 4<(2+3) ? 1 : 32))
+echo 1 $(( (2+2)<(2+3) ? 1 : 32))
+echo 32 $(( (2+2)>(2+3) ? 1 : 32))
+
+# check that the unevaluated part of the ternary operator does not do
+# evaluation or assignment
+x=i+=2
+y=j+=2
+#ash# declare -i i=1 j=1
+ i=1
+ j=1
+echo 20 $((1 ? 20 : (x+=2)))
+#ash# echo $i,$x # ash mishandles this
+echo 30 $((0 ? (y+=2) : 30))
+#ash# echo $j,$y # ash mishandles this
+
+x=i+=2
+y=j+=2
+#ash# declare -i i=1 j=1
+ i=1
+ j=1
+echo 20 $((1 ? 20 : (x+=2)))
+#ash# echo $i,$x # ash mishandles this
+echo 30 $((0 ? (y+=2) : 30))
+#ash# echo $i,$y # ash mishandles this
+
+# check precedence of assignment vs. conditional operator
+# should be an error
+#ash# declare -i x=2
+ x=2
+#ashnote# bash reports error but continues, ash aborts - using subshell to 'emulate' bash:
+( y=$((1 ? 20 : x+=2)) )
+
+# check precedence of assignment vs. conditional operator
+#ash# declare -i x=2
+ x=2
+# ash says "line NNN: syntax error: 0 ? x+=2 : 20"
+#ash# echo 20 $((0 ? x+=2 : 20))
+
+# associativity of assignment-operator operator
+#ash# declare -i i=1 j=2 k=3
+i=1
+j=2
+k=3
+echo 6 $((i += j += k))
+echo 6,5,3 $i,$j,$k
+
+# octal, hex
+echo 263 $(( 0x100 | 007 ))
+echo 255 $(( 0xff ))
+#ash# echo 255 $(( 16#ff ))
+#ash# echo 127 $(( 16#FF/2 ))
+#ash# echo 36 $(( 8#44 ))
+
+echo 40 $(( 8 ^ 32 ))
+
+#ash# # other bases
+#ash# echo 10 $(( 16#a ))
+#ash# echo 10 $(( 32#a ))
+#ash# echo 10 $(( 56#a ))
+#ash# echo 10 $(( 64#a ))
+#ash#
+#ash# echo 10 $(( 16#A ))
+#ash# echo 10 $(( 32#A ))
+#ash# echo 36 $(( 56#A ))
+#ash# echo 36 $(( 64#A ))
+#ash#
+#ash# echo 62 $(( 64#@ ))
+#ash# echo 63 $(( 64#_ ))
+
+#ash# # weird bases (error)
+#ash# echo $(( 3425#56 ))
+
+#ash# # missing number after base
+#ash# echo 0 $(( 2# ))
+
+# these should generate errors
+( echo $(( 7 = 43 )) )
+#ash# echo $(( 2#44 ))
+( echo $(( 44 / 0 )) )
+( let 'jv += $iv' )
+( echo $(( jv += \$iv )) )
+( let 'rv = 7 + (43 * 6' )
+
+#ash# # more errors
+#ash# declare -i i
+#ash# i=0#4
+#ash# i=2#110#11
+
+((echo abc; echo def;); echo ghi)
+
+#ash# if (((4+4) + (4 + 7))); then
+#ash# echo ok
+#ash# fi
+
+#ash# (()) # make sure the null expression works OK
+
+#ash# a=(0 2 4 6)
+#ash# echo 6 $(( a[1] + a[2] ))
+#ash# echo 1 $(( (a[1] + a[2]) == a[3] ))
+#ash# (( (a[1] + a[2]) == a[3] )) ; echo 0 $?
+
+# test pushing and popping the expression stack
+unset A
+A="4 + "
+( echo A $(( ( 4 + A ) + 4 )) )
+A="3 + 5"
+echo 16 $(( ( 4 + A ) + 4 ))
+
+# badly-formed conditional expressions
+( echo $(( 4 ? : $A )) )
+( echo $(( 1 ? 20 )) )
+( echo $(( 4 ? 20 : )) )
+
+# precedence and short-circuit evaluation
+B=9
+echo 9 $B
+
+# error
+( echo $(( 0 && B=42 )); echo 9 $B )
+
+# error
+( echo $(( 1 || B=88 )); echo 9 $B )
+
+# ash mistakenly evaluates B=... below
+#ash# echo 0 $(( 0 && (B=42) ))
+echo 9 $B
+#ash# echo 0 $(( (${$} - $$) && (B=42) ))
+echo 9 $B
+#ash# echo 1 $(( 1 || (B=88) ))
+echo 9 $B
+
+
+# until command with (( )) command
+x=7
+
+echo 7 $x
+#ash# until (( x == 4 ))
+ until test "$x" = 4
+do
+ echo $x
+ x=4
+done
+
+echo 4 $x
+
+# exponentiation
+echo 32767 $(( 2**15 - 1))
+echo 32768 $(( 2**(16-1)))
+echo 131072 $(( 2**16*2 ))
+echo 2147483647 $(( 2**31-1))
+echo 1 $(( 2**0 ))
+
+# {pre,post}-{inc,dec}rement and associated errors
+
+x=4
+
+echo 4 $x
+echo 4 $(( x++ ))
+echo 5 $x
+echo 5 $(( x-- ))
+echo 4 $x
+
+echo 3 $(( --x ))
+echo 3 $x
+
+echo 4 $(( ++x ))
+echo 4 $x
+
+# bash 3.2 apparently thinks that ++7 is 7
+#ash# echo 7 $(( ++7 ))
+( echo $(( 7-- )) )
+
+( echo $(( --x=7 )) )
+( echo $(( ++x=7 )) )
+
+( echo $(( x++=7 )) )
+( echo $(( x--=7 )) )
+
+echo 4 $x
+
+echo 7 $(( +7 ))
+echo -7 $(( -7 ))
+
+# bash 3.2 apparently thinks that ++7 is 7
+#ash# echo $(( ++7 ))
+#ash# echo $(( --7 ))
+
+${THIS_SH} ./arith1.sub
+${THIS_SH} ./arith2.sub
+
+x=4
+y=7
+
+#ash# (( x=8 , y=12 ))
+ x=8
+ y=12
+echo $x $y
+
+#ash# # should be an error
+#ash# (( x=9 y=41 ))
+
+# These are errors
+unset b
+( echo $((a b)) )
+#ash# ((a b))
+
+n=42
+printf "%d\n" $n
+printf "%i\n" $n
+#ash# echo $(( 8#$(printf "%o\n" $n) ))
+printf "%u\n" $n
+#ash# echo $(( 16#$(printf "%x\n" $n) ))
+#ash# echo $(( 16#$(printf "%X\n" $n) ))
+
+# causes longjmp botches through bash-2.05b
+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 0000000..80aa999
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith1.sub
@@ -0,0 +1,40 @@
+# test of redone post-increment and post-decrement code
+( echo $(( 4-- )) )
+( echo $(( 4++ )) )
+( echo $(( 4 -- )) )
+( echo $(( 4 ++ )) )
+
+#ash# (( array[0]++ ))
+#ash# echo ${array}
+
+#ash# (( array[0] ++ ))
+#ash# echo ${array}
+
+#ash# (( a++ ))
+#ash# echo $a
+#ash# (( a ++ ))
+#ash# echo $a
+ a=2
+
+echo 6 $(( a ++ + 4 ))
+echo 3 $a
+
+echo 7 $(( a+++4 ))
+echo 4 $a
+
+echo 0 $(( a---4 ))
+echo 3 $a
+
+echo 7 $(( a -- + 4 ))
+echo 2 $a
+
+echo -2 $(( a -- - 4 ))
+echo 1 $a
+
+#ash# (( ++ + 7 ))
+
+#ash# (( ++ ))
+( echo $(( +++7 )) )
+# bash 3.2 apparently thinks that ++ +7 is 7
+#ash# echo $(( ++ + 7 ))
+#ash# (( -- ))
diff --git a/shell/ash_test/ash-arith/arith2.sub b/shell/ash_test/ash-arith/arith2.sub
new file mode 100755
index 0000000..f7e3c92
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith2.sub
@@ -0,0 +1,57 @@
+# bash 3.2 apparently thinks that ++7 is 7 etc
+( echo $(( --7 )) )
+( echo $(( ++7 )) )
+( echo $(( -- 7 )) )
+( echo $(( ++ 7 )) )
+
+#ash# ((++array[0] ))
+#ash# echo 1 $array
+#ash# (( ++ array[0] ))
+#ash# echo 2 $array
+
+#ash# (( ++a ))
+#ash# echo 1 $a
+#ash# (( ++ a ))
+#ash# echo 2 $a
+
+#ash# (( --a ))
+#ash# echo 1 $a
+#ash# (( -- a ))
+#ash# echo 0 $a
+ a=0
+
+echo 5 $(( 4 + ++a ))
+echo 1 $a
+
+# ash doesn't handle it right...
+#ash# echo 6 $(( 4+++a ))
+#ash# echo 2 $a
+ a=2
+
+# ash doesn't handle it right...
+#ash# echo 3 $(( 4---a ))
+#ash# echo 1 $a
+ a=1
+
+echo 4 $(( 4 - -- a ))
+echo 0 $a
+
+#ash# (( -- ))
+# bash 3.2 apparently thinks that ---7 is -7
+#ash# echo $(( ---7 ))
+( echo $(( -- - 7 )) )
+
+#ash# (( ++ ))
+# bash 3.2: 7
+#ash# echo 7 $(( ++7 ))
+( echo $(( ++ + 7 )) )
+
+# bash 3.2: -7
+#ash# echo -7 $(( ++-7 ))
+# bash 3.2: -7
+#ash# echo -7 $(( ++ - 7 ))
+
+# bash 3.2: 7
+#ash# echo 7 $(( +--7 ))
+# bash 3.2: 7
+#ash# echo 7 $(( -- + 7 ))
diff --git a/shell/ash_test/printenv.c b/shell/ash_test/printenv.c
new file mode 100644
index 0000000..07ea2a9
--- /dev/null
+++ b/shell/ash_test/printenv.c
@@ -0,0 +1,67 @@
+/* printenv -- minimal clone of BSD printenv(1).
+
+ usage: printenv [varname]
+
+ Chet Ramey
+ chet@po.cwru.edu
+*/
+
+/* Copyright (C) 1997-2002 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <stdlib.h>
+#include <string.h>
+
+extern char **environ;
+
+int
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ register char **envp, *eval;
+ int len;
+
+ argv++;
+ argc--;
+
+ /* printenv */
+ if (argc == 0)
+ {
+ for (envp = environ; *envp; envp++)
+ puts (*envp);
+ exit (0);
+ }
+
+ /* printenv varname */
+ len = strlen (*argv);
+ for (envp = environ; *envp; envp++)
+ {
+ if (**argv == **envp && strncmp (*envp, *argv, len) == 0)
+ {
+ eval = *envp + len;
+ /* If the environment variable doesn't have an `=', ignore it. */
+ if (*eval == '=')
+ {
+ puts (eval + 1);
+ exit (0);
+ }
+ }
+ }
+ exit (1);
+}
diff --git a/shell/ash_test/recho.c b/shell/ash_test/recho.c
new file mode 100644
index 0000000..02be0d7
--- /dev/null
+++ b/shell/ash_test/recho.c
@@ -0,0 +1,63 @@
+/*
+ recho -- really echo args, bracketed with <> and with invisible chars
+ made visible.
+
+ Chet Ramey
+ chet@po.cwru.edu
+*/
+
+/* Copyright (C) 2002-2005 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void strprint();
+
+int
+main(argc, argv)
+int argc;
+char **argv;
+{
+ register int i;
+
+ for (i = 1; i < argc; i++) {
+ printf("argv[%d] = <", i);
+ strprint(argv[i]);
+ printf(">\n");
+ }
+ exit(0);
+}
+
+void
+strprint(str)
+char *str;
+{
+ register unsigned char *s;
+
+ for (s = (unsigned char *)str; s && *s; s++) {
+ if (*s < ' ') {
+ putchar('^');
+ putchar(*s+64);
+ } else if (*s == 127) {
+ putchar('^');
+ putchar('?');
+ } else
+ putchar(*s);
+ }
+}
diff --git a/shell/ash_test/run-all b/shell/ash_test/run-all
new file mode 100755
index 0000000..ba1756e
--- /dev/null
+++ b/shell/ash_test/run-all
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+test -x ash || { echo "No ./ash?!"; exit; }
+test -x printenv || gcc -O2 -o printenv printenv.c || exit $?
+test -x recho || gcc -O2 -o recho recho.c || exit $?
+test -x zecho || gcc -O2 -o zecho zecho.c || exit $?
+
+PATH="$PWD:$PATH" # for ash and recho/zecho/printenv
+export PATH
+
+THIS_SH="$PWD/ash"
+export THIS_SH
+
+do_test()
+{
+ test -d "$1" || return 0
+ (
+ cd "$1" || { echo "cannot cd $1!"; exit 1; }
+ for x in run-*; do
+ test -f "$x" || continue
+ case "$x" in
+ "$0"|run-minimal|run-gprof) ;;
+ *.orig|*~) ;;
+ #*) echo $x ; sh $x ;;
+ *)
+ sh "$x" >"../$1-$x.fail" 2>&1 && \
+ { echo "$1/$x: ok"; rm "../$1-$x.fail"; } || echo "$1/$x: fail";
+ ;;
+ esac
+ done
+ # Many bash run-XXX scripts just do this,
+ # no point in duplication it all over the place
+ for x in *.tests; do
+ test -x "$x" || continue
+ name="${x%%.tests}"
+ test -f "$name.right" || continue
+ {
+ "$THIS_SH" "./$x" >"$name.xx" 2>&1
+ diff -u "$name.xx" "$name.right" >"../$1-$x.fail" && rm -f "$name.xx" "../$1-$x.fail"
+ } && echo "$1/$x: ok" || echo "$1/$x: fail"
+ done
+ )
+}
+
+# main part of this script
+# Usage: run-all [directories]
+
+if [ $# -lt 1 ]; then
+ # All sub directories
+ modules=`ls -d ash-*`
+
+ for module in $modules; do
+ do_test $module
+ done
+else
+ while [ $# -ge 1 ]; do
+ if [ -d $1 ]; then
+ do_test $1
+ fi
+ shift
+ done
+fi
diff --git a/shell/ash_test/zecho.c b/shell/ash_test/zecho.c
new file mode 100644
index 0000000..621d06d
--- /dev/null
+++ b/shell/ash_test/zecho.c
@@ -0,0 +1,39 @@
+/* zecho - bare-bones echo */
+
+/* Copyright (C) 1996-2002 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(argc, argv)
+int argc;
+char **argv;
+{
+ argv++;
+
+ while (*argv) {
+ (void)printf("%s", *argv);
+ if (*++argv)
+ putchar(' ');
+ }
+
+ putchar('\n');
+ exit(0);
+}