From 29ddb68da428804148a0c6f44229cf1848bebf8c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 12 Feb 2014 01:39:06 -0800 Subject: [PATCH] Tests and fix to allow return to work correctly within if statements. Closes #1297. --- parse_execution.cpp | 6 ++++++ tests/test1.in | 9 +++++++++ tests/test1.out | 1 + 3 files changed, 16 insertions(+) diff --git a/parse_execution.cpp b/parse_execution.cpp index 08f222ed7..11aa5325f 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -325,6 +325,12 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse { run_job_list(*job_list_to_execute, ib); } + + /* It's possible there's a last-minute cancellation, in which case we should not stomp the exit status (#1297) */ + if (should_cancel_execution(ib)) + { + result = parse_execution_cancelled; + } /* Done */ parser->pop_block(ib); diff --git a/tests/test1.in b/tests/test1.in index 7f60a4dad..529baea1c 100644 --- a/tests/test1.in +++ b/tests/test1.in @@ -121,3 +121,12 @@ echo -e Catch your breath echo -e 'abc\x21def' echo -e 'abc\x211def' + +function always_fails + if true + return 1 + end +end + +always_fails ; echo $status + diff --git a/tests/test1.out b/tests/test1.out index b3460cdde..893e0464c 100644 --- a/tests/test1.out +++ b/tests/test1.out @@ -36,3 +36,4 @@ abc Catch your breath abc!def abc!1def +1