From: Justin Hunter Date: Sat, 22 Aug 2009 21:21:18 +0000 (-0700) Subject: add another roundtrip test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ed0b4561a2e254ad1e8739af075ef3329604373d;p=dbsrgits%2FSQL-Translator-2.0-ish.git add another roundtrip test --- 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; +}