aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-02-07 17:56:40 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-02-07 17:57:53 -0800
commite632d39b1f627773b29f7934d7d79545af75e47f (patch)
tree2222b1a5364128f8e7812ecbbc33f310ba59c6dd
parent09054a09fa8aef98229ea132f9043ead7f7e1e0e (diff)
Make if statements always return success at the end, matching other
shells. Fixes #1061.
-rw-r--r--builtin.cpp4
-rw-r--r--parse_execution.cpp6
-rw-r--r--tests/test8.in4
-rw-r--r--tests/test8.out2
4 files changed, 16 insertions, 0 deletions
diff --git a/builtin.cpp b/builtin.cpp
index 81738ffb..fb5fbeb4 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -3773,6 +3773,10 @@ static int builtin_end(parser_t &parser, wchar_t **argv)
}
case IF:
+ /* Always return success (#1061) */
+ proc_set_last_status(0);
+ break;
+
case SUBST:
case BEGIN:
case SWITCH:
diff --git a/parse_execution.cpp b/parse_execution.cpp
index 68a27b4d..d0d8336b 100644
--- a/parse_execution.cpp
+++ b/parse_execution.cpp
@@ -306,6 +306,12 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse
/* Done */
parser->pop_block(ib);
+ /* Issue 1061: If we executed, then always report success, instead of letting the exit status of the last command linger */
+ if (result == parse_execution_success)
+ {
+ proc_set_last_status(STATUS_BUILTIN_OK);
+ }
+
return result;
}
diff --git a/tests/test8.in b/tests/test8.in
index c3c73384..a31ad127 100644
--- a/tests/test8.in
+++ b/tests/test8.in
@@ -23,3 +23,7 @@ echo (seq $n)[3..5 -2..2]
echo Test more
echo $test[(count $test)..1]
echo $test[1..(count $test)]
+
+# See issue 1061
+echo "Verify that if statements swallow failure"
+if false ; end ; echo $status
diff --git a/tests/test8.out b/tests/test8.out
index 72af9bb8..4ac13406 100644
--- a/tests/test8.out
+++ b/tests/test8.out
@@ -15,3 +15,5 @@ Test command substitution
Test more
10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10
+Verify that if statements swallow failure
+0