XML-Compile-Tester-0.90/0000755000175000001440000000000012013016552014145 5ustar markovusersXML-Compile-Tester-0.90/Makefile.PL0000644000175000001440000000143612013016460016121 0ustar markovusersuse ExtUtils::MakeMaker; use 5.008; WriteMakefile ( NAME => 'XML::Compile::Tester' , VERSION => '0.90' , PREREQ_PM => { Log::Report => 0.17 , Test::More => 0.54 , Test::Deep => 0.095 } , AUTHOR => 'Mark Overmeer' , ABSTRACT => 'support XML::Compile related regression testing' , LICENSE => 'perl' ); ### used by oodist during production of distribution sub MY::postamble { <<'__POSTAMBLE' } # for DIST RAWDIR = ../public_html/xml-compile-tester/raw DISTDIR = ../public_html/xml-compile-tester/source LICENSE = artistic SKIP_LINKS = XML::LibXML # for POD FIRST_YEAR = 2008 EMAIL = perl@overmeer.net WEBSITE = http://perl.overmeer.net/xml-compile/ PODTAIL = ../XML-shared-podtail __POSTAMBLE XML-Compile-Tester-0.90/t/0000755000175000001440000000000012013016551014407 5ustar markovusersXML-Compile-Tester-0.90/t/01use.t0000644000175000001440000000017312013016460015531 0ustar markovusers#!/usr/bin/perl use warnings; use strict; use lib 'lib'; use Test::More tests => 1; require_ok('XML::Compile::Tester'); XML-Compile-Tester-0.90/t/99pod.t0000644000175000001440000000041212013016460015534 0ustar markovusers#!/usr/bin/perl use warnings; use strict; use Test::More; BEGIN { eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; plan skip_all => "devel home uses OODoc" if $ENV{MARKOV_DEVEL}; } all_pod_files_ok(); XML-Compile-Tester-0.90/ChangeLog0000644000175000001440000000217412013016550015721 0ustar markovusers === version history of XML::Compile::Tester Unless noted otherwise, these changes where initiated and applied by Mark Overmeer. version 0.90: Thu Aug 16 00:06:24 CEST 2012 Improvements: - add templ_tree() version 0.06: Tue Jun 15 14:49:28 CEST 2010 Fixes: - templ_xml should default include_namespaces to version 0.05: Wed Feb 11 11:07:24 CET 2009 Fixes: - do not use /bin/pwd in t/99pod.t - use 'use_default_namespace' i.s.o 'use_default_prefix' in writer. - do not complain if default_namespace is not set. Improvements: - removed superfluous '$' before 'templ*' in SYNOPSIS version 0.04: Wed Oct 1 22:12:59 CEST 2008 Fixes: - dependency with XML::Compile::Util. [cpantesters] version 0.03: Wed Oct 1 09:50:53 CEST 2008 Changes: - create_reader --> reader_create, create_writer --> writer_create Improvements: - much more documentation. version 0.02: Tue Apr 29 19:01:14 CEST 2008 Improvements: - does not depend on XML::Compile. - Add ChangeLog file to package. version 0.01: Mon Apr 21 17:09:08 CEST 2008 - initial implementation, derived from XML::Compile file t/TestTools.pm XML-Compile-Tester-0.90/META.yml0000644000175000001440000000103312013016551015412 0ustar markovusers--- abstract: 'support XML::Compile related regression testing' author: - 'Mark Overmeer' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: XML-Compile-Tester no_index: directory: - t - inc requires: Log::Report: 0.17 Test::Deep: 0.095 Test::More: 0.54 version: 0.90 XML-Compile-Tester-0.90/lib/0000755000175000001440000000000012013016551014712 5ustar markovusersXML-Compile-Tester-0.90/lib/XML/0000755000175000001440000000000012013016551015352 5ustar markovusersXML-Compile-Tester-0.90/lib/XML/Compile/0000755000175000001440000000000012013016551016742 5ustar markovusersXML-Compile-Tester-0.90/lib/XML/Compile/Tester.pod0000644000175000001440000001442712013016550020723 0ustar markovusers=head1 NAME XML::Compile::Tester - support XML::Compile related regression testing =head1 INHERITANCE XML::Compile::Tester is a Exporter =head1 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); =head1 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. =head1 FUNCTIONS =head2 Reader checks =over 4 =item B(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, C is true, and C is false. These values can be overruled using L, and with the OPTIONS 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); =item B(SCHEMA, TYPE, XML) Parsing the XML to interpret the TYPE should return an error. The error text is returned. example: reader_error my $error = reader_error($schema, $type, <<_XML); ... _XML is($error, 'error text', 'my test'); like($error, qr/error pattern/, 'my test'); =back =head2 Writer checks =over 4 =item B(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, C and C are true, and C is false. These values can be overruled using L, and with the OPTIONS 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'); ... _EXPECTED # implicit creation of $doc my $xml = writer_test($writer, $data); =item B(SCHEMA, TYPE, DATA) Translating the Perl DATA into 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'); =item B(WRITER, DATA, [DOC]) Run the test with a compiled WRITER, which was created with L. When no DOC (XML::LibXML::Document object) was specified, then one will be created for you. =back =head2 Check templates =over 4 =item B(SCHEMA, TYPE, OPTIONS) =item B(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); =back =head2 Helpers =over 4 =item B(XML, EXPECTED, [COMMENT]) Compare the XML (either a string or an XML::LibXML::Element) with the EXPECTED string. 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'); ... _XML =item B(OPTIONS) Each call to create a reader or writer (also indirectly) with XML::Compile::Schema subroutine compile will get these OPTIONS 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 =item B(TESTNS) Defined which namespace to use when a relative (only localName) type is provided. By default, this is C (an error when used) =back =head1 SEE ALSO This module is part of XML-Compile-Tester distribution version 0.90, built on August 16, 2012. Website: F Other distributions in this suite: L, L, L, L, L, L, L, L, L, L, L, L, L, and L. Please post questions or ideas to the mailinglist at F For live contact with other developers, visit the C<#xml-compile> channel on C. =head1 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 F XML-Compile-Tester-0.90/lib/XML/Compile/Tester.pm0000644000175000001440000001045512013016550020552 0ustar markovusers# Copyrights 2008-2012 by [Mark Overmeer]. # For other contributors see ChangeLog. # See the manual pages for details on the licensing terms. # Pod stripped from pm file by OODoc 2.00. use warnings; use strict; package XML::Compile::Tester; use vars '$VERSION'; $VERSION = '0.90'; use base 'Exporter'; our @EXPORT = qw/ set_compile_defaults set_default_namespace reader_create create_reader writer_create create_writer writer_test reader_error writer_error templ_xml templ_perl templ_tree compare_xml /; use Test::More; use Data::Dumper; use Log::Report qw/try/; my $default_namespace; my @compile_defaults; # not using pack_type, which avoids a recursive dependency to XML::Compile sub _reltype_to_abs($) { defined $default_namespace && substr($_[0], 0,1) eq '{' ? "{$default_namespace}$_[0]" : $_[0] } sub reader_create($$$@) { my ($schema, $test, $reltype) = splice @_, 0, 3; my $type = _reltype_to_abs $reltype; my $read_t = $schema->compile ( READER => $type , check_values => 1 , include_namespaces => 0 , @compile_defaults , @_ ); isa_ok($read_t, 'CODE', "reader element $test"); $read_t; } *create_reader = \&reader_create; # name change in 0.03 sub reader_error($$$) { my ($schema, $reltype, $xml) = @_; my $r = reader_create $schema, "check read error $reltype", $reltype; defined $r or return; my $tree = try { $r->($xml) }; my $error = ref $@ && $@->exceptions ? join("\n", map {$_->message} $@->exceptions) : ''; undef $tree if $error; # there is output if only warnings are produced ok(!defined $tree, "no return for $reltype"); warn "RETURNED TREE=",Dumper $tree if defined $tree; ok(length $error, "ER=$error"); $error; } sub writer_create($$$@) { my ($schema, $test, $reltype) = splice @_, 0, 3; my $type = _reltype_to_abs $reltype; my $write_t = $schema->compile ( WRITER => $type , check_values => 1 , include_namespaces => 0 , use_default_namespace => 1 , @compile_defaults , @_ ); isa_ok($write_t, 'CODE', "writer element $test"); $write_t; } *create_writer = \&writer_create; # name change in 0.03 sub writer_test($$;$) { my ($writer, $data, $doc) = @_; $doc ||= XML::LibXML->createDocument('1.0', 'UTF-8'); isa_ok($doc, 'XML::LibXML::Document'); my $tree = $writer->($doc, $data); ok(defined $tree); defined $tree or return; isa_ok($tree, 'XML::LibXML::Node'); $tree; } sub writer_error($$$) { my ($schema, $reltype, $data) = @_; my $write = writer_create $schema, "writer for $reltype", $reltype; my $node; try { my $doc = XML::LibXML->createDocument('1.0', 'UTF-8'); isa_ok($doc, 'XML::LibXML::Document'); $node = $write->($doc, $data); }; my $error = ref $@ && $@->exceptions ? join("\n", map {$_->message} $@->exceptions) : ''; undef $node if $error; # there is output if only warnings are produced # my $error = $@ ? $@->wasFatal->message : ''; ok(!defined $node, "no return for $reltype expected"); warn "RETURNED =", $node->toString if ref $node; ok(length $error, "EW=$error"); $error; } sub templ_xml($$@) { my ($schema, $test, @opts) = @_; my $abs = _reltype_to_abs $test; $schema->template ( XML => $abs , include_namespaces => 1 , @opts ) . "\n"; } sub templ_perl($$@) { my ($schema, $test, @opts) = @_; my $abs = _reltype_to_abs $test; $schema->template ( PERL => $abs , include_namespaces => 0 , @opts ); } sub templ_tree($$@) { my ($schema, $test, @opts) = @_; my $abs = _reltype_to_abs($test); $schema->template ( TREE => $abs , @opts ); } sub set_compile_defaults(@) { @compile_defaults = @_ } sub set_default_namespace($) { $default_namespace = shift } sub compare_xml($$;$) { my ($tree, $expect, $comment) = @_; my $dump = ref $tree ? $tree->toString : $tree; for($dump, $expect) { defined $_ or next; s/\>\s+/>/gs; s/\s+\\s+\' (2) if you use Windows, have a look at http://ppm.activestate.com/ (3) if you have downloaded this module manually (as root/administrator) gzip -d XML-Compile-Tester-0.90.tar.gz tar -xf XML-Compile-Tester-0.90.tar cd XML-Compile-Tester-0.90 perl Makefile.PL make # optional make test # optional make install For usage, see the included manual-pages or http://search.cpan.org/dist/XML-Compile-Tester-0.90/ Please report problems to http://rt.cpan.org/Dist/Display.html?Queue=XML-Compile-Tester