File: 62roundtrip_datacheck.t

package info (click to toggle)
libsql-translator-perl 0.11024-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,572 kB
  • sloc: perl: 67,471; sql: 3,809; xml: 258; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}