simplified "assert" by not trying to catch messages that themselves have errors

This commit is contained in:
Vern Paxson 2024-12-02 10:37:10 -08:00
parent a2a47ba334
commit 05e913db1b
6 changed files with 17 additions and 31 deletions

View file

@ -1,4 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
expression error in <...>/assert.zeek, line 10: field value missing (r$b)
error in <...>/assert.zeek, line 10: assertion failure: r?$b (<error eval fmt("r$b is not set trying anyway: %s", r$b)>)
expression error in <...>/assert.zeek, line 12: field value missing (r$b)
fatal error: errors occurred while initializing

View file

@ -1,5 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
expression error in <...>/assert-hook.zeek, line 15: field value missing (get_current_packet_header()$ip)
expression error in <...>/assert-hook.zeek, line 17: field value missing (get_current_packet_header()$ip)
error in <...>/assert-hook.zeek, line 17: assertion failure: 2 + 2 == 5 (<error eval cat(get_current_packet_header()$ip)>)
error in <...>/assert-hook.zeek, line 22: assertion failure: 2 + 2 == 5 ({"msg":"false and works"})
expression error in <...>/assert-hook.zeek, line 18: field value missing (get_current_packet_header()$ip)
error in <...>/assert-hook.zeek, line 24: assertion failure: 2 + 2 == 5 ({"msg":"false and works"})

View file

@ -1,7 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
assertion_result, T, 2 + 2 == 4, <error eval cat(get_current_packet_header()$ip)>, <...>/assert-hook.zeek, 15
assertion_result, T, 2 + 2 == 4, {"msg":"true and works"}, <...>/assert-hook.zeek, 16
assertion_result, F, 2 + 2 == 5, <error eval cat(get_current_packet_header()$ip)>, <...>/assert-hook.zeek, 17
assertion_failure, 2 + 2 == 5, <error eval cat(get_current_packet_header()$ip)>, <...>/assert-hook.zeek, 17
assertion_result, F, 2 + 2 == 5, {"msg":"false and works"}, <...>/assert-hook.zeek, 22
assertion_failure, 2 + 2 == 5, {"msg":"false and works"}, <...>/assert-hook.zeek, 22
assertion_result, T, 2 + 2 == 4, {"msg":"true and works"}, <...>/assert-hook.zeek, 15
assertion_result, F, 2 + 2 == 5, {"msg":"false and works"}, <...>/assert-hook.zeek, 24
assertion_failure, 2 + 2 == 5, {"msg":"false and works"}, <...>/assert-hook.zeek, 24

View file

@ -164,9 +164,11 @@ hook assertion_result(result: bool, cond: string, msg: string, bt: Backtrace)
event zeek_init()
{
assert 2 + 2 == 4, cat(get_current_packet_header()$ip);
assert 2 + 2 == 4, to_json([$msg="true and works"]);
assert 2 + 2 == 5, cat(get_current_packet_header()$ip);
# This next assert will generate a run-time error, exiting the
# event handler.
assert 2 + 2 == 4, cat(get_current_packet_header()$ip);
assert 2 + 2 == 5, "didn't get to here";
}
event zeek_done()

View file

@ -69,6 +69,8 @@ event zeek_init()
{
local r: MyRecord = [$a=1234];
assert ! r?$b, fmt("Unexpected r$b is set to %s", r$b);
# This will generate a run-time error, rather than reporting the
# failed assertion.
assert r?$b, fmt("r$b is not set trying anyway: %s", r$b);
}