Commit | Line | Data |
ed0b4561 |
1 | use warnings; |
2 | use strict; |
d4c630fa |
3 | use Test::More; |
ed0b4561 |
4 | use Test::Differences; |
5 | use 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 | |
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 | |
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 | |
40 | done_testing; |