add constraints after all tables are added
[dbsrgits/SQL-Translator-2.0-ish.git] / t / 62roundtrip_datacheck.t
1 use warnings;
2 use strict;
3 use Test::More;
4 use Test::Differences;
5 use FindBin qw/$Bin/;
6
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
13 use SQL::Translator;
14
15 my $base_xml_fn = "$Bin/data/roundtrip.xml";
16 my $autogen_yaml_fn = "$Bin/data/roundtrip_autogen.yaml";
17
18 my $orig_xml = _parse_to_xml ($base_xml_fn, 'XML');
19 my $new_xml = _parse_to_xml ($autogen_yaml_fn, 'YAML');
20
21 eq_or_diff ("$new_xml", "$orig_xml", 'YAML test schema matches original XML schema');
22
23 sub _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
29   open (my $fh, '<', $fn) or die "$fn: $!"; 
30
31   my $xml = $tr->translate (
32     parser => $type,
33     data => do { local $/; <$fh> },
34     producer => 'XML',
35   ) or die $tr->error;
36
37   return $xml;
38 }
39
40 done_testing;