hush: fix "while false; ..." exitcode; add testsuites
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 28 Jul 2008 23:17:31 +0000 (23:17 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 28 Jul 2008 23:17:31 +0000 (23:17 -0000)
shell/hush.c
shell/hush_test/hush-misc/break4.right [new file with mode: 0644]
shell/hush_test/hush-misc/break4.tests [new file with mode: 0755]
shell/hush_test/hush-misc/while1.right [new file with mode: 0644]
shell/hush_test/hush-misc/while1.tests [new file with mode: 0755]

index a74fe473045b9a3ca09d9ec5b89e1e6657f4ca94..5b2f188cd08c084cc181bb6b635a16b1150e565f 100644 (file)
@@ -2305,8 +2305,10 @@ static int run_list(struct pipe *pi)
 #endif
 #if ENABLE_HUSH_LOOPS
                if (rword == RES_WHILE) {
-                       if (rcode)
+                       if (rcode) {
+                               rcode = 0; /* "while false; do...done" - exitcode 0 */
                                goto check_jobs_and_break;
+                       }
                }
                if (rword == RES_UNTIL) {
                        if (!rcode) {
diff --git a/shell/hush_test/hush-misc/break4.right b/shell/hush_test/hush-misc/break4.right
new file mode 100644 (file)
index 0000000..6f41c14
--- /dev/null
@@ -0,0 +1,6 @@
+A
+AA
+TRUE
+A
+AA
+OK:0
diff --git a/shell/hush_test/hush-misc/break4.tests b/shell/hush_test/hush-misc/break4.tests
new file mode 100755 (executable)
index 0000000..67da288
--- /dev/null
@@ -0,0 +1,12 @@
+cond=true
+while $cond; do
+    echo A
+    if test "$cond" = true; then
+       cond='echo TRUE'
+    else
+       cond=false
+    fi
+    while true; do echo AA; continue 2; echo BB; done
+    echo B
+done
+echo OK:$?
diff --git a/shell/hush_test/hush-misc/while1.right b/shell/hush_test/hush-misc/while1.right
new file mode 100644 (file)
index 0000000..7c4d7be
--- /dev/null
@@ -0,0 +1 @@
+OK:0
diff --git a/shell/hush_test/hush-misc/while1.tests b/shell/hush_test/hush-misc/while1.tests
new file mode 100755 (executable)
index 0000000..11e201e
--- /dev/null
@@ -0,0 +1,2 @@
+while false; do echo NOT SHOWN; done
+echo OK:$?