Test::Proto - OO test script golf sugar
Version 0.027
This module provides an expressive interface for validating deep structures and objects.
use Test::Proto ':all'; pArray ->contains_only(pSeries('', pHash), "ArrayRef must contain only an empty string followed by a hashref") ->ok(["", {a=>'b'}]); # provides diagnostics, including subtests as TAP, using Test::Builder p ->like(qr/^\d+$/, 'looks like a positive integer') ->unlike(qr/^0\d+$/, 'no leading zeros') ->validate('123'); # returns an object with a true value pObject ->is_a('XML::LibXML::Node', 'must inherit from XML::LibXML::Node') ->is_a('XML::LibXML::Element', 'what it really is') ->method_exists('findnodes', 'must have the findnodes method') ->method_scalar_context('localName', [], p->like(qr/blockquote|li|p/, 'We can add normal text here') ) ->ok(XML::LibXML::Element->new('li')); # have a look at the nested prototype in try_can
The idea behind Test::Proto is that test scripts for code written on modern, OO principles should themselves resemble the target code rather than sequential code.
Tests for deep structures and objects tend should not be repetitive and should be flexible. Test::Proto allows you to create objects "protoypes" intended to test structures which conform to a known type.
As in the example above, the way it works is: you create a prototype object, add test cases to the prototype using method calls, and then validate your string/arryref/object/etc. against the prototype using the validate or ok method.
NB: The meaning of "prototype" used here is not related to subroutine prototypes (declaring the arguments expected by a given function or method).
p p('foo') p(['bar']) p({foo=>'bar'})
Returns a basic prototype. See Test::Proto::Base. If an argument is passed, upgrades the argument and uses the resulting prototype.
Returns a prototype for an array/ArrayRef. See Test::Proto::ArrayRef.
Returns a prototype for a hash/HashRef. See Test::Proto::HashRef.
Returns a prototype for a CodeRef. See Test::Proto::CodeRef.
pObject pObject('IO::Handle') # tests with is_a
Returns a prototype for an object. See Test::Proto::Object.
Returns a series object for use in validating lists. See Test::Proto::Series.
Returns a repeatable series object for use in validating lists. See Test::Proto::Repeatable.
Returns an alternation for use in validating lists. See Test::Proto::Alternation.
Returns a comparison object (string, by default). See Test::Proto::Compare.
Returns a numeric comparison object. See Test::Proto::Compare::Numeric.
Begun by Daniel Perrett, <perrettdl at googlemail.com>
<perrettdl at googlemail.com>
Michael Schwern
Data::DPath
Data::Sah
Data::Verifier
Test::Deep
Validation::Class
Please report any bugs or feature requests to the github issues tracker at https://github.com/pdl/Test-Proto/issues. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Test::Proto
You can also look for information at:
Github (please report bugs here)
https://github.com/pdl/Test-Proto
MetaCPAN
https://metacpan.org/module/Test::Proto
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-Proto
Search CPAN
http://search.cpan.org/dist/Test-Proto/
Copyright 2012-2013 Daniel Perrett.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
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.