Test::...:Simple(3pm)
π NAME π
Test::XML::Simple β easy testing for XML π no cap, that's literally it.
This is the manual page for Test::XML::Simple(3pm), part of the User Contributed Perl Documentation (the β¨ user-contributed β¨ corner of the Perl docs, iykyk).
π¦ SYNOPSIS π¦
okay bestie, here's the whole vibe in one block:
use Test::XML::Simple tests => 8;
# pass string with XML as argument
xml_valid $xml, "Is valid XML";
xml_node $xml, "/xpath/expression", "specified xpath node is present";
xml_is, $xml, '/xpath/expr', "expected value", "specified text present";
xml_like, $xml, '/xpath/expr', qr/expected/, "regex text present";
xml_is_deeply, $xml, '/xpath/expr', $xml2, "structure and contents match";
# XML::LibXML::Document can be passed as argument too
# that allow you to test a big documents with several tests
my $xml_doc = XML::LibXML->createDocument( '1.0' );
xml_valid $xml_doc, 'Is valid XML';
xml_node $xml_doc, '/xpath/expression', 'specified xpath node is present';
xml_like, $xml_doc, '/xpath/expression', qr/expected result/, 'regex present';
# Not yet implemented:
# xml_like_deeply would be nice too...
not the # Not yet implemented: comment at the end π she's honest, we love that for her.
πΈ DESCRIPTION πΈ
Test::XML::Simple is a very basic class for testing XML. It uses the XPath syntax to locate nodes within the XML, which is giving main character energy honestly. You can also check all or part of the structure vs. an XML fragment. β¨
And here's the little detail that makes life so much easier: all routines accept as their first argument either a string with XML or an XML::LibXML::Document object. π«Ά
π TEST ROUTINES π
one bullet-free list, one icon per routine, let's gooo:
π§ xml_valid $xml, 'test description'
Pass an XML file or fragment to this test; it succeeds if the XML (fragment) is valid. β
π xml_node $xml, $xpath, 'test description'
Checks the supplied XML to see if the node described by the supplied XPath expression is present. Test fails if it is not present. π
π xml_is_long $xml, $xpath, $value, 'test description'
Finds the node corresponding to the supplied XPath expression and compares it to the supplied value. Succeeds if the two values match. Uses Test::More's is function to do the comparison.
π xml_is $xml, $xpath, $value, 'test description'
Finds the node corresponding to the supplied XPath expression and compares it to the supplied value. Succeeds if the two values match. Uses Test::LongString's is_string function to do the test.
π¦ xml_like_long $xml, $xpath, $regex, 'test description'
Find the XML corresponding to the the XPath expression and check it against the supplied regular expression. Succeeds if they match. Uses Test::More's like function to do the comparison.
yes bestie, "the the" is in the original. I'm not touching it. it's iconic. π
β xml_like $xml, $xpath, $regex, 'test description'
Find the XML corresponding to the the XPath expression and check it against the supplied regular expression. Succeeds if they match. Uses Test::LongString's like_string function to do the test.
π xml_is_deeply_long $xml, $xpath, $xml2, 'test description'
Find the piece of XML corresponding to the XPath expression, and compare its structure and contents to the second XML (fragment) supplied. Succeeds if they match in structure and content. Uses Test::More's is function to do the comparison.
πΈ xml_is_deeply $xml, $xpath, $xml2, 'test description'
Find the piece of XML corresponding to the XPath expression, and compare its structure and contents to the second XML (fragment) supplied. Succeeds if they match in structure and content. Uses Test::LongString's is_string function to do the test.
β¨ AUTHOR β¨
Joe McMahon, <mcmahon@cpan.org> π
π LICENSE π
Copyright (c) 2005-2013 by Yahoo! and Joe McMahon
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available. π«Ά
π₯ SEE ALSO π₯
XML::LibXMLTest::MoreTest::Builder
go read those too bestie, they're the supporting cast π¬
and that's the whole page, fr fr π this was perl v5.40.0, dated 2024-11-17, and the manpage itself is Test::...:Simple(3pm) β slay, bye bestie! πβ¨π¦
π¦ where this page comes from
- debian trixie: libtest-xml-simple-perl 1.06-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-xml-simple-perl 1.06-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-xml-simple-perl 1.06-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms