XML::C...Tester(3pm)
π XML::Compile::Tester β the manual, but make it cute β¨
okay bestie, gather round, because this is XML::C...Tester(3pm) from the User Contributed Perl Documentation crew, and she's here to help you write regression tests for your XML::Compile situation. no cap. π
β¨ NAME β¨
XML::Compile::Tester β support for XML::Compile related regression testing π
π INHERITANCE π
XML::Compile::Tester
is a Exporter
yeah she's an Exporter, so all her little helper functions can come hang out in your namespace, no invite needed. π«Ά
π¦ SYNOPSIS π¦
use XML::Compile::Tester;
# default additional compile flags, avoids repetition
set_compile_defaults(validation => 0, @other_opts);
set_compile_defaults(); # reset
# set default namespace, such that $type only needs to use local
my $ns = 'some-schemas-targetNamespace';
my $type = pack_type($ns, 'localName'); # X::C::Util
set_default_namespace($ns);
my $type = 'localName'; # now implicit in $ns
my $reader = reader_create($schema, "my reader", $type, @opts);
my $data = $reader->($xml); # $xml is string, filename, node
my $writer = writer_create($schema, "my writer", $type, @opts);
my $xml = $writer->($doc, $data);
my $xml = writer_test($writer, $data);
my $rerror = reader_error($schema, $type, $xml);
my $werror = writer_error($schema, $type, $data);
my $output = templ_xml($schema, $type, @options);
my $output = templ_perl($schema, $type, @options);
look at her. iconic. π§
πΈ DESCRIPTION πΈ
the XML::Compile module suite has extensive regression testing. and like, probably? you want to do regression testing too? valid. so this module hands you a bunch of functions that simplify writing tests for XML::Compile related distributions. it's giving "we already wrote the annoying part so you don't have to." periodt. π
π FUNCTIONS π
π Reader checks π
reader_create($schema, $comment, $type, %options)β makes you a reader for$type. one test gets created, reporting success or failure of the creation. obviously XML::Compile::Schema subroutinecompileis being called under the hood, with some options. by default,check_valuesis true, andinclude_namespacesis false. you can overrule these usingset_compile_defaults(), and with the%optionsparameter list. bestie behaviour fr fr.
example: reader_create
my $type = pack_type('namespace', 'localName');
my $reader = reader_create($schema, 'my test', $type
, check_occurs => 0, @other_options);
my $data = $reader->($xml);
is_deeply($data, $expected, 'my test'); # Test::More
cmp_deeply($data, $expected, 'my test'); # Test::Deep
# alternative for $type:
set_default_namespace('namespace');
my $reader = reader_create($schema, 'my test', 'localName'
, check_occurs => 0, @other_options);
reader_error($schema, $type, $xml)β parsing the$xmlto interpret the$typeshould return an error. and the error text is returned to you. like, the error is the point. π
example: reader_error
my $error = reader_error($schema, $type, <<_XML);
<test1>...</test1>
_XML
is($error, 'error text', 'my test');
like($error, qr/error pattern/, 'my test');
β¨ Writer checks β¨
writer_create($schema, $comment, $type, %options)β creates a writer for$type. one test (in the Test::More sense, iykyk) is created, reporting success or failure of the creation. and yes, XML::Compile::Schema subroutinecompileis being called, with some options. by default,check_valuesanduse_default_namespaceare true, andinclude_namespacesis false. overrule them withset_compile_defaults(), and with the%optionsparameter list. π
example: writer_create
set_default_namespace('namespace');
my $writer = writer_create($schema, 'my test', 'test1');
my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
my $xml = $writer->($doc, $data);
compare_xml($xml, <<_EXPECTED, 'my test');
<test1>...</test1>
_EXPECTED
# implicit creation of $doc
my $xml = writer_test($writer, $data);
writer_error($schema, $type, $data)β translating the Perl$datainto the XML type should return a validation error, which is returned. (yes, again: the error is the whole vibe.) π
example: writer_error
my $error = writer_error($schema, $type, $data);
is($error, 'error text', 'my test');
like($error, qr/error pattern/, 'my test');
writer_test( $writer, $data, [$doc] )β runs the test with a compiled$writer, which was created withwriter_create(). when no$doc(XML::LibXML::Documentobject) was specified, then one will be created for you. she's thoughtful like that. π«Ά
π¦ Check templates π¦
templ_perl($schema, $type, %options)templ_xml($schema, $type, %options)
create an example template for $type, as XML message. the %options are passed to XML::Compile::Schema subroutine template.
example: templ_xml
my $out = templ_xml($schema, $type, show => 'ALL');
is($out, $expected);
π Helpers π
compare_xml( $created, $expected, [$comment] )β compares the$createdXML (either a string or anXML::LibXML::Element) with the$expectedstring. both sources are stripped from layout before comparing. lowkey magical.
heads up bestie: in a future release, this algorithm will get improved to compare the parsed XML node trees, not the strings. so like, don't build your whole personality on the string behaviour, k? π
example: compare_xml
compare_xml($xml, <<_XML, 'my test');
<test1>...</test1>
_XML
set_compile_defaults(%options)β every call to create a reader or writer (also indirectly) with XML::Compile::Schema subroutinecompilewill get these%optionspassed, on top (and overruling) the usual settings. main character energy for your defaults. π
example:
# defaults for XML::Compile::Schema::compile()
set_compile_defaults(include_namespaces => 1, validate => 0
, sloppy_intergers => 1, sloppy_floats => 1);
set_compile_defaults(); # reset
set_default_namespace($testns)β defines which namespace to use when a relative (onlylocalName) type is provided. by default, this isundefβ which means an error when used. so set it, or catch hands. π
π SEE ALSO π
this module is part of the XML-Compile-Tester distribution version 0.91, built on May 11, 2018. website: http://perl.overmeer.net/CPAN/ π¦
π LICENSE π
copyrights 2008-2018 by [Mark Overmeer <markov@cpan.org>]. for other contributors see ChangeLog.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. see http://dev.perl.org/licenses/
and that's the whole page bestie, no cap. she's XML-Compile-Tester version 0.91, built on May 11, 2018, and this particular rendering rode in on perl v5.36.0 dated 2022-12-01 β from XML::C...Tester(3pm) with love. slay, go write some tests. π
β¨π
π¦ where this page comes from
- debian bookworm: libxml-compile-tester-perl 0.91-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-compile-tester-perl 0.91-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-compile-tester-perl 0.91-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-compile-tester-perl 0.91-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-compile-tester-perl 0.91-2 Β· 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