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