Test::Proto::Base - Base Class for Test Prototypes
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.
p
Test::Proto::Base->new
These are the methods intended for use when execcuting tests. All the methods for writing tests can be found at Test::Proto::Role::Value.
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.
$p->ok($subject, $context)
Works like validate, only produces a Test::Builder-compatible TAP output.
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.
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 '@'.
'A' & 'B'
'@'
These are for documentation purposes only.
This roughly corresponds to ref. Useful for indicating what sort of element you're expecting.
ref
This is documented for information purposes only and is not intended to be used except in the maintainance of Test::Proto itself.
Test::Proto
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.
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 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.
natural_script
user_script
->ok()
This method adds a test to the current object, specifically to the user_script, and returns the prototype object.
$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.
->run_test
For author, version, bug reports, support, etc, please see Test::Proto.
To install Test::Proto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Proto
CPAN shell
perl -MCPAN -e shell install Test::Proto
For more information on module installation, please visit the detailed CPAN module installation guide.