Update tests to use maybe_plan.
[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);
16local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
17
18use FindBin qw/$Bin/;
19
20# Testing 1,2,3,4...
21#=============================================================================
22
2d691ec1 23BEGIN {
24 maybe_plan(3, 'Template', 'Test::Differences')
2b2601b5 25}
26use Test::Differences;
2b2601b5 27
28use SQL::Translator;
29use SQL::Translator::Producer::TTSchema;
30
31# Parse the test XML schema
2e11379e 32my $obj;
2b2601b5 33$obj = SQL::Translator->new(
34 debug => DEBUG, #$opt{d},
35 show_warnings => 1,
36 add_drop_table => 1,
2e11379e 37 from => "XML-SQLFairy",
2b2601b5 38 filename => "$Bin/data/xml/schema-basic.xml",
39 to => "TTSchema",
40 producer_args => {
41 ttfile => "$Bin/data/template/basic.tt",
42 },
43);
44my $out;
0da6f155 45lives_ok { $out = $obj->translate; } "Translate ran";
46ok $out ne "" ,"Produced something!";
2b2601b5 47local $/ = undef; # slurp
48eq_or_diff $out, <DATA> ,"Output looks right";
0da6f155 49# I'm not sure if this diff is the best test, it is probaly too sensitive. But
50# it at least it will blow up if anything changes!
2b2601b5 51
52print $out if DEBUG;
53#print "Debug:", Dumper($obj) if DEBUG;
54
55__DATA__
56Schema:
57Database:
58
59Table: Basic
60==========================================================================
61
62Fields
63 id
64 data_type: int
65 size: 10
66 is_nullable: 0
67 default_value:
68 is_primary_key: 1
69 is_unique: 0
70 is_auto_increment: 1
71 is_foreign_key: 0
72 foreign_key_reference:
73 is_valid: 1
74 order: 1
75 extra:
76 table: Basic
77
78 title
79 data_type: varchar
80 size: 100
81 is_nullable: 0
82 default_value: hello
83 is_primary_key: 0
84 is_unique: 0
85 is_auto_increment: 0
86 is_foreign_key: 0
87 foreign_key_reference:
88 is_valid: 1
89 order: 2
90 extra:
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
105 extra:
106 table: Basic
107
108 email
109 data_type: varchar
110 size: 255
111 is_nullable: 1
112 default_value:
113 is_primary_key: 0
114 is_unique: 1
115 is_auto_increment: 0
116 is_foreign_key: 0
117 foreign_key_reference:
118 is_valid: 1
119 order: 4
120 extra:
121 table: Basic
122
123 explicitnulldef
124 data_type: varchar
125 size: 0
126 is_nullable: 1
127 default_value:
128 is_primary_key: 0
129 is_unique: 0
130 is_auto_increment: 0
131 is_foreign_key: 0
132 foreign_key_reference:
133 is_valid: 1
134 order: 5
135 extra:
136 table: Basic
137
138 explicitemptystring
139 data_type: varchar
140 size: 0
141 is_nullable: 1
142 default_value:
143 is_primary_key: 0
144 is_unique: 0
145 is_auto_increment: 0
146 is_foreign_key: 0
147 foreign_key_reference:
148 is_valid: 1
149 order: 6
150 extra:
151 table: Basic
152
5952d39c 153 emptytagdef
b3530353 154 data_type: varchar
155 size: 0
156 is_nullable: 1
157 default_value:
158 is_primary_key: 0
159 is_unique: 0
160 is_auto_increment: 0
161 is_foreign_key: 0
162 foreign_key_reference:
163 is_valid: 1
164 order: 7
165 extra:
166 table: Basic
167
2b2601b5 168
169Indices
170 titleindex
171 table: Basic
172 fields: title
173 type: NORMAL
174 options:
175 is_valid: 1
176
177
178Constraints
179 ?
180 type: PRIMARY KEY
181 fields: id
182 expression:
183 match_type:
184 reference_fields:
185 reference_table:
186 deferrable: 1
187 on_delete:
188 on_update:
189 options:
190 is_valid: 1
191
192 emailuniqueindex
193 type: UNIQUE
194 fields: email
195 expression:
196 match_type:
197 reference_fields:
198 reference_table:
199 deferrable: 1
200 on_delete:
201 on_update:
202 options:
203 is_valid: 1
204