Test::XML::Deep = XML::Simple + Test::Deep
Version 0.07
This module can be used to easily test that some XML has the structure and values you desire.
It is particularly useful when some values in your XML document may differ from one test run to another (for example, a timestamp).
An Example:
use Test::XML::Deep; my $xml = <<EOXML; <?xml version="1.0" encoding="UTF-8"?> <example> <sometag attribute="value">some data</sometag> <sometag attribute="other">more data</sometag> </example> EOXML my $expected = { sometag => [ { attribute => 'value', content => 'some data' }, ] }; cmp_xml_deeply($xml, $expected);
The real power comes from using Test::Deep and making use of the functions it exports (I.E. array_each(), re()):
use Test::Deep; my $expected = { sometag => array_each( { attribute => re('^\w+$'), content => re('data$'), } ) }; cmp_xml_deeply($xml, $expected);
You can also pass in a filename:
cmp_xml_deeply('somefile.xml', { my_expected => 'data_structure' });
cmp_xml_deeply
$xml is a filename or string of XML that you'd like to test.
$hashref_expected should be the expected value of the XML as it would be parsed by XML::Simple.
An optional test name is accepted as the third parameter.
Fergal Daly, for exporting cmp_details from Test::Deep lickety-split!
Michael G Schwern, for Test::Builder, which makes modules like this possible.
see: http://github.com/jlavallee/test-xml-deep
Jeff Lavallee, <jeff at zeroclue.com>
<jeff at zeroclue.com>
Please report any bugs or feature requests to bug-test-xml-deep at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-XML-Deep. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test-xml-deep at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Test::XML::Deep
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-XML-Deep
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-XML-Deep
CPAN Ratings
http://cpanratings.perl.org/d/Test-XML-Deep
Search CPAN
http://search.cpan.org/dist/Test-XML-Deep
Copyright 2009 Jeff Lavallee, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::XML::Simple, Test::Deep
To install Test::XML::Deep, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::XML::Deep
CPAN shell
perl -MCPAN -e shell install Test::XML::Deep
For more information on module installation, please visit the detailed CPAN module installation guide.