[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: hust test for noMMU
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2009-05-23 14:52:24
Message-ID: 200905231652.25026.vda.linux () googlemail ! com
[Download RAW message or body]
On Friday 22 May 2009 00:05, Mike Frysinger wrote:
> On Thursday 21 May 2009 08:39:07 Michal Simek wrote:
> > Hi All,
> >
> > I am doing some tests with hush because I would like to run LTP tests on
> > noMMU Microblaze kernel (and use runltp script). I copied all hush tests to
> > rootfs and run them but I am getting this error.
> >
> > /test/hush_test # ./run-all
> > No ./hush - creating a link to ../../busybox
> > ln: hush: File exists
> > sh: hush.c:5855
> > sh: syntax error: unexpected )
>
> hush currently doesnt support case statements nested in subshells:
> $ hush -c '(case m in m) :;; esac)'
> the parser needs a state machine tweak to handle the case syntax. fwiw, bash
> has had many bugs along these same lines :).
Fix is attached. It also fixes
case esac in "esac") echo OK;; esac
case. :)
--
vda
["9.patch" (text/x-diff)]
diff -d -urpN busybox.8/shell/hush.c busybox.9/shell/hush.c
--- busybox.8/shell/hush.c 2009-05-20 12:20:48.000000000 +0200
+++ busybox.9/shell/hush.c 2009-05-23 16:50:53.000000000 +0200
@@ -192,9 +192,10 @@ typedef enum reserved_style {
#endif
#if ENABLE_HUSH_CASE
RES_CASE ,
- /* two pseudo-keywords support contrived "case" syntax: */
- RES_MATCH , /* "word)" */
- RES_CASEI , /* "this command is inside CASE" */
+ /* three pseudo-keywords support contrived "case" syntax: */
+ RES_CASE_IN, /* "case ... IN", turns into RES_MATCH when IN is observed */
+ RES_MATCH , /* "word)" */
+ RES_CASE_BODY, /* "this command is inside CASE" */
RES_ESAC ,
#endif
RES_XXXX ,
@@ -3766,8 +3767,9 @@ static void debug_print_tree(struct pipe
#endif
#if ENABLE_HUSH_CASE
[RES_CASE ] = "CASE" ,
+ [RES_CASE_IN ] = "CASE_IN" ,
[RES_MATCH] = "MATCH",
- [RES_CASEI] = "CASEI",
+ [RES_CASE_BODY] = "CASE_BODY",
[RES_ESAC ] = "ESAC" ,
#endif
[RES_XXXX ] = "XXXX" ,
@@ -4011,7 +4013,7 @@ static int run_list(struct pipe *pi)
}
continue;
}
- if (rword == RES_CASEI) { /* inside of a case branch */
+ if (rword == RES_CASE_BODY) { /* inside of a case branch */
if (cond_code != 0)
continue; /* not matched yet, skip this pipe */
}
@@ -4252,7 +4254,9 @@ static void done_pipe(struct parse_conte
#endif
#if ENABLE_HUSH_CASE
if (ctx->ctx_res_w == RES_MATCH)
- ctx->ctx_res_w = RES_CASEI;
+ ctx->ctx_res_w = RES_CASE_BODY;
+ if (ctx->ctx_res_w == RES_CASE)
+ ctx->ctx_res_w = RES_CASE_IN;
#endif
ctx->command = NULL; /* trick done_command below */
/* Create the memory for command, roughly:
@@ -4366,10 +4370,10 @@ static int reserved_word(o_string *word,
debug_printf("found reserved word %s, res %d\n", r->literal, r->res);
#if ENABLE_HUSH_CASE
- if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE)
- /* "case word IN ..." - IN part starts first match part */
+ if (r->res == RES_IN && ctx->ctx_res_w == RES_CASE_IN) {
+ /* "case word IN ..." - IN part starts first MATCH part */
r = &reserved_match;
- else
+ } else
#endif
if (r->flag == 0) { /* '!' */
if (ctx->ctx_inverted) { /* bash doesn't accept '! ! true' */
@@ -4495,6 +4499,9 @@ static int done_word(o_string *word, str
&& ctx->ctx_res_w != RES_FOR /* ...not after FOR or IN */
&& ctx->ctx_res_w != RES_IN
# endif
+# if ENABLE_HUSH_CASE
+ && ctx->ctx_res_w != RES_CASE
+# endif
) {
debug_printf_parse("checking '%s' for reserved-ness\n", word->data);
if (reserved_word(word, ctx)) {
@@ -5578,7 +5585,13 @@ static struct pipe *parse_stream(char **
}
if (end_trigger && end_trigger == ch
- && (heredoc_cnt == 0 || end_trigger != ';')
+ && (ch != ';' || heredoc_cnt == 0)
+#if ENABLE_HUSH_CASE
+ && (ch != ')'
+ || ctx.ctx_res_w != RES_MATCH
+ || (!dest.o_quoted && strcmp(dest.data, "esac") == 0)
+ )
+#endif
) {
if (heredoc_cnt) {
/* This is technically valid:
@@ -5784,7 +5797,7 @@ static struct pipe *parse_stream(char **
break;
ch = i_getch(input);
nommu_addchr(&ctx.as_string, ch);
- if (ctx.ctx_res_w == RES_CASEI) {
+ if (ctx.ctx_res_w == RES_CASE_BODY) {
ctx.ctx_dsemicolon = 1;
ctx.ctx_res_w = RES_MATCH;
break;
diff -d -urpN busybox.8/shell/hush_test/hush-misc/case1.right \
busybox.9/shell/hush_test/hush-misc/case1.right
--- busybox.8/shell/hush_test/hush-misc/case1.right 2009-05-13 23:48:24.000000000 \
+0200
+++ busybox.9/shell/hush_test/hush-misc/case1.right 2009-05-23 16:50:53.000000000 \
+0200 @@ -12,3 +12,11 @@ OK_44
OK_51
OK_52
OK_53
+OK_sub1
+OK_sub2
+OK_sub3
+OK_sub4
+OK_sub5
+OK_sub6
+OK_esac1
+Done
diff -d -urpN busybox.8/shell/hush_test/hush-misc/case1.tests \
busybox.9/shell/hush_test/hush-misc/case1.tests
--- busybox.8/shell/hush_test/hush-misc/case1.tests 2009-05-23 11:06:36.000000000 \
+0200
+++ busybox.9/shell/hush_test/hush-misc/case1.tests 2009-05-23 16:50:53.000000000 \
+0200 @@ -25,13 +25,16 @@ case w in `echo w`) echo OK_51;; `echo W
case w in `echo OK_52 >&2`) echo SKIP;; `echo`w) echo OK_53;; esac;
# parsing cases in subshells can easily get messy
- case m in m) echo ok-sub1;; esac
- case m in (m) echo ok-sub2;; esac
-(case m in m) echo ok-sub3;; esac)
-(case m in (m) echo ok-sub4;; esac)
+ case m in m) echo OK_sub1;; esac
+ case m in (m) echo OK_sub2;; esac
+(case m in m) echo OK_sub3;; esac)
+(case m in (m) echo OK_sub4;; esac)
(
- case m in m) echo ok-sub5;; esac
+ case m in m) echo OK_sub5;; esac
)
(
- case m in (m) echo ok-sub6;; esac
+ case m in (m) echo OK_sub6;; esac
)
+(case esac in "esac") echo OK_esac1;; esac)
+
+echo Done
diff -d -urpN busybox.8/shell/hush_test/hush-vars/unset.right \
busybox.9/shell/hush_test/hush-vars/unset.right
--- busybox.8/shell/hush_test/hush-vars/unset.right 2009-05-23 11:06:36.000000000 \
+0200
+++ busybox.9/shell/hush_test/hush-vars/unset.right 2009-05-23 16:50:53.000000000 \
+0200 @@ -1,5 +1,5 @@
0
-unset: invalid option -- 'm'
+unset: invalid option -- m
1
0
___
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic