I needed to be able to pass in additional information to the templates (beyond the...
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
CommitLineData
2b2601b5 1#!/usr/bin/perl -w
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;
2e11379e 13use vars '%opt';
14BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
2b2601b5 15use constant DEBUG => (exists $opt{d} ? 1 : 0);
2b2601b5 16
17use FindBin qw/$Bin/;
18
19# Testing 1,2,3,4...
20#=============================================================================
21
2d691ec1 22BEGIN {
d2f0a9f6 23 maybe_plan(3,
24 'XML::XPath',
d55fe5ca 25 'SQL::Translator::Parser::XML::SQLFairy',
d2f0a9f6 26 'Template',
27 'Test::Differences'
28 )
2b2601b5 29}
30use Test::Differences;
a03aec42 31
2b2601b5 32use SQL::Translator;
33use SQL::Translator::Producer::TTSchema;
34
35# Parse the test XML schema
2e11379e 36my $obj;
2b2601b5 37$obj = SQL::Translator->new(
38 debug => DEBUG, #$opt{d},
39 show_warnings => 1,
40 add_drop_table => 1,
2e11379e 41 from => "XML-SQLFairy",
7266dab2 42 filename => "$Bin/data/xml/schema.xml",
2b2601b5 43 to => "TTSchema",
44 producer_args => {
45 ttfile => "$Bin/data/template/basic.tt",
46 },
47);
48my $out;
0da6f155 49lives_ok { $out = $obj->translate; } "Translate ran";
50ok $out ne "" ,"Produced something!";
2b2601b5 51local $/ = undef; # slurp
52eq_or_diff $out, <DATA> ,"Output looks right";
2b2601b5 53
54print $out if DEBUG;
55#print "Debug:", Dumper($obj) if DEBUG;
56
57__DATA__
58Schema:
59Database:
60
61Table: Basic
62==========================================================================
63
64Fields
65 id
66 data_type: int
67 size: 10
68 is_nullable: 0
69 default_value:
70 is_primary_key: 1
71 is_unique: 0
72 is_auto_increment: 1
73 is_foreign_key: 0
74 foreign_key_reference:
75 is_valid: 1
76 order: 1
2b2601b5 77 table: Basic
78
79 title
80 data_type: varchar
81 size: 100
82 is_nullable: 0
83 default_value: hello
84 is_primary_key: 0
85 is_unique: 0
86 is_auto_increment: 0
87 is_foreign_key: 0
88 foreign_key_reference:
89 is_valid: 1
90 order: 2
2b2601b5 91 table: Basic
92
93 description
94 data_type: text
95 size: 0
96 is_nullable: 1
97 default_value:
98 is_primary_key: 0
99 is_unique: 0
100 is_auto_increment: 0
101 is_foreign_key: 0
102 foreign_key_reference:
103 is_valid: 1
104 order: 3
2b2601b5 105 table: Basic
106
107 email
108 data_type: varchar
109 size: 255
110 is_nullable: 1
111 default_value:
112 is_primary_key: 0
113 is_unique: 1
114 is_auto_increment: 0
115 is_foreign_key: 0
116 foreign_key_reference:
117 is_valid: 1
118 order: 4
2b2601b5 119 table: Basic
120
121 explicitnulldef
122 data_type: varchar
123 size: 0
124 is_nullable: 1
125 default_value:
126 is_primary_key: 0
127 is_unique: 0
128 is_auto_increment: 0
129 is_foreign_key: 0
130 foreign_key_reference:
131 is_valid: 1
132 order: 5
2b2601b5 133 table: Basic
134
135 explicitemptystring
136 data_type: varchar
137 size: 0
138 is_nullable: 1
139 default_value:
140 is_primary_key: 0
141 is_unique: 0
142 is_auto_increment: 0
143 is_foreign_key: 0
144 foreign_key_reference:
145 is_valid: 1
146 order: 6
2b2601b5 147 table: Basic
148
5952d39c 149 emptytagdef
b3530353 150 data_type: varchar
151 size: 0
152 is_nullable: 1
153 default_value:
154 is_primary_key: 0
155 is_unique: 0
156 is_auto_increment: 0
157 is_foreign_key: 0
158 foreign_key_reference:
159 is_valid: 1
160 order: 7
b3530353 161 table: Basic
162
2b2601b5 163
164Indices
165 titleindex
166 table: Basic
167 fields: title
168 type: NORMAL
169 options:
170 is_valid: 1
171
172
173Constraints
174 ?
175 type: PRIMARY KEY
176 fields: id
177 expression:
178 match_type:
179 reference_fields:
180 reference_table:
181 deferrable: 1
182 on_delete:
183 on_update:
184 options:
185 is_valid: 1
186
187 emailuniqueindex
188 type: UNIQUE
189 fields: email
190 expression:
191 match_type:
192 reference_fields:
193 reference_table:
194 deferrable: 1
195 on_delete:
196 on_update:
197 options:
198 is_valid: 1
199