Release commit for 1.62
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
CommitLineData
aee4b66e 1#!/usr/bin/perl -w
2b2601b5 2# vim:filetype=perl
3
4# Before `make install' is performed this script should be runnable with
5# `make test'. After `make install' it should work as `perl test.pl'
6
2e11379e 7use strict;
2b2601b5 8use Test::More;
9use Test::Exception;
2d691ec1 10use Test::SQL::Translator qw(maybe_plan);
2b2601b5 11
12use Data::Dumper;
2b2601b5 13use FindBin qw/$Bin/;
14
15# Testing 1,2,3,4...
16#=============================================================================
17
2d691ec1 18BEGIN {
3e1ed76b 19 maybe_plan(6,
d55fe5ca 20 'SQL::Translator::Parser::XML::SQLFairy',
3e1ed76b 21 'Template 2.20',
d2f0a9f6 22 'Test::Differences'
08918cf7 23 );
2b2601b5 24}
25use Test::Differences;
a03aec42 26
2b2601b5 27use SQL::Translator;
28use SQL::Translator::Producer::TTSchema;
29
9d6bd3c7 30# Main test. Template whole schema and test tt_vars
31{
32 my $obj;
33 $obj = SQL::Translator->new(
9768b204 34 show_warnings => 0,
9d6bd3c7 35 from => "XML-SQLFairy",
36 filename => "$Bin/data/xml/schema.xml",
37 to => "TTSchema",
38 producer_args => {
39 ttfile => "$Bin/data/template/basic.tt",
40 tt_vars => {
41 foo => 'bar',
42 hello => 'world',
43 },
046d668a 44 },
9d6bd3c7 45 );
46 my $out;
47 lives_ok { $out = $obj->translate; } "Translate ran";
48 ok $out ne "" ,"Produced something!";
aee4b66e 49 eq_or_diff
50 $out,
51 do { local (@ARGV, $/) = "$Bin/data/template/testresult_basic.txt"; <> },
52 "Output looks right"
53 ;
9d6bd3c7 54}
55
56# Test passing of Template config
57{
58 my $tmpl = q{
59 [%- FOREACH table = schema.get_tables %]
60 Table: $table
61 [%- END %]};
62 my $obj;
63 $obj = SQL::Translator->new(
9768b204 64 show_warnings => 0,
9d6bd3c7 65 from => "XML-SQLFairy",
66 filename => "$Bin/data/xml/schema.xml",
67 to => "TTSchema",
68 producer_args => {
69 ttfile => \$tmpl,
70 tt_conf => {
71 INTERPOLATE => 1,
72 },
73 tt_vars => {
74 foo => 'bar',
75 hello => 'world',
76 },
77 },
78 );
79 my $out;
80 lives_ok { $out = $obj->translate; } "Translate ran";
81 ok $out ne "" ,"Produced something!";
82 local $/ = undef; # slurp
83 eq_or_diff $out, q{
b08b5416 84 Table: Basic
85 Table: Another}
9d6bd3c7 86 ,"Output looks right";
87}