Update tests to use maybe_plan.
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
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
7 use strict;
8 use Test::More;
9 use Test::Exception;
10 use Test::SQL::Translator qw(maybe_plan);
11
12 use Data::Dumper;
13 use vars '%opt';
14 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
15 use constant DEBUG => (exists $opt{d} ? 1 : 0);
16 local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
17
18 use FindBin qw/$Bin/;
19
20 # Testing 1,2,3,4...
21 #=============================================================================
22
23 BEGIN {
24     maybe_plan(3, 'Template', 'Test::Differences')
25 }
26 use Test::Differences;
27     
28 use SQL::Translator;
29 use SQL::Translator::Producer::TTSchema;
30
31 # Parse the test XML schema
32 my $obj;
33 $obj = SQL::Translator->new(
34     debug          => DEBUG, #$opt{d},
35     show_warnings  => 1,
36     add_drop_table => 1,
37     from           => "XML-SQLFairy",
38     filename       => "$Bin/data/xml/schema-basic.xml",
39     to             => "TTSchema",
40      producer_args  => {
41         ttfile => "$Bin/data/template/basic.tt",
42     },
43 );
44 my $out;
45 lives_ok { $out = $obj->translate; }  "Translate ran";
46 ok $out ne ""                        ,"Produced something!";
47 local $/ = undef; # slurp
48 eq_or_diff $out, <DATA>              ,"Output looks right";
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!
51
52 print $out if DEBUG;
53 #print "Debug:", Dumper($obj) if DEBUG;
54
55 __DATA__
56 Schema: 
57 Database: 
58
59 Table: Basic
60 ==========================================================================
61
62 Fields
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     
153     emptytagdef
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     
168
169 Indices
170     titleindex
171         table:    Basic
172         fields:   title
173         type:     NORMAL
174         options:  
175         is_valid: 1
176     
177     
178 Constraints
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