Merge remote-tracking branch 'origin/topic/awelzel/2285-assert-statement'

* origin/topic/awelzel/2285-assert-statement:
  NEWS: Small section about assert statement
  Stmt: Rework assertion hooks break semantics
  Stmt: Introduce assert statement and related hooks
  ZeekArgs: Helper for empty arguments
  Reporter: Allow AssertStmt to throw InterpreterException
  Lift backtrace() code into Func.{h,cc}
This commit is contained in:
Arne Welzel 2023-06-14 12:51:08 +02:00
commit 2f1ea789d1
50 changed files with 783 additions and 47 deletions

View file

@ -942,6 +942,45 @@ type BacktraceElement: record {
## .. zeek:see:: backtrace print_backtrace
type Backtrace: vector of BacktraceElement;
## A hook that is invoked when an assert statement fails.
##
## By default, a reporter error message is logged describing the failing
## assert similarly to how scripting errors are reported after invoking
## this hook. Using the :zeek:see:`break` statement in an assertion_failure
## hook handler allows to suppress this message.
##
## cond: The string representation of the condition.
##
## msg: Evaluated message as string given to the assert statement.
##
## bt: Backtrace of the assertion error. The top element will contain
## the location of the assert statement that failed.
##
## .. zeek:see:: assertion_result
type assertion_failure: hook(cond: string, msg: string, bt: Backtrace);
## A hook that is invoked with the result of every assert statement.
##
## This is a potentially expensive hook meant to be used by testing
## frameworks to summarize assert results. In a production setup,
## this hook is likely detrimental to performance.
##
## Using the :zeek:see:`break` statement within an assertion_failure hook
## handler allows to suppress the reporter error message generated for
## failing assert statements.
##
## result: The result of evaluating **cond**.
##
## cond: The string representation of the condition.
##
## msg: Evaluated message as string given to the assert statement.
##
## bt: Backtrace of the assertion error. The top element will contain
## the location of the assert statement that failed.
##
## .. zeek:see:: assertion_failure
type assertion_result: hook(result: bool, cond: string, msg: string, bt: Backtrace);
# todo:: Do we still need these here? Can they move into the packet filter
# framework?
#