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'
20 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
21 use constant DEBUG => (exists $opt{d} ? 1 : 0);
25 # Usefull test subs for the schema objs
26 #=============================================================================
29 $ATTRIBUTES{field} = [qw/
43 die "test_field needs a least a name!" unless $test->{name};
44 my $name = $test->{name};
46 foreach my $attr ( @{$ATTRIBUTES{field}} ) {
47 if ( exists $test->{$attr} ) {
48 my $ans = $test->{$attr};
49 if ( $attr =~ m/^is_/ ) {
50 if ($ans) { ok $fld->$attr, " $name - $attr true"; }
51 else { ok !$fld->$attr, " $name - $attr false"; }
54 is $fld->$attr, $ans, " $name - $attr = '"
55 .(defined $ans ? $ans : "NULL" )."'";
59 ok !$fld->$attr, "$name - $attr not set";
67 my $name = $arg{name} || die "Need a table name to test.";
68 my @fldnames = map { $_->{name} } @{$arg{fields}};
69 is_deeply( [ map {$_->name} $tbl->get_fields ],
70 [ map {$_->{name}} @{$arg{fields}} ],
71 "Table $name\'s fields" );
72 foreach ( @{$arg{fields}} ) {
73 my $name = $_->{name} || die "Need a field name to test.";
74 test_field( $tbl->get_field($name), $_ );
79 #=============================================================================
84 use SQL::Translator::Schema::Constants;
86 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
87 die "Can't find test schema $testschema" unless -e $testschema;
88 my %base_translator_args = (
89 filename => $testschema,
101 $obj = SQL::Translator->new(
102 filename => $testschema,
109 my $sql = $obj->translate;
111 #print "Debug: translator", Dumper($obj) if DEBUG;
112 #print "Debug: schema", Dumper($obj->schema) if DEBUG;
117 my $scma = $obj->schema;
118 my @tblnames = map {$_->name} $scma->get_tables;
119 is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/]
129 test_table( $scma->get_table("Foo"),
135 default_value => undef,
141 data_type => "varchar",
146 name => "protectedname",
147 data_type => "varchar",
148 default_value => undef,
152 name => "privatename",
153 data_type => "varchar",
154 default_value => undef,
163 test_table( $scma->get_table("Recording"),
167 name => "recordingid",
169 default_value => undef,
175 data_type => "varchar",
180 data_type => "varchar",
189 test_table( $scma->get_table("Track"),
195 default_value => undef,
200 name => "recordingid",
202 default_value => undef,
205 #is_foreign_key => 1,
210 default_value => "1",
215 data_type => "varchar",