Test::Proto - OO test script golf sugar
Version 0.01
This module simplifies writing tests for deep structures and objects.
use Test::Proto; pAr ->contains_only('', pHr, "ArrayRef must contain only an empty string followed by a hashref") ->ok(["", {a=>'b'}]); pSt ->is_like(qr/^\d+$/, 'looks like a positive integer') ->is_unlike(qr/^0\d+$/, 'no leading zeros') ->ok('123'); pOb ->is_a('XML::LibXML::Node', 'must inherit from XML::LibXML::Node') ->is_a('XML::LibXML::Element', 'what it really is') ->can_do('findnodes', 'must have the findnodes method') ->try_can('localName', [], 'li') ->ok(XML::LibXML::Element->new('li'));
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 so that when you decide you need $got->{'wurple'}{'diddle'}{'do'} to look like $got->{'wurple'}->diddle->[$i]{'do'} you can make a much smaller change to your script. Test::Proto is a framework primarily for testing the same thing for multiple conditions, and testing the things it contains/produces in a similar manner.
$got->{'wurple'}{'diddle'}{'do'}
$got->{'wurple'}->diddle->[$i]{'do'}
The way it works is that you create a "prototype" (using a subclass of Test::Proto::Base), add tests to the prototype, and validate then your string/arryref/object/etc. against the prototype.
Returns a basic prototype. See Test::Proto::Base.
Returns a defined prototype. See Test::Proto::Base.
Returns a string prototype. See Test::Proto::String.
Returns an object prototype. See Test::Proto::Object.
Returns an arrayref prototype. See Test::Proto::ArrayRef.
Returns a hashref prototype. See Test::Proto::HashRef.
Returns a coderef prototype. See Test::Proto::CodeRef.
Returns a series. See Test::Proto::Series.
Returns a comparison object. See Test::Proto::Compare.
Returns a numeric comparison object. See Test::Proto::Compare::Numeric.
Daniel Perrett, <perrettdl at googlemail.com>
<perrettdl at googlemail.com>
Please report any bugs or feature requests to bug-test-proto at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Proto. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test-proto at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Test::Proto
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Proto
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-Proto
CPAN Ratings
http://cpanratings.perl.org/d/Test-Proto
Search CPAN
http://search.cpan.org/dist/Test-Proto/
Copyright 2012 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.