Jeff Lavallee > Test-XML-Deep-0.07 > Test::XML::Deep

Download:
Test-XML-Deep-0.07.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.07   Source  

NAME ^

Test::XML::Deep = XML::Simple + Test::Deep

VERSION ^

Version 0.07

SYNOPSIS ^

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' });

EXPORT ^

cmp_xml_deeply

FUNCTIONS ^

cmp_xml_deeply( $xml, $hashref_expected, [ 'test name' ] );

$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.

ACKNOWLEDGEMENTS ^

Fergal Daly, for exporting cmp_details from Test::Deep lickety-split!

Michael G Schwern, for Test::Builder, which makes modules like this possible.

SOURCE ^

see: http://github.com/jlavallee/test-xml-deep

AUTHOR ^

Jeff Lavallee, <jeff at zeroclue.com>

BUGS ^

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.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Test::XML::Deep

You can also look for information at:

COPYRIGHT & LICENSE ^

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.

SEE ALSO ^

Test::XML::Simple, Test::Deep

syntax highlighting: