Allow "gutter" to be set by producer arg (Markus Törnqvist).
[dbsrgits/SQL-Translator.git] / t / 18ttschema-producer.t
CommitLineData
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 7use strict;
2b2601b5 8use Test::More;
9use Test::Exception;
2d691ec1 10use Test::SQL::Translator qw(maybe_plan);
2b2601b5 11
12use Data::Dumper;
2e11379e 13use vars '%opt';
14BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
2b2601b5 15use constant DEBUG => (exists $opt{d} ? 1 : 0);
2b2601b5 16
17use FindBin qw/$Bin/;
18
19# Testing 1,2,3,4...
20#=============================================================================
21
2d691ec1 22BEGIN {
23 maybe_plan(3, 'Template', 'Test::Differences')
2b2601b5 24}
25use Test::Differences;
a03aec42 26
2b2601b5 27use SQL::Translator;
28use SQL::Translator::Producer::TTSchema;
29
30# Parse the test XML schema
2e11379e 31my $obj;
2b2601b5 32$obj = SQL::Translator->new(
33 debug => DEBUG, #$opt{d},
34 show_warnings => 1,
35 add_drop_table => 1,
2e11379e 36 from => "XML-SQLFairy",
7266dab2 37 filename => "$Bin/data/xml/schema.xml",
2b2601b5 38 to => "TTSchema",
39 producer_args => {
40 ttfile => "$Bin/data/template/basic.tt",
41 },
42);
43my $out;
0da6f155 44lives_ok { $out = $obj->translate; } "Translate ran";
45ok $out ne "" ,"Produced something!";
2b2601b5 46local $/ = undef; # slurp
47eq_or_diff $out, <DATA> ,"Output looks right";
2b2601b5 48
49print $out if DEBUG;
50#print "Debug:", Dumper($obj) if DEBUG;
51
52__DATA__
53Schema:
54Database:
55
56Table: Basic
57==========================================================================
58
59Fields
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
2b2601b5 72 table: Basic
73
74 title
75 data_type: varchar
76 size: 100
77 is_nullable: 0
78 default_value: hello
79 is_primary_key: 0
80 is_unique: 0
81 is_auto_increment: 0
82 is_foreign_key: 0
83 foreign_key_reference:
84 is_valid: 1
85 order: 2
2b2601b5 86 table: Basic
87
88 description
89 data_type: text
90 size: 0
91 is_nullable: 1
92 default_value:
93 is_primary_key: 0
94 is_unique: 0
95 is_auto_increment: 0
96 is_foreign_key: 0
97 foreign_key_reference:
98 is_valid: 1
99 order: 3
2b2601b5 100 table: Basic
101
102 email
103 data_type: varchar
104 size: 255
105 is_nullable: 1
106 default_value:
107 is_primary_key: 0
108 is_unique: 1
109 is_auto_increment: 0
110 is_foreign_key: 0
111 foreign_key_reference:
112 is_valid: 1
113 order: 4
2b2601b5 114 table: Basic
115
116 explicitnulldef
117 data_type: varchar
118 size: 0
119 is_nullable: 1
120 default_value:
121 is_primary_key: 0
122 is_unique: 0
123 is_auto_increment: 0
124 is_foreign_key: 0
125 foreign_key_reference:
126 is_valid: 1
127 order: 5
2b2601b5 128 table: Basic
129
130 explicitemptystring
131 data_type: varchar
132 size: 0
133 is_nullable: 1
134 default_value:
135 is_primary_key: 0
136 is_unique: 0
137 is_auto_increment: 0
138 is_foreign_key: 0
139 foreign_key_reference:
140 is_valid: 1
141 order: 6
2b2601b5 142 table: Basic
143
5952d39c 144 emptytagdef
b3530353 145 data_type: varchar
146 size: 0
147 is_nullable: 1
148 default_value:
149 is_primary_key: 0
150 is_unique: 0
151 is_auto_increment: 0
152 is_foreign_key: 0
153 foreign_key_reference:
154 is_valid: 1
155 order: 7
b3530353 156 table: Basic
157
2b2601b5 158
159Indices
160 titleindex
161 table: Basic
162 fields: title
163 type: NORMAL
164 options:
165 is_valid: 1
166
167
168Constraints
169 ?
170 type: PRIMARY KEY
171 fields: id
172 expression:
173 match_type:
174 reference_fields:
175 reference_table:
176 deferrable: 1
177 on_delete:
178 on_update:
179 options:
180 is_valid: 1
181
182 emailuniqueindex
183 type: UNIQUE
184 fields: email
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