XML::Compile::Tester3pm
Support xml::compile related regression testing
Usage
use XML::Compile::Tester;# default additional compile flags, avoids repetitionset_compile_defaults(validation => 0, @other_opts);set_compile_defaults(); # reset# set default namespace, such that $type only needs to use localmy $ns = 'some-schemas-targetNamespace';my $type = pack_type($ns, 'localName'); # X::C::Utilset_default_namespace($ns);my $type = 'localName'; # now implicit in $nsmy $reader = reader_create($schema, "my reader", $type, @opts);my $data = $reader->($xml); # $xml is string, filename, nodemy $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);
Inheritance
XML::Compile::Testeris a Exporter
Overview
The XML::Compile module suite has extensive regression testing. Probably, you want to do regression testing as well. This module provide functions which simplify writing tests for XML::Compile related distributions.
Functions
Reader checks
reader_create($schema, $comment, $type, %options)-
Create a reader for
$type. One test is created, reporting success or failure of the creation.Of course, XML::Compile::Schema subroutine compile is being called, with some options. By default,
"check_values"is true, and"include_namespaces"is false. These values can be overruled usingset_compile_defaults(), and with the%optionsparameter list.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::Morecmp_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. The error text is returned.example: reader_error
my $error = reader_error($schema, $type, <<_XML);<test1>...</test1>_XMLis($error, 'error text', 'my test');like($error, qr/error pattern/, 'my test');
Writer checks
writer_create($schema, $comment, $type, %options)-
Create a writer for
$type. One test (in the Test::More sense) is created, reporting success or failure of the creation.Of course, XML::Compile::Schema subroutine compile is being called, with some options. By default,
"check_values"and"use_default_namespace"are true, and"include_namespaces"is false. These values can be overruled usingset_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 $docmy $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.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] )-
Run the test with a compiled
$writer, which was created withwriter_create(). When no$doc(XML::LibXML::Document object) was specified, then one will be created for you.
Check templates
templ_perl($schema, $type, %options)
templ_xml($schema, $type, %options)-
Create an example template for
$type, as XML message. The%optionsare 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] )-
Compare the
$createdXML (either a string or an XML::LibXML::Element) with the$expectedstring. Both sources are stripped from layout before comparing.In a future release, this algorithm will get improved to compare the parsed XML node trees, not the strings.
example: compare_xml
compare_xml($xml, <<_XML, 'my test');<test1>...</test1>_XML
set_compile_defaults(%options)-
Each call to create a reader or writer (also indirectly) with XML::Compile::Schema subroutine compile will get these
%optionspassed, on top (and overruling) the usual settings.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)-
Defined which namespace to use when a relative (only localName) type is provided. By default, this is
"undef"(an error when used)
Releases
6 releases since Debian 8 (Jessie); the text changed 2 times.