mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 00:22:48 +08:00
Add tests for dynamically invoked break and continue
This commit is contained in:
parent
cb79548c49
commit
ec244c3975
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
./
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user