add constraints after all tables are added
[dbsrgits/SQL-Translator-2.0-ish.git] / t / 62roundtrip_datacheck.t
CommitLineData
ed0b4561 1use warnings;
2use strict;
d4c630fa 3use Test::More;
ed0b4561 4use Test::Differences;
5use FindBin qw/$Bin/;
6
ed0b4561 7# It's very hard to read and modify YAML by hand. Thus we
8# use an XML file for definitions, and generate a YAML from
9# it in Makefile.PL, so we do not saddle the user with XML
10# dependencies for testing. This test makes sure they do
11# not drift apart.
12
13use SQL::Translator;
14
15my $base_xml_fn = "$Bin/data/roundtrip.xml";
16my $autogen_yaml_fn = "$Bin/data/roundtrip_autogen.yaml";
17
18my $orig_xml = _parse_to_xml ($base_xml_fn, 'XML');
19my $new_xml = _parse_to_xml ($autogen_yaml_fn, 'YAML');
20
21eq_or_diff ("$new_xml", "$orig_xml", 'YAML test schema matches original XML schema');
22
23sub _parse_to_xml {
24 my ($fn, $type) = @_;
25
26 my $tr = SQL::Translator->new;
27 $tr->no_comments (1); # this will drop the XML header
28
d4c630fa 29 open (my $fh, '<', $fn) or die "$fn: $!";
30
ed0b4561 31 my $xml = $tr->translate (
32 parser => $type,
d4c630fa 33 data => do { local $/; <$fh> },
ed0b4561 34 producer => 'XML',
35 ) or die $tr->error;
36
37 return $xml;
38}
d4c630fa 39
40done_testing;