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