Add tests for dynamically invoked break and continue

This commit is contained in:
ridiculousfish 2021-10-25 12:43:30 -07:00
parent cb79548c49
commit ec244c3975
2 changed files with 29 additions and 0 deletions

View File

@ -271,6 +271,7 @@ static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &strea
}
// Paranoia: ensure we have a real loop.
// This is checked in the AST but we may be invoked dynamically, e.g. just via "eval break".
bool has_loop = false;
for (const auto &b : parser.blocks()) {
if (b.type() == block_type_t::while_block || b.type() == block_type_t::for_block) {

View File

@ -406,6 +406,34 @@ while contains $i a
end
#CHECK: Doop
# break and continue may be dynamically invoked.
set dyn_break break
set dyn_continue continue
while true
$dyn_break
echo "I should be unreachable"
end
for foo in 1 2 3
$dyn_continue
echo "I should be unreachable"
end
# Check that these error correctly.
# Simplify __fish_print_help, as it's noisy.
function __fish_print_help
echo $argv[2..]
end
$dyn_break
eval break
#CHECKERR: break: Not inside of loop
#CHECKERR: break: Not inside of loop
$dyn_continue
eval continue
#CHECKERR: continue: Not inside of loop
#CHECKERR: continue: Not inside of loop
# Test implicit cd. This should do nothing.
./