Fixed syntax error.
[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, 
24         'XML::XPath', 
25         'SQL::Translator::Parser::XML::SQLFairy',
26         'Template', 
27         'Test::Differences'
28     )
29 }
30 use Test::Differences;
31
32 use SQL::Translator;
33 use SQL::Translator::Producer::TTSchema;
34
35 # Parse the test XML schema
36 my $obj;
37 $obj = SQL::Translator->new(
38     debug          => DEBUG, #$opt{d},
39     show_warnings  => 1,
40     add_drop_table => 1,
41     from           => "XML-SQLFairy",
42     filename       => "$Bin/data/xml/schema.xml",
43     to             => "TTSchema",
44      producer_args  => {
45         ttfile => "$Bin/data/template/basic.tt",
46     },
47 );
48 my $out;
49 lives_ok { $out = $obj->translate; }  "Translate ran";
50 ok $out ne ""                        ,"Produced something!";
51 local $/ = undef; # slurp
52 eq_or_diff $out, <DATA>              ,"Output looks right";
53
54 print $out if DEBUG;
55 #print "Debug:", Dumper($obj) if DEBUG;
56
57 __DATA__
58 Schema: 
59 Database: 
60
61 Table: Basic
62 ==========================================================================
63
64 Fields
65     id
66         data_type:             int
67         size:                  10
68         is_nullable:           0
69         default_value:         
70         is_primary_key:        1
71         is_unique:             0
72         is_auto_increment:     1
73         is_foreign_key:        0
74         foreign_key_reference: 
75         is_valid:              1
76         order:                 1
77         table:                 Basic
78     
79     title
80         data_type:             varchar
81         size:                  100
82         is_nullable:           0
83         default_value:         hello
84         is_primary_key:        0
85         is_unique:             0
86         is_auto_increment:     0
87         is_foreign_key:        0
88         foreign_key_reference: 
89         is_valid:              1
90         order:                 2
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         table:                 Basic
106     
107     email
108         data_type:             varchar
109         size:                  255
110         is_nullable:           1
111         default_value:         
112         is_primary_key:        0
113         is_unique:             1
114         is_auto_increment:     0
115         is_foreign_key:        0
116         foreign_key_reference: 
117         is_valid:              1
118         order:                 4
119         table:                 Basic
120     
121     explicitnulldef
122         data_type:             varchar
123         size:                  0
124         is_nullable:           1
125         default_value:         
126         is_primary_key:        0
127         is_unique:             0
128         is_auto_increment:     0
129         is_foreign_key:        0
130         foreign_key_reference: 
131         is_valid:              1
132         order:                 5
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         table:                 Basic
148     
149     emptytagdef
150         data_type:             varchar
151         size:                  0
152         is_nullable:           1
153         default_value:         
154         is_primary_key:        0
155         is_unique:             0
156         is_auto_increment:     0
157         is_foreign_key:        0
158         foreign_key_reference: 
159         is_valid:              1
160         order:                 7
161         table:                 Basic
162     
163
164 Indices
165     titleindex
166         table:    Basic
167         fields:   title
168         type:     NORMAL
169         options:  
170         is_valid: 1
171     
172     
173 Constraints
174     ?
175         type:             PRIMARY KEY
176         fields:           id
177         expression:       
178         match_type:       
179         reference_fields: 
180         reference_table:  
181         deferrable:       1
182         on_delete:        
183         on_update:        
184         options:          
185         is_valid:         1
186     
187     emailuniqueindex
188         type:             UNIQUE
189         fields:           email
190         expression:       
191         match_type:       
192         reference_fields: 
193         reference_table:  
194         deferrable:       1
195         on_delete:        
196         on_update:        
197         options:          
198         is_valid:         1
199