From: Peter Rabbitson Date: Tue, 9 Jun 2009 20:49:32 +0000 (+0000) Subject: Create a YAML copy of the main roundtrip schema - this is what we use to run t/60roun... X-Git-Tag: v0.11008~157 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dc34f950edab906d21423ce3d13b6ca07e368e6e;p=dbsrgits%2FSQL-Translator.git Create a YAML copy of the main roundtrip schema - this is what we use to run t/60roundtrip.t without depending on LibXML. The YAML is regenerated on every Makefile.PL run --- diff --git a/Makefile.PL b/Makefile.PL index 7d6b752..b10392d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,18 +17,16 @@ my $deps = { 'DBI' => 0, 'File::ShareDir' => 1.0, 'File::Spec' => 0, + 'XML::Writer' => 0.500, }, recommends => { 'Template' => 2.10, 'GD' => 0, 'GraphViz' => 0, 'Graph::Directed' => 0, - 'IO::File' => 0, - 'IO::Scalar' => 0, 'Spreadsheet::ParseExcel' => 0.41, 'Text::ParseWords' => 0, 'Text::RecordParser' => 0.02, - 'XML::Writer' => 0.500, 'XML::LibXML' => 1.61, }, test_requires => { @@ -78,4 +76,63 @@ auto_provides(); auto_install(); +if ($Module::Install::AUTHOR) { + _recompile_grammars(); + _recreate_rt_source(); +} + WriteAll(); + + +sub _recompile_grammars { + # placeholder, will be used to recompile P::RD parsers before shipping + # will also allow to lose dependency on P::RD +} + +sub _recreate_rt_source { + my $base_xml = "t/data/roundtrip.xml"; + my $autogen_yaml = "t/data/roundtrip_autogen.yaml"; + + print "Updating $autogen_yaml\n"; + + unlink $autogen_yaml; + + eval { + + use lib 'lib'; + + require SQL::Translator; + require SQL::Translator::Parser::XML; + + open (my $fh, '>', $autogen_yaml) or die "$autogen_yaml: $!\n"; + + my $tr = SQL::Translator->new; + my $yaml = $tr->translate ( + parser => 'XML', + file => $base_xml, + producer => 'YAML', + ) or die sprintf ("Unable to translate %s to YAML: %s\n", + $base_xml, + $tr->error || 'error unknown' + ); + + print $fh $yaml; + close $fh; + }; + + if ($@) { + print < $msg; } - else { + elsif ($ntests and $ntests ne 'no_plan') { plan tests => $ntests; } + else { + plan 'no_plan'; + } } 1; # compile please =========================================================== diff --git a/t/62roundtrip_datacheck.t b/t/62roundtrip_datacheck.t new file mode 100644 index 0000000..ffcb9da --- /dev/null +++ b/t/62roundtrip_datacheck.t @@ -0,0 +1,41 @@ +use warnings; +use strict; +use Test::SQL::Translator; +use Test::Differences; +use FindBin qw/$Bin/; + +BEGIN { + maybe_plan(1, 'SQL::Translator::Parser::XML', + 'SQL::Translator::Producer::XML'); +} + +# It's very hard to read and modify YAML by hand. Thus we +# use an XML file for definitions, and generate a YAML from +# it in Makefile.PL, so we do not saddle the user with XML +# dependencies for testing. This test makes sure they do +# not drift apart. + +use SQL::Translator; + +my $base_xml_fn = "$Bin/data/roundtrip.xml"; +my $autogen_yaml_fn = "$Bin/data/roundtrip_autogen.yaml"; + +my $orig_xml = _parse_to_xml ($base_xml_fn, 'XML'); +my $new_xml = _parse_to_xml ($autogen_yaml_fn, 'YAML'); + +eq_or_diff ("$new_xml", "$orig_xml", 'YAML test schema matches original XML schema'); + +sub _parse_to_xml { + my ($fn, $type) = @_; + + my $tr = SQL::Translator->new; + $tr->no_comments (1); # this will drop the XML header + + my $xml = $tr->translate ( + parser => $type, + file => $fn, + producer => 'XML', + ) or die $tr->error; + + return $xml; +} diff --git a/t/data/roundtrip.xml b/t/data/roundtrip.xml new file mode 100644 index 0000000..631d507 --- /dev/null +++ b/t/data/roundtrip.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + Hello emptytagdef + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+
+ + + + SELECT email FROM Basic WHERE (email IS NOT NULL) + + + + + + + update modified=timestamp(); + + + + update modified2=timestamp(); + + + + + + + select foo from bar + Go Sox! + + + + +