From: Mark Addison Date: Wed, 1 Oct 2003 21:55:05 +0000 (+0000) Subject: Tidy up, as they seemed to be a bit of a mess. X-Git-Tag: v0.04~157 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd5abbd7b779462eac9cdff9c0c2028b6c372ed1;p=dbsrgits%2FSQL-Translator.git Tidy up, as they seemed to be a bit of a mess. --- diff --git a/t/21xml-xmi-parser.t b/t/21xml-xmi-parser.t index 773d8b9..15939c5 100644 --- a/t/21xml-xmi-parser.t +++ b/t/21xml-xmi-parser.t @@ -5,22 +5,22 @@ # `make test'. After `make install' it should work as `perl test.pl' # -# basic.t -# ------- -# Tests that; +# Tests basic functionality and the default xmi2schema # use strict; -use Test::More; -use Test::Exception; - -use strict; +use FindBin qw/$Bin/; use Data::Dumper; + +# run test with -d for debug my %opt; BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; } use constant DEBUG => (exists $opt{d} ? 1 : 0); -use FindBin qw/$Bin/; +use Test::More; +use Test::Exception; +use SQL::Translator; +use SQL::Translator::Schema::Constants; # Usefull test subs for the schema objs #============================================================================= @@ -80,23 +80,9 @@ sub test_table { plan tests => 103; -use SQL::Translator; -use SQL::Translator::Schema::Constants; - my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; -my %base_translator_args = ( - filename => $testschema, - from => 'XML-XMI', - to => 'MySQL', - debug => DEBUG, - show_warnings => 1, - add_drop_table => 1, -); -# -# Basic tests -# my $obj; $obj = SQL::Translator->new( filename => $testschema, @@ -104,12 +90,9 @@ $obj = SQL::Translator->new( to => 'MySQL', debug => DEBUG, show_warnings => 1, - add_drop_table => 1, ); my $sql = $obj->translate; print $sql if DEBUG; -#print "Debug: translator", Dumper($obj) if DEBUG; -#print "Debug: schema", Dumper($obj->schema) if DEBUG; # # Test the schema @@ -119,8 +102,6 @@ my @tblnames = map {$_->name} $scma->get_tables; is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/] ,"tables"); -# - # # Tables # diff --git a/t/22xml-xmi-parser-visibility.t b/t/22xml-xmi-parser-visibility.t index 2f8b39d..acad644 100644 --- a/t/22xml-xmi-parser-visibility.t +++ b/t/22xml-xmi-parser-visibility.t @@ -5,100 +5,29 @@ # `make test'. After `make install' it should work as `perl test.pl' # -# basic.t -# ------- -# Tests that; +# Tests the visibility arg. # use strict; -use Test::More; -use Test::Exception; - -use strict; +use FindBin qw/$Bin/; use Data::Dumper; + +# run test with -d for debug my %opt; BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; } use constant DEBUG => (exists $opt{d} ? 1 : 0); -use FindBin qw/$Bin/; - -# Usefull test subs for the schema objs -#============================================================================= - -my %ATTRIBUTES; -$ATTRIBUTES{field} = [qw/ -name -data_type -default_value -size -is_primary_key -is_unique -is_nullable -is_foreign_key -is_auto_increment -/]; - -sub test_field { - my ($fld,$test) = @_; - die "test_field needs a least a name!" unless $test->{name}; - my $name = $test->{name}; - - foreach my $attr ( @{$ATTRIBUTES{field}} ) { - if ( exists $test->{$attr} ) { - my $ans = $test->{$attr}; - if ( $attr =~ m/^is_/ ) { - if ($ans) { ok $fld->$attr, " $name - $attr true"; } - else { ok !$fld->$attr, " $name - $attr false"; } - } - else { - is $fld->$attr, $ans, " $name - $attr = '" - .(defined $ans ? $ans : "NULL" )."'"; - } - } - else { - ok !$fld->$attr, "$name - $attr not set"; - } - } -} - -sub test_table { - my $tbl = shift; - my %arg = @_; - my $name = $arg{name} || die "Need a table name to test."; - my @fldnames = map { $_->{name} } @{$arg{fields}}; - is_deeply( [ map {$_->name} $tbl->get_fields ], - [ map {$_->{name}} @{$arg{fields}} ], - "Table $name\'s fields" ); - foreach ( @{$arg{fields}} ) { - my $name = $_->{name} || die "Need a field name to test."; - test_field( $tbl->get_field($name), $_ ); - } -} +use Test::More; +use Test::Exception; +use SQL::Translator; +use SQL::Translator::Schema::Constants; -# Testing 1,2,3,.. -#============================================================================= plan tests => 8; -use SQL::Translator; -use SQL::Translator::Schema::Constants; - my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; -my %base_translator_args = ( - filename => $testschema, - from => 'XML-XMI', - to => 'MySQL', - debug => DEBUG, - show_warnings => 1, - add_drop_table => 1, -); - -# -# Visibility tests -# -# Classes my @testd = ( "" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/], [qw/fooid name protectedname privatename/], @@ -117,20 +46,19 @@ my @testd = ( to => 'MySQL', debug => DEBUG, show_warnings => 1, - add_drop_table => 1, parser_args => { visibility => $vis, }, ); my $sql = $obj->translate; + print $sql if DEBUG; my $scma = $obj->schema; - my @tblnames = map {$_->name} $scma->get_tables; + # Tables from classes + my @tblnames = map {$_->name} $scma->get_tables; is_deeply( \@tblnames, $tables, "Tables with visibility => '$vis'"); + # Fields from attributes my @fldnames = map {$_->name} $scma->get_table("Foo")->get_fields; is_deeply( \@fldnames, $foofields, "Foo fields with visibility => '$vis'"); - - #print "Debug: translator", Dumper($obj) if DEBUG; - #print "Debug: schema", Dumper($obj->schema) if DEBUG; }