mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/fix-assert-cond-twice'
* origin/topic/awelzel/fix-assert-cond-twice:
Stmt: Fix assert evaluating cond twice
(cherry picked from commit 6867eda621
)
This commit is contained in:
parent
1d381b264b
commit
6b6942f9b2
4 changed files with 36 additions and 1 deletions
|
@ -1644,7 +1644,7 @@ ValPtr AssertStmt::Exec(Frame* f, StmtFlowType& flow) {
|
||||||
bool run_result_hook = assertion_result_hook && assertion_result_hook->HasEnabledBodies();
|
bool run_result_hook = assertion_result_hook && assertion_result_hook->HasEnabledBodies();
|
||||||
auto assert_result = cond->Eval(f)->AsBool();
|
auto assert_result = cond->Eval(f)->AsBool();
|
||||||
|
|
||||||
if ( ! cond->Eval(f)->AsBool() || run_result_hook ) {
|
if ( ! assert_result || run_result_hook ) {
|
||||||
zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString();
|
zeek::StringValPtr msg_val = zeek::val_mgr->EmptyString();
|
||||||
|
|
||||||
if ( msg ) {
|
if ( msg ) {
|
||||||
|
|
1
testing/btest/Baseline/language.assert-hook-8/.stderr
Normal file
1
testing/btest/Baseline/language.assert-hook-8/.stderr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
6
testing/btest/Baseline/language.assert-hook-8/out
Normal file
6
testing/btest/Baseline/language.assert-hook-8/out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
zeek_init
|
||||||
|
returning true
|
||||||
|
assertion_result, T, always_true(), always true, <...>/assert-hook.zeek, 23
|
||||||
|
returning false
|
||||||
|
assertion_result, F, always_false(), always false, <...>/assert-hook.zeek, 24
|
|
@ -196,3 +196,31 @@ event zeek_done()
|
||||||
assert 2 + 2 == 5, "this is false";
|
assert 2 + 2 == 5, "this is false";
|
||||||
print "not reached";
|
print "not reached";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TEST-START-NEXT
|
||||||
|
# Ensure cond is only evaluated once.
|
||||||
|
hook assertion_result(result: bool, cond: string, msg: string, bt: Backtrace)
|
||||||
|
{
|
||||||
|
print "assertion_result", result, cond, msg, bt[0]$file_location, bt[0]$line_location;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
function always_true(): bool
|
||||||
|
{
|
||||||
|
print "returning true";
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
function always_false(): bool
|
||||||
|
{
|
||||||
|
print "returning false";
|
||||||
|
return F;
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
print "zeek_init";
|
||||||
|
assert always_true(), "always true";
|
||||||
|
assert always_false(), "always false";
|
||||||
|
print "not reached";
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue