INHERITANCE

 XML::Compile::Tester
   is a Exporter

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

DESCRIPTION

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(\s-1SCHEMA\s0, \s-1COMMENT\s0, \s-1TYPE\s0, \s-1OPTIONS\s0)

Create a reader for \s-1TYPE\s0. 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, \*(C`check_values\*(C' is true, and \*(C`include_namespaces\*(C' is false. These values can be overruled using set_compile_defaults(), and with the \s-1OPTIONS\s0 parameter 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::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(\s-1SCHEMA\s0, \s-1TYPE\s0, \s-1XML\s0)

Parsing the \s-1XML\s0 to interpret the \s-1TYPE\s0 should return an error. The error text is returned. 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(\s-1SCHEMA\s0, \s-1COMMENT\s0, \s-1TYPE\s0, \s-1OPTIONS\s0)

Create a writer for \s-1TYPE\s0. 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, \*(C`check_values\*(C' and \*(C`use_default_namespace\*(C' are true, and \*(C`include_namespaces\*(C' is false. These values can be overruled using set_compile_defaults(), and with the \s-1OPTIONS\s0 parameter 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(\s-1SCHEMA\s0, \s-1TYPE\s0, \s-1DATA\s0)

Translating the Perl \s-1DATA\s0 into the \s-1XML\s0 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(\s-1WRITER\s0, \s-1DATA\s0, [\s-1DOC\s0])

Run the test with a compiled \s-1WRITER\s0, which was created with writer_create(). When no \s-1DOC\s0 (XML::LibXML::Document object) was specified, then one will be created for you.

Check templates

templ_perl(\s-1SCHEMA\s0, \s-1TYPE\s0, \s-1OPTIONS\s0)
templ_xml(\s-1SCHEMA\s0, \s-1TYPE\s0, \s-1OPTIONS\s0)

Create an example template for \s-1TYPE\s0, as \s-1XML\s0 message. The \s-1OPTIONS\s0 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(\s-1XML\s0, \s-1EXPECTED\s0, [\s-1COMMENT\s0])

Compare the \s-1XML\s0 (either a string or an XML::LibXML::Element) with the \s-1EXPECTED\s0 string. Both sources are stripped from layout before comparing. In a future release, this algorithm will get improved to compare the parsed \s-1XML\s0 node trees, not the strings. example: compare_xml compare_xml($xml, <<_XML, 'my test'); <test1>...</test1> _XML

set_compile_defaults(\s-1OPTIONS\s0)

Each call to create a reader or writer (also indirectly) with XML::Compile::Schema subroutine compile will get these \s-1OPTIONS\s0 passed, 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(\s-1TESTNS\s0)

Defined which namespace to use when a relative (only localName) type is provided. By default, this is \*(C`undef\*(C' (an error when used)

RELATED TO XML::Compile::Tester…

This module is part of XML-Compile-Tester distribution version 0.90, built on August 16, 2012. Website: http://perl.overmeer.net/xml-compile/

Other distributions in this suite: XML::Compile, XML::Compile::SOAP, XML::Compile::SOAP12, XML::Compile::SOAP::Daemon, XML::Compile::SOAP::WSA, XML::Compile::C14N, XML::Compile::WSS, XML::Compile::Tester, XML::Compile::Cache, XML::Compile::Dumper, XML::Compile::RPC, XML::Rewrite, XML::eXistDB, and XML::LibXML::Simple.

Please post questions or ideas to the mailinglist at http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile For live contact with other developers, visit the \*(C`#xml-compile\*(C' channel on \*(C`irc.perl.org\*(C'.

LICENSE

Copyrights 2008-2012 by [Mark Overmeer]. 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://www.perl.com/perl/misc/Artistic.html