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

Test::Proto::Base - Base Class for Test Prototypes

SYNOPSIS

my $p = Test::Proto::Base->new->is_eq(-5);
$p->ok ($temperature) # will fail unless $temperature is -5
$p->ok ($score) # you can use the same test multple times
ok($p->validate($score)) # If you like your "ok"s first

This is a base class for test prototypes.

Throughout this documentation, p will be used as a shorthand for Test::Proto::Base->new.

METHODS

PUBLIC METHODS

These are the methods intended for use when execcuting tests. All the methods for writing tests can be found at Test::Proto::Role::Value.

validate

my $result = $p->validate($subject);
warn $result unless $result;

Runs through the tests in the prototype and checks that they all pass. It returns a TestRunner which evaluates true or false accordingly.

If you have an existing TestRunner, you can pass it that as well;

my $result = $p->validate($subject, $context);

EXPERIMENTAL: If no argument is passed, $_ will be used.

ok

$p->ok($subject, $context)

Works like validate, only produces a Test::Builder-compatible TAP output.

clone

This method returns a copy of the current object. The new object can have tests added without affecting the existing test. However, existing tests are not cloned, so if you want to tag them, you will need to clone them too.

OPERATOR OVERLOADING

Prototypes can be combined with the operators &, |, ^, and negated: !. In all cases, a new prototype is returned.

$x & $y => p->all_of([$x, $y])
$x | $y => p->any_of([$x, $y])
$x ^ $y => p->some_of([$x, $y], 1)
!$x     => p->none_of([$x])

Remember that this only works with prototypes. 'A' & 'B' still returns '@'.

PROTOTYPER METHODS

These are for documentation purposes only.

natural_type

This roughly corresponds to ref. Useful for indicating what sort of element you're expecting.

This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.

natural_script

These are tests common to the whole prototype which need not be repeated if two similar scripts are joined together. Normally, this should only be modified by the prototype class.

This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.

user_script

These are the tests which the user (specifically, the test script author) has added by a method call. Normally, these should empty in a class but may be present in an instance of an object.

This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.

script

This method returns an arrayref containing the contents of the natural_script and the user_script, i.e. all the tests in the object that are due to be run when ->ok() is called.

add_test

This method adds a test to the current object, specifically to the user_script, and returns the prototype object.

This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.

run_tests

$self->run_tests($subject, $context);

This method runs all the tests in the prototype object's script (simply calling the ->run_test method on each), and returns the prototype object.

This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.

OTHER INFORMATION

For author, version, bug reports, support, etc, please see Test::Proto.