The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Assert::Refute::Exec - Contract execution class for Assert::Refute suite

DESCRIPTION

This class represents one specific application of contract. It is mutable, but can only changed in one way (there is no undo of tests and diagnostic messages). Eventually a done_testing locks it completely, leaving only "QUERYING PRIMITIVES" for inspection.

See Assert::Refute::Contract for contract definition.

SYNOPSIS

    my $c = Assert::Refute::Exec->new;
    $c->refute ( $cond, $message );
    $c->refute ( $cond2, $message2 );
    # .......
    $c->done_testing; # no more refute after this

    $c->count;      # how many tests were run
    $c->is_passing; # did any of them fail?
    $c->as_tap;     # return printable summary in familiar format

OBJECT-ORIENTED INTERFACE

new

    Assert::Refute::Exec->new( %options );

%options may include:

  • indent - log indentation (will be shown as 4 spaces in as_tap);

RUNNING PRIMITIVES

refute( $condition, $message )

An inverted assertion. That is, it passes if $condition is false.

Returns inverse of first argument. Dies if "done_testing" was called.

See "refute" in Assert::Refute for more detailed discussion.

diag

    diag "Message", \%reference, ...;

Add human-readable diagnostic message to report. References are explained to depth 1.

note

    diag "Message", \%reference, ...;

Add human-readable notice message to report. References are explained to depth 1.

done_testing

Stop testing. After this call, no more writes (including done_testing) can be performed on this contract. This happens by default at the end of contract{ ... } block.

If an argument is given, it is considered to be the exception that interrupted the contract execution, resulting in an unconditionally failed contract.

TESTING PRIMITIVES

Assert::Refute comes with a set of basic checks similar to that of Test::More, all being wrappers around "refute" discussed above. They are available as both prototyped functions (if requested) and methods in contract execution object and its descendants.

The list is as follows:

is, isnt, ok, use_ok, require_ok, cmp_ok, like, unlike, can_ok, isa_ok, new_ok, contract_is, is_deeply, note, diag.

See Assert::Refute::T::Basic for more details.

Additionally, any checks defined using Assert::Refute::Build will be added to this Assert::Refute::Exec by default.

subcontract( "Message" => $specification, @arguments ... )

Execute a previously defined contract and fail loudly if it fails.

[NOTE] that the message comes first, unlike in refute or other test conditions, and is required.

QUERYING PRIMITIVES

is_done

Tells whether done_testing was seen.

is_passing

Tell whether the contract is passing or not.

count

How many tests have been executed.

get_tests

Returns a list of test ids, preserving order.

result( $id )

Returns result of test denoted by $id, dies if such test was never performed. The result is false for passing tests and whatever the reason for failure was for failing ones.

has_died

Returns true if contract execution was ever interrupted by exception.

last_error

Return last error that was recorded during contract execution, or false if there was none.

as_tap

Return a would-be Test::More script output for current contract.

signature

Produce a terse pass/fail summary as a string of numbers and letters.

The format is "t(\d+|N)*[rdE]".

t is always present at the start;
a number stands for a series of passing tests;
N stands for a single failing test;
r stands for a contract that is still running;
E stands for a an exception during execution;
d stands for a contract that is done.

The format is still evolving. Capital letters are used to represent failure, and it is likely to stay like that.

The numeric notation was inspired by Forsyth-Edwards notation (FEN) in chess.

DEVELOPMENT PRIMITIVES

Generally one should not touch these methods unless when subclassing to build a new test backend.

log_message( $indent, $level, $message )

Append a message to execution log. Levels are:

-2 - something totally horrible
-1 - a failing test
0 - a passing test
1 - a diagnostic message, think Test::More/diag
2+ - a normally ignored verbose message, think "note" in Test::More

add_result( $id, $result )

Add a refutation to the failed tests log.

get_proxy

Return ($self, indent) pair in list content, or just $self in scalar context.

LICENSE AND COPYRIGHT

This module is part of Assert::Refute suite.

Copyright 2017 Konstantin S. Uvarin. <khedin at gmail.com>

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.