Commit | Line | Data |
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 |
7 | use strict; |
2b2601b5 |
8 | use Test::More; |
9 | use Test::Exception; |
2d691ec1 |
10 | use Test::SQL::Translator qw(maybe_plan); |
2b2601b5 |
11 | |
12 | use Data::Dumper; |
2b2601b5 |
13 | use FindBin qw/$Bin/; |
14 | |
15 | # Testing 1,2,3,4... |
16 | #============================================================================= |
17 | |
2d691ec1 |
18 | BEGIN { |
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 | } |
25 | use Test::Differences; |
a03aec42 |
26 | |
2b2601b5 |
27 | use SQL::Translator; |
28 | use 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!"; |
49 | local $/ = undef; # slurp |
50 | eq_or_diff $out, <DATA> ,"Output looks right"; |
51 | } |
52 | |
53 | # Test passing of Template config |
54 | { |
55 | my $tmpl = q{ |
56 | [%- FOREACH table = schema.get_tables %] |
57 | Table: $table |
58 | [%- END %]}; |
59 | my $obj; |
60 | $obj = SQL::Translator->new( |
9768b204 |
61 | show_warnings => 0, |
9d6bd3c7 |
62 | from => "XML-SQLFairy", |
63 | filename => "$Bin/data/xml/schema.xml", |
64 | to => "TTSchema", |
65 | producer_args => { |
66 | ttfile => \$tmpl, |
67 | tt_conf => { |
68 | INTERPOLATE => 1, |
69 | }, |
70 | tt_vars => { |
71 | foo => 'bar', |
72 | hello => 'world', |
73 | }, |
74 | }, |
75 | ); |
76 | my $out; |
77 | lives_ok { $out = $obj->translate; } "Translate ran"; |
78 | ok $out ne "" ,"Produced something!"; |
79 | local $/ = undef; # slurp |
80 | eq_or_diff $out, q{ |
b08b5416 |
81 | Table: Basic |
82 | Table: Another} |
9d6bd3c7 |
83 | ,"Output looks right"; |
84 | } |
2b2601b5 |
85 | |
2b2601b5 |
86 | |
87 | __DATA__ |
88 | Schema: |
89 | Database: |
90 | |
046d668a |
91 | Foo: bar |
92 | Hello: world |
93 | |
2b2601b5 |
94 | Table: Basic |
95 | ========================================================================== |
96 | |
97 | Fields |
98 | id |
99 | data_type: int |
100 | size: 10 |
101 | is_nullable: 0 |
102 | default_value: |
103 | is_primary_key: 1 |
104 | is_unique: 0 |
105 | is_auto_increment: 1 |
106 | is_foreign_key: 0 |
107 | foreign_key_reference: |
108 | is_valid: 1 |
109 | order: 1 |
2b2601b5 |
110 | table: Basic |
111 | |
112 | title |
113 | data_type: varchar |
114 | size: 100 |
115 | is_nullable: 0 |
116 | default_value: hello |
117 | is_primary_key: 0 |
118 | is_unique: 0 |
119 | is_auto_increment: 0 |
120 | is_foreign_key: 0 |
121 | foreign_key_reference: |
122 | is_valid: 1 |
123 | order: 2 |
2b2601b5 |
124 | table: Basic |
125 | |
126 | description |
127 | data_type: text |
128 | size: 0 |
129 | is_nullable: 1 |
130 | default_value: |
131 | is_primary_key: 0 |
132 | is_unique: 0 |
133 | is_auto_increment: 0 |
134 | is_foreign_key: 0 |
135 | foreign_key_reference: |
136 | is_valid: 1 |
137 | order: 3 |
2b2601b5 |
138 | table: Basic |
139 | |
140 | email |
141 | data_type: varchar |
21d62b63 |
142 | size: 500 |
2b2601b5 |
143 | is_nullable: 1 |
144 | default_value: |
145 | is_primary_key: 0 |
146 | is_unique: 1 |
147 | is_auto_increment: 0 |
148 | is_foreign_key: 0 |
149 | foreign_key_reference: |
150 | is_valid: 1 |
151 | order: 4 |
2b2601b5 |
152 | table: Basic |
153 | |
154 | explicitnulldef |
155 | data_type: varchar |
156 | size: 0 |
157 | is_nullable: 1 |
158 | default_value: |
159 | is_primary_key: 0 |
160 | is_unique: 0 |
161 | is_auto_increment: 0 |
162 | is_foreign_key: 0 |
163 | foreign_key_reference: |
164 | is_valid: 1 |
165 | order: 5 |
2b2601b5 |
166 | table: Basic |
167 | |
168 | explicitemptystring |
169 | data_type: varchar |
170 | size: 0 |
171 | is_nullable: 1 |
172 | default_value: |
173 | is_primary_key: 0 |
174 | is_unique: 0 |
175 | is_auto_increment: 0 |
176 | is_foreign_key: 0 |
177 | foreign_key_reference: |
178 | is_valid: 1 |
179 | order: 6 |
2b2601b5 |
180 | table: Basic |
181 | |
5952d39c |
182 | emptytagdef |
b3530353 |
183 | data_type: varchar |
184 | size: 0 |
185 | is_nullable: 1 |
186 | default_value: |
187 | is_primary_key: 0 |
188 | is_unique: 0 |
189 | is_auto_increment: 0 |
190 | is_foreign_key: 0 |
191 | foreign_key_reference: |
192 | is_valid: 1 |
193 | order: 7 |
b3530353 |
194 | table: Basic |
195 | |
b08b5416 |
196 | another_id |
197 | data_type: int |
198 | size: 10 |
199 | is_nullable: 1 |
200 | default_value: 2 |
201 | is_primary_key: 0 |
202 | is_unique: 0 |
203 | is_auto_increment: 0 |
204 | is_foreign_key: 1 |
205 | foreign_key_reference: Another |
206 | is_valid: 1 |
207 | order: 8 |
208 | table: Basic |
209 | |
08d91aad |
210 | timest |
211 | data_type: timestamp |
212 | size: 0 |
213 | is_nullable: 1 |
214 | default_value: |
215 | is_primary_key: 0 |
216 | is_unique: 0 |
217 | is_auto_increment: 0 |
218 | is_foreign_key: 0 |
219 | foreign_key_reference: |
220 | is_valid: 1 |
b08b5416 |
221 | order: 9 |
08d91aad |
222 | table: Basic |
223 | |
2b2601b5 |
224 | |
225 | Indices |
226 | titleindex |
227 | table: Basic |
228 | fields: title |
229 | type: NORMAL |
230 | options: |
231 | is_valid: 1 |
232 | |
233 | |
234 | Constraints |
235 | ? |
236 | type: PRIMARY KEY |
237 | fields: id |
238 | expression: |
239 | match_type: |
240 | reference_fields: |
241 | reference_table: |
242 | deferrable: 1 |
243 | on_delete: |
244 | on_update: |
245 | options: |
246 | is_valid: 1 |
247 | |
248 | emailuniqueindex |
249 | type: UNIQUE |
250 | fields: email |
251 | expression: |
252 | match_type: |
253 | reference_fields: |
254 | reference_table: |
255 | deferrable: 1 |
256 | on_delete: |
257 | on_update: |
258 | options: |
259 | is_valid: 1 |
260 | |
b08b5416 |
261 | ? |
262 | type: FOREIGN KEY |
263 | fields: another_id |
264 | expression: |
265 | match_type: |
266 | reference_fields: id |
267 | reference_table: Another |
268 | deferrable: 1 |
269 | on_delete: |
270 | on_update: |
271 | options: |
272 | is_valid: 1 |
273 | |
274 | Table: Another |
275 | ========================================================================== |
276 | |
277 | Fields |
278 | id |
279 | data_type: int |
280 | size: 10 |
281 | is_nullable: 0 |
282 | default_value: |
283 | is_primary_key: 1 |
284 | is_unique: 0 |
285 | is_auto_increment: 1 |
286 | is_foreign_key: 0 |
287 | foreign_key_reference: |
288 | is_valid: 1 |
d37416fd |
289 | order: 1 |
b08b5416 |
290 | table: Another |
291 | |
292 | |
293 | Indices |
294 | |
295 | Constraints |
296 | ? |
297 | type: PRIMARY KEY |
298 | fields: id |
299 | expression: |
300 | match_type: |
301 | reference_fields: |
302 | reference_table: |
303 | deferrable: 1 |
304 | on_delete: |
305 | on_update: |
306 | options: |
307 | is_valid: 1 |
308 | |