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);
22 local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
26 # Usefull test subs for the schema objs
27 #=============================================================================
30 $ATTRIBUTES{field} = [qw/
44 die "test_field needs a least a name!" unless $test->{name};
45 my $name = $test->{name};
47 foreach my $attr ( @{$ATTRIBUTES{field}} ) {
48 if ( exists $test->{$attr} ) {
49 my $ans = $test->{$attr};
50 if ( $attr =~ m/^is_/ ) {
51 if ($ans) { ok $fld->$attr, " $name - $attr true"; }
52 else { ok !$fld->$attr, " $name - $attr false"; }
55 is $fld->$attr, $ans, " $name - $attr = '"
56 .(defined $ans ? $ans : "NULL" )."'";
60 ok !$fld->$attr, "$name - $attr not set";
68 my $name = $arg{name} || die "Need a table name to test.";
69 my @fldnames = map { $_->{name} } @{$arg{fields}};
70 is_deeply( [ map {$_->name} $tbl->get_fields ],
71 [ map {$_->{name}} @{$arg{fields}} ],
72 "Table $name\'s fields" );
73 foreach ( @{$arg{fields}} ) {
74 my $name = $_->{name} || die "Need a field name to test.";
75 test_field( $tbl->get_field($name), $_ );
80 #=============================================================================
85 use SQL::Translator::Schema::Constants;
87 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
88 # Parse the test XML schema
90 $obj = SQL::Translator->new(
95 die "Can't find test schema $testschema" unless -e $testschema;
96 my $sql = $obj->translate(
99 filename => $testschema,
102 #print "Debug: translator", Dumper($obj) if DEBUG;
103 #print "Debug: schema", Dumper($obj->schema) if DEBUG;
106 # Test the schema objs generted from the XML
108 my $scma = $obj->schema;
109 my @tblnames = map {$_->name} $scma->get_tables;
110 is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording Track/], "tables");
115 test_table( $scma->get_table("Foo"),
121 default_value => undef,
127 data_type => "varchar",
136 test_table( $scma->get_table("Recording"),
140 name => "recordingid",
142 default_value => undef,
148 data_type => "varchar",
153 data_type => "varchar",
162 test_table( $scma->get_table("Track"),
168 default_value => undef,
173 name => "recordingid",
175 default_value => undef,
178 #is_foreign_key => 1,
183 default_value => "1",
188 data_type => "varchar",