diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-10 23:23:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-10 23:23:41 +0000 |
commit | ce4acbbab664e9ab3432189f88b525f10553f674 (patch) | |
tree | d845cf76877865eaa332338bf689f65dda3b1794 | |
parent | 6ba6f546ac8016a3acccb19b2eff8b6878a3a87c (diff) | |
download | busybox-w32-ce4acbbab664e9ab3432189f88b525f10553f674.tar.gz busybox-w32-ce4acbbab664e9ab3432189f88b525f10553f674.tar.bz2 busybox-w32-ce4acbbab664e9ab3432189f88b525f10553f674.zip |
hush: add function tests
-rw-r--r-- | shell/hush.c | 38 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/func1.right | 6 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/func1.tests | 16 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/func2.right | 5 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/func2.tests | 9 | ||||
-rwxr-xr-x | shell/hush_test/hush-z_slow/leak_all1.tests | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-z_slow/leak_all2.tests | 6 |
7 files changed, 65 insertions, 19 deletions
diff --git a/shell/hush.c b/shell/hush.c index 40fcb7be4..a055ec14f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * "small and simple is beautiful" philosophy, which | 5 | * "small and simple is beautiful" philosophy, which |
6 | * incidentally is a good match to today's BusyBox. | 6 | * incidentally is a good match to today's BusyBox. |
7 | * | 7 | * |
8 | * Copyright (C) 2000,2001 Larry Doolittle <larry@doolittle.boa.org> | 8 | * Copyright (C) 2000,2001 Larry Doolittle <larry@doolittle.boa.org> |
9 | * Copyright (C) 2008,2009 Denys Vlasenko <vda.linux@googlemail.com> | 9 | * Copyright (C) 2008,2009 Denys Vlasenko <vda.linux@googlemail.com> |
10 | * | 10 | * |
11 | * Credits: | 11 | * Credits: |
@@ -68,7 +68,7 @@ | |||
68 | #include <glob.h> | 68 | #include <glob.h> |
69 | /* #include <dmalloc.h> */ | 69 | /* #include <dmalloc.h> */ |
70 | #if ENABLE_HUSH_CASE | 70 | #if ENABLE_HUSH_CASE |
71 | #include <fnmatch.h> | 71 | # include <fnmatch.h> |
72 | #endif | 72 | #endif |
73 | #include "math.h" | 73 | #include "math.h" |
74 | #include "match.h" | 74 | #include "match.h" |
@@ -100,31 +100,31 @@ | |||
100 | 100 | ||
101 | #if defined SINGLE_APPLET_MAIN | 101 | #if defined SINGLE_APPLET_MAIN |
102 | /* STANDALONE does not make sense, and won't compile */ | 102 | /* STANDALONE does not make sense, and won't compile */ |
103 | #undef CONFIG_FEATURE_SH_STANDALONE | 103 | # undef CONFIG_FEATURE_SH_STANDALONE |
104 | #undef ENABLE_FEATURE_SH_STANDALONE | 104 | # undef ENABLE_FEATURE_SH_STANDALONE |
105 | #undef USE_FEATURE_SH_STANDALONE | 105 | # undef USE_FEATURE_SH_STANDALONE |
106 | #define SKIP_FEATURE_SH_STANDALONE(...) __VA_ARGS__ | 106 | # define SKIP_FEATURE_SH_STANDALONE(...) __VA_ARGS__ |
107 | #define ENABLE_FEATURE_SH_STANDALONE 0 | 107 | # define ENABLE_FEATURE_SH_STANDALONE 0 |
108 | #define USE_FEATURE_SH_STANDALONE(...) | 108 | # define USE_FEATURE_SH_STANDALONE(...) |
109 | #define SKIP_FEATURE_SH_STANDALONE(...) __VA_ARGS__ | 109 | # define SKIP_FEATURE_SH_STANDALONE(...) __VA_ARGS__ |
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | #if !ENABLE_HUSH_INTERACTIVE | 112 | #if !ENABLE_HUSH_INTERACTIVE |
113 | #undef ENABLE_FEATURE_EDITING | 113 | # undef ENABLE_FEATURE_EDITING |
114 | #define ENABLE_FEATURE_EDITING 0 | 114 | # define ENABLE_FEATURE_EDITING 0 |
115 | #undef ENABLE_FEATURE_EDITING_FANCY_PROMPT | 115 | # undef ENABLE_FEATURE_EDITING_FANCY_PROMPT |
116 | #define ENABLE_FEATURE_EDITING_FANCY_PROMPT 0 | 116 | # define ENABLE_FEATURE_EDITING_FANCY_PROMPT 0 |
117 | #endif | 117 | #endif |
118 | 118 | ||
119 | /* Do we support ANY keywords? */ | 119 | /* Do we support ANY keywords? */ |
120 | #if ENABLE_HUSH_IF || ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE | 120 | #if ENABLE_HUSH_IF || ENABLE_HUSH_LOOPS || ENABLE_HUSH_CASE |
121 | #define HAS_KEYWORDS 1 | 121 | # define HAS_KEYWORDS 1 |
122 | #define IF_HAS_KEYWORDS(...) __VA_ARGS__ | 122 | # define IF_HAS_KEYWORDS(...) __VA_ARGS__ |
123 | #define IF_HAS_NO_KEYWORDS(...) | 123 | # define IF_HAS_NO_KEYWORDS(...) |
124 | #else | 124 | #else |
125 | #define HAS_KEYWORDS 0 | 125 | # define HAS_KEYWORDS 0 |
126 | #define IF_HAS_KEYWORDS(...) | 126 | # define IF_HAS_KEYWORDS(...) |
127 | #define IF_HAS_NO_KEYWORDS(...) __VA_ARGS__ | 127 | # define IF_HAS_NO_KEYWORDS(...) __VA_ARGS__ |
128 | #endif | 128 | #endif |
129 | 129 | ||
130 | /* If you comment out one of these below, it will be #defined later | 130 | /* If you comment out one of these below, it will be #defined later |
diff --git a/shell/hush_test/hush-misc/func1.right b/shell/hush_test/hush-misc/func1.right new file mode 100644 index 000000000..e21665aaf --- /dev/null +++ b/shell/hush_test/hush-misc/func1.right | |||
@@ -0,0 +1,6 @@ | |||
1 | Hello | ||
2 | Zero: 0 | ||
3 | One: 1 Param1: World | ||
4 | Zero: 0 Param1: Restored | ||
5 | Multi line function | ||
6 | One: 1 | ||
diff --git a/shell/hush_test/hush-misc/func1.tests b/shell/hush_test/hush-misc/func1.tests new file mode 100755 index 000000000..ffb269fad --- /dev/null +++ b/shell/hush_test/hush-misc/func1.tests | |||
@@ -0,0 +1,16 @@ | |||
1 | f() { echo Hello; } | ||
2 | g () { echo One: $# Param1: $1; } | ||
3 | h ( ) | ||
4 | { | ||
5 | echo -n 'Multi ' && echo -n 'line ' | ||
6 | echo function | ||
7 | false | ||
8 | } | ||
9 | |||
10 | f | ||
11 | echo Zero: $? | ||
12 | set -- Restored | ||
13 | { g World; } | ||
14 | echo Zero: $? Param1: $1 | ||
15 | ( h ) | ||
16 | echo One: $? | ||
diff --git a/shell/hush_test/hush-misc/func2.right b/shell/hush_test/hush-misc/func2.right new file mode 100644 index 000000000..f2a041da7 --- /dev/null +++ b/shell/hush_test/hush-misc/func2.right | |||
@@ -0,0 +1,5 @@ | |||
1 | First 0 | ||
2 | Second 0 | ||
3 | First 1 | ||
4 | Second 1 | ||
5 | Done | ||
diff --git a/shell/hush_test/hush-misc/func2.tests b/shell/hush_test/hush-misc/func2.tests new file mode 100755 index 000000000..763203f15 --- /dev/null +++ b/shell/hush_test/hush-misc/func2.tests | |||
@@ -0,0 +1,9 @@ | |||
1 | i=0 | ||
2 | while test $i != 2; do | ||
3 | f() { echo First $i; } | ||
4 | f | ||
5 | f() { echo Second $i; } | ||
6 | f | ||
7 | : $((i++)) | ||
8 | done | ||
9 | echo Done | ||
diff --git a/shell/hush_test/hush-z_slow/leak_all1.tests b/shell/hush_test/hush-z_slow/leak_all1.tests index b26e2df02..d244744a6 100755 --- a/shell/hush_test/hush-z_slow/leak_all1.tests +++ b/shell/hush_test/hush-z_slow/leak_all1.tests | |||
@@ -27,6 +27,8 @@ HERE | |||
27 | { : /bin/*; } | 27 | { : /bin/*; } |
28 | set -- par1_$i par2_$i par3_$i par4_$i | 28 | set -- par1_$i par2_$i par3_$i par4_$i |
29 | trap "echo trap$i" WINCH | 29 | trap "echo trap$i" WINCH |
30 | f() { echo $1; } | ||
31 | f >/dev/null | ||
30 | : $((i++)) | 32 | : $((i++)) |
31 | done | 33 | done |
32 | 34 | ||
@@ -55,6 +57,8 @@ HERE | |||
55 | { : /bin/*; } | 57 | { : /bin/*; } |
56 | set -- par1_$i par2_$i par3_$i par4_$i | 58 | set -- par1_$i par2_$i par3_$i par4_$i |
57 | trap "echo trap$i" WINCH | 59 | trap "echo trap$i" WINCH |
60 | f() { echo $1; } | ||
61 | f >/dev/null | ||
58 | : $((i++)) | 62 | : $((i++)) |
59 | done | 63 | done |
60 | 64 | ||
diff --git a/shell/hush_test/hush-z_slow/leak_all2.tests b/shell/hush_test/hush-z_slow/leak_all2.tests index 8fb1ca9b4..d51ea8063 100755 --- a/shell/hush_test/hush-z_slow/leak_all2.tests +++ b/shell/hush_test/hush-z_slow/leak_all2.tests | |||
@@ -27,6 +27,8 @@ HERE | |||
27 | } 1<>/dev/null | 27 | } 1<>/dev/null |
28 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done | 28 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done |
29 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null | 29 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null |
30 | f() { echo $1; } | ||
31 | f >/dev/null | ||
30 | 32 | ||
31 | memleak | 33 | memleak |
32 | 34 | ||
@@ -53,6 +55,8 @@ HERE | |||
53 | } 1<>/dev/null | 55 | } 1<>/dev/null |
54 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done | 56 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done |
55 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null | 57 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null |
58 | f() { echo $1; } | ||
59 | f >/dev/null | ||
56 | 60 | ||
57 | # And same again | 61 | # And same again |
58 | 62 | ||
@@ -77,6 +81,8 @@ HERE | |||
77 | } 1<>/dev/null | 81 | } 1<>/dev/null |
78 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done | 82 | while { echo $dev_null >>$dev_null; }; do cat <"$dev_null"; break; done |
79 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null | 83 | ( until { echo $dev_null >>$dev_null | false; }; do cat <"$dev_null"; break; done ) <$dev_null |
84 | f() { echo $1; } | ||
85 | f >/dev/null | ||
80 | 86 | ||
81 | memleak | 87 | memleak |
82 | kb=$? | 88 | kb=$? |