XML test src changed name.
[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
17 use FindBin qw/$Bin/;
18
19 # Testing 1,2,3,4...
20 #=============================================================================
21
22 BEGIN {
23     maybe_plan(3, 'Template', 'Test::Differences')
24 }
25 use Test::Differences;
26
27 use SQL::Translator;
28 use SQL::Translator::Producer::TTSchema;
29
30 # Parse the test XML schema
31 my $obj;
32 $obj = SQL::Translator->new(
33     debug          => DEBUG, #$opt{d},
34     show_warnings  => 1,
35     add_drop_table => 1,
36     from           => "XML-SQLFairy",
37     filename       => "$Bin/data/xml/schema.xml",
38     to             => "TTSchema",
39      producer_args  => {
40         ttfile => "$Bin/data/template/basic.tt",
41     },
42 );
43 my $out;
44 lives_ok { $out = $obj->translate; }  "Translate ran";
45 ok $out ne ""                        ,"Produced something!";
46 local $/ = undef; # slurp
47 eq_or_diff $out, <DATA>              ,"Output looks right";
48
49 print $out if DEBUG;
50 #print "Debug:", Dumper($obj) if DEBUG;
51
52 __DATA__
53 Schema: 
54 Database: 
55
56 Table: Basic
57 ==========================================================================
58
59 Fields
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     
150     emptytagdef
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     
165
166 Indices
167     titleindex
168         table:    Basic
169         fields:   title
170         type:     NORMAL
171         options:  
172         is_valid: 1
173     
174     
175 Constraints
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