zeek/testing/btest/language/next-break-context-errors.zeek
Arne Welzel 850aaaa5a8 parse.y: Traverse AST post parsing to detect break/next usage issues
Seemed easiest to do it via the traversal infrastructure as we do not
otherwise track enough context/scope when instantiating break or next
statements.

Might be worth moving this out of src/parse.y, but didn't exactly know
where. Or maybe we wait until there's more such trivial validations
popping up

Fixes #2440
2022-10-28 12:53:37 +02:00

85 lines
988 B
Text

# @TEST-DOC: Check break and next usage within for, while, switch and hooks.
# @TEST-EXEC-FAIL: zeek -b %INPUT
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
function f()
{
next;
}
event zeek_init() { f(); };
@TEST-START-NEXT
function f()
{
break;
}
event zeek_init() { f(); };
@TEST-START-NEXT
event zeek_init()
{
next;
}
@TEST-START-NEXT
event zeek_init()
{
break;
}
@TEST-START-NEXT
event zeek_init()
{
if ( T )
break;
}
@TEST-START-NEXT
event zeek_init()
{
local history = "Sr";
switch history {
case "S":
print history;
next;
break;
}
}
@TEST-START-NEXT
global the_hook: hook(c: count);
hook the_hook(c: count)
{
next;
}
@TEST-START-NEXT
global the_hook: hook(c: count);
hook the_hook(c: count)
{
if ( T )
next;
}
@TEST-START-NEXT
# Should report 3 errors.
global the_hook: hook(c: count);
hook the_hook(c: count)
{
next;
}
event zeek_init()
{
break;
}
event zeek_init()
{
next;
}