Added BUG notes and test about single tags e.g. <foo/>
[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 Test::More;
8 use Test::Exception;
9
10 use Data::Dumper;
11 BEGIN { our %opt; map { $opt{$_}=1 if s/^-// } @ARGV; }
12 use constant DEBUG => (exists $opt{d} ? 1 : 0);
13 local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
14
15 use FindBin qw/$Bin/;
16
17 # Testing 1,2,3,4...
18 #=============================================================================
19
20 eval { require Template; };
21 if ($@ && $@ =~ m!locate Template.pm in!) {
22     plan skip_all => "You need Template Toolkit to run this test.";
23 }
24 eval { require Test::Differences; };
25 if ($@ && $@ =~ m!locate Test/Differences.pm in!) {
26     plan skip_all => "You need Test::Differences for this test.";
27 }
28 use Test::Differences;
29 plan tests => 3;
30     
31 use SQL::Translator;
32 use SQL::Translator::Producer::TTSchema;
33
34 # Parse the test XML schema
35 our $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 );
47 my $out;
48 lives_ok { $out = $obj->translate; }  "Produced template";
49 ok $out ne ""                        ,"Output has some content";
50 local $/ = undef; # slurp
51 eq_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
55 print $out if DEBUG;
56 #print "Debug:", Dumper($obj) if DEBUG;
57
58 __DATA__
59 Schema: 
60 Database: 
61
62 Table: Basic
63 ==========================================================================
64
65 Fields
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     singletagdef
157         data_type:             varchar
158         size:                  0
159         is_nullable:           1
160         default_value:         
161         is_primary_key:        0
162         is_unique:             0
163         is_auto_increment:     0
164         is_foreign_key:        0
165         foreign_key_reference: 
166         is_valid:              1
167         order:                 7
168         extra:                 
169         table:                 Basic
170     
171
172 Indices
173     titleindex
174         table:    Basic
175         fields:   title
176         type:     NORMAL
177         options:  
178         is_valid: 1
179     
180     
181 Constraints
182     ?
183         type:             PRIMARY KEY
184         fields:           id
185         expression:       
186         match_type:       
187         reference_fields: 
188         reference_table:  
189         deferrable:       1
190         on_delete:        
191         on_update:        
192         options:          
193         is_valid:         1
194     
195     emailuniqueindex
196         type:             UNIQUE
197         fields:           email
198         expression:       
199         match_type:       
200         reference_fields: 
201         reference_table:  
202         deferrable:       1
203         on_delete:        
204         on_update:        
205         options:          
206         is_valid:         1
207