Commit | Line | Data |
dc34f950 |
1 | use warnings; |
2 | use strict; |
3 | use Test::SQL::Translator; |
4 | use Test::Differences; |
5 | use FindBin qw/$Bin/; |
6 | |
7 | BEGIN { |
8 | maybe_plan(1, 'SQL::Translator::Parser::XML', |
9 | 'SQL::Translator::Producer::XML'); |
10 | } |
11 | |
12 | # It's very hard to read and modify YAML by hand. Thus we |
13 | # use an XML file for definitions, and generate a YAML from |
14 | # it in Makefile.PL, so we do not saddle the user with XML |
15 | # dependencies for testing. This test makes sure they do |
16 | # not drift apart. |
17 | |
18 | use SQL::Translator; |
19 | |
20 | my $base_xml_fn = "$Bin/data/roundtrip.xml"; |
21 | my $autogen_yaml_fn = "$Bin/data/roundtrip_autogen.yaml"; |
22 | |
23 | my $orig_xml = _parse_to_xml ($base_xml_fn, 'XML'); |
24 | my $new_xml = _parse_to_xml ($autogen_yaml_fn, 'YAML'); |
25 | |
26 | eq_or_diff ("$new_xml", "$orig_xml", 'YAML test schema matches original XML schema'); |
27 | |
28 | sub _parse_to_xml { |
29 | my ($fn, $type) = @_; |
30 | |
31 | my $tr = SQL::Translator->new; |
32 | $tr->no_comments (1); # this will drop the XML header |
33 | |
34 | my $xml = $tr->translate ( |
35 | parser => $type, |
36 | file => $fn, |
37 | producer => 'XML', |
38 | ) or die $tr->error; |
39 | |
40 | return $xml; |
41 | } |