NAME
TB2::AssertStack - A stack of where asserts were called
SYNOPSIS
use TB2::AssertRecord;
use TB2::AssertStack;
my $stack = TB2::AssertStack->new;
my $record = TB2::AssertRecord->new_from_caller(1);
$stack->push($record);
my $record = $stack->pop;
my $asserts = $stack->asserts;
DESCRIPTION
Records what asserts have been called in the current user assert call stack. This is used to know at that point the user originally called an assert, so diagnostics can report the file and line number from the user's point of view despite being buried deep in stacks of asserts.
It can also let TB2 know when control is about to return to the user from calling an assert so it can fire an end of assert action which includes formatting and outputing the final result and diagnostics.
Asserts are stored as TB2::AssertRecord objects.
Methods
asserts
my $asserts = $stack->asserts;
Returns an array ref of the TB2::AssertRecord objects on the stack.
top
my $record = $stack->top;
Returns the top AssertRecord on the stack.
at_top
my $is_at_top = $stack->at_top;
Returns true if the stack contains just one assert.
in_assert
my $is_in_assert = $stack->in_assert;
Returns true if there are any assertions on the stack
from_top
my $message = $stack->from_top(@message);
Joins @message with empty string and returns it with " at $file line $line" appended from the top of the stack.
Convenient for printing failure diagnostics.
push
$stack->push(@asserts);
Push asserts onto the stack
pop
my $assert = $stack->pop;
Pop an assert off the stack