Test::XML(3pm)
π Test::XML π
okay bestie, so this is Test::XML β it's a Perl thing for comparing XML in your tests, and honestly? it's giving β¨peace of mindβ¨. it lives in the User Contributed Perl Documentation, so you already know it's the people's module. π«Ά
β¨ SYNOPSIS β¨
like, here's the whole vibe in one code block:
use Test::XML tests => 3;
is_xml( '<foo />', '<foo></foo>' ); # PASS
is_xml( '<foo />', '<bar />' ); # FAIL
isnt_xml( '<foo />', '<bar />' ); # PASS
is_well_formed_xml('<foo/>'); # PASS
is_well_formed_xml('<foo>'); # FAIL
see how <foo /> and <foo></foo> are literally the same thing to this module? that's the whole point bestie, semantic comparison, no cap. π
πΈ DESCRIPTION πΈ
so this module is a lil collection of generic XML testing tools. and if you're looking for stuff that's specific to particular XML modules, keep scrolling β there's a list of those other modules further down. iykyk. π¦
π FUNCTIONS π
π
is_xml ( GOT, EXPECTED [, TESTNAME ] )
this one takes GOT and EXPECTED β both of them strings of XML β and compares them. and the way it compares them? semantically. meaning it will straight-up ignore syntax differences that don't actually mean anything in XML, like:
- different quote characters for attributes
- the order of attributes
- empty tag styles
returns true or false depending on whether the test succeeded. iconic behaviour, honestly. β¨
π
isnt_xml( GOT, MUST_NOT_BE [, TESTNAME ] )
basically is_xml()'s chaotic twin. it does the same kinda thing, except it fails if GOT and MUST_NOT_BE are identical. so it passes when they're not the same. periodt.
π
is_well_formed_xml( XML [, TESTNAME ] )
this one just checks whether a given XML string is parseable as XML. that's it. is it valid? is it well-formed? vibe check complete. π§
π
is_good_xml ( XML [, TESTNAME ] )
an alias for is_well_formed_xml(). same energy, different name. π
π NOTES π
okay so there are a few features of XML::SemanticDiff that might genuinely surprise you if nobody warned you first. consider this your warning. π¨
- Leading and trailing whitespace is always stripped, even in elements with character content.
- Whitespace inside character content is always stripped down to a single space.
- In mixed content elements (ie: an element with both text and elements beneath it), all text is treated as a single value.
- The order of elements is ignored.
lowkey important: that last one means element order doesn't matter to this module. if you were relying on order, that's a you problem bestie. π
π SEE ALSO π
Test::XML::SAXTest::XML::TwigTest::MoreXML::SemanticDiff
go read those too, they're all part of the same little friend group. π«Ά
β AUTHOR β
Dominic Mitchell, <cpan2 (at) semantico.com>
π COPYRIGHT AND LICENSE π
Copyright 2002 by semantico
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie!! π this was perl v5.34.0, dated 2022-06-18, and yes it's the User Contributed Perl Documentation version of Test::XML(3pm). slay, go write some tests, mwah πβ¨
π¦ where this page comes from
- debian bookworm: libtest-xml-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-xml-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-xml-perl 0.08-4 Β· 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