Added TTSchema producer.
[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
7use Test::More;
8use Test::Exception;
9
10use Data::Dumper;
11BEGIN { our %opt; map { $opt{$_}=1 if s/^-// } @ARGV; }
12use constant DEBUG => (exists $opt{d} ? 1 : 0);
13local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
14
15use FindBin qw/$Bin/;
16
17# Testing 1,2,3,4...
18#=============================================================================
19
20eval { require Template; };
21if ($@ && $@ =~ m!locate Template.pm in!) {
22 plan skip_all => "You need Template Toolkit to run this test.";
23}
24eval { require Test::Differences; };
25if ($@ && $@ =~ m!locate Test/Differences.pm in!) {
26 plan skip_all => "You need Test::Differences for this test.";
27}
28use Test::Differences;
29plan tests => 3;
30
31use SQL::Translator;
32use SQL::Translator::Producer::TTSchema;
33
34# Parse the test XML schema
35our $obj;
36$obj = SQL::Translator->new(
37 debug => DEBUG, #$opt{d},
38 show_warnings => 1,
39 add_drop_table => 1,
40 from => "SqlfXML",
41 filename => "$Bin/data/xml/schema-basic.xml",
42 to => "TTSchema",
43 producer_args => {
44 ttfile => "$Bin/data/template/basic.tt",
45 },
46);
47my $out;
48lives_ok { $out = $obj->translate; } "Produced template";
49ok $out ne "" ,"Output has some content";
50local $/ = undef; # slurp
51eq_or_diff $out, <DATA> ,"Output looks right";
52# I'm sure if this diff is the best test, it is probaly too sensitive. But it
53# at least it will blow up if anything changes!
54
55print $out if DEBUG;
56#print "Debug:", Dumper($obj) if DEBUG;
57
58__DATA__
59Schema:
60Database:
61
62Table: Basic
63==========================================================================
64
65Fields
66 id
67 data_type: int
68 size: 10
69 is_nullable: 0
70 default_value:
71 is_primary_key: 1
72 is_unique: 0
73 is_auto_increment: 1
74 is_foreign_key: 0
75 foreign_key_reference:
76 is_valid: 1
77 order: 1
78 extra:
79 table: Basic
80
81 title
82 data_type: varchar
83 size: 100
84 is_nullable: 0
85 default_value: hello
86 is_primary_key: 0
87 is_unique: 0
88 is_auto_increment: 0
89 is_foreign_key: 0
90 foreign_key_reference:
91 is_valid: 1
92 order: 2
93 extra:
94 table: Basic
95
96 description
97 data_type: text
98 size: 0
99 is_nullable: 1
100 default_value:
101 is_primary_key: 0
102 is_unique: 0
103 is_auto_increment: 0
104 is_foreign_key: 0
105 foreign_key_reference:
106 is_valid: 1
107 order: 3
108 extra:
109 table: Basic
110
111 email
112 data_type: varchar
113 size: 255
114 is_nullable: 1
115 default_value:
116 is_primary_key: 0
117 is_unique: 1
118 is_auto_increment: 0
119 is_foreign_key: 0
120 foreign_key_reference:
121 is_valid: 1
122 order: 4
123 extra:
124 table: Basic
125
126 explicitnulldef
127 data_type: varchar
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: 5
138 extra:
139 table: Basic
140
141 explicitemptystring
142 data_type: varchar
143 size: 0
144 is_nullable: 1
145 default_value:
146 is_primary_key: 0
147 is_unique: 0
148 is_auto_increment: 0
149 is_foreign_key: 0
150 foreign_key_reference:
151 is_valid: 1
152 order: 6
153 extra:
154 table: Basic
155
156
157Indices
158 titleindex
159 table: Basic
160 fields: title
161 type: NORMAL
162 options:
163 is_valid: 1
164
165
166Constraints
167 ?
168 type: PRIMARY KEY
169 fields: id
170 expression:
171 match_type:
172 reference_fields:
173 reference_table:
174 deferrable: 1
175 on_delete:
176 on_update:
177 options:
178 is_valid: 1
179
180 emailuniqueindex
181 type: UNIQUE
182 fields: email
183 expression:
184 match_type:
185 reference_fields:
186 reference_table:
187 deferrable: 1
188 on_delete:
189 on_update:
190 options:
191 is_valid: 1
192