From: Justin Hunter Date: Sat, 20 Feb 2010 01:42:57 +0000 (-0800) Subject: partial test cleanup, more to come X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=272186989d75fd7739983fab6036b038c2ab0311;p=dbsrgits%2FSQL-Translator-2.0-ish.git partial test cleanup, more to come --- diff --git a/t/38-mysql-producer.t b/t/38-mysql-producer.t index 442b028..efdae10 100644 --- a/t/38-mysql-producer.t +++ b/t/38-mysql-producer.t @@ -1,6 +1,4 @@ #!/usr/bin/perl -w -# vim:filetype=perl - # # Note that the bulk of the testing for the mysql producer is in # 08postgres-to-mysql.t. This test is for additional stuff that can't be tested @@ -10,25 +8,15 @@ use strict; use Test::More; use Test::Exception; -#use Test::SQL::Translator qw(maybe_plan); use Data::Dumper; use FindBin qw/$Bin/; -# Testing 1,2,3,4... -#============================================================================= - -#BEGIN { -# maybe_plan(40, -# 'YAML', -# 'SQL::Translator::Producer::MySQL', -# 'Test::Differences', -# ) -#} use Test::Differences; use SQL::Translator; -# Main test. +my $sqlt; + { my $yaml_in = <new( show_warnings => 1, no_comments => 1, @@ -183,10 +170,9 @@ my $mysql_out = join(";\n\n", @stmts_no_drop) . ";\n\n"; eq_or_diff $out, $mysql_out, "Scalar output looks right with quoting"; my @out = $sqlt->translate(data => $yaml_in) - or die "Translat eerror:".$sqlt->error; + or die "Translate error:".$sqlt->error; is_deeply \@out, \@stmts_no_drop, "Array output looks right with quoting"; - @{$sqlt}{qw/quote_table_names quote_field_names/} = (0,0); $out = $sqlt->translate(data => $yaml_in) or die "Translate error:".$sqlt->error; @@ -200,20 +186,23 @@ my $mysql_out = join(";\n\n", @stmts_no_drop) . ";\n\n"; @{$sqlt}{qw/add_drop_table quote_field_names quote_table_names/} = (1,1,1); @out = $sqlt->translate(data => $yaml_in) - or die "Translat eerror:".$sqlt->error; + or die "Translate error:".$sqlt->error; $out = $sqlt->translate(data => $yaml_in) - or die "Translat eerror:".$sqlt->error; + or die "Translate error:".$sqlt->error; eq_or_diff $out, join(";\n\n", @stmts) . ";\n\n", "Output looks right with DROP TABLEs"; is_deeply \@out, \@stmts, "Array output looks right with DROP TABLEs"; } +my $producer = $sqlt->_producer; +my $parser = $sqlt->_parser; + ############################################################################### # New alter/add subs -my $table = SQL::Translator::Schema::Table->new( name => 'mytable'); +my $table = SQL::Translator::Object::Table->new( name => 'mytable'); -my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield', +my $field1 = SQL::Translator::Object::Column->new( name => 'myfield', table => $table, data_type => 'VARCHAR', size => 10, @@ -223,11 +212,11 @@ my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield', is_foreign_key => 0, is_unique => 0 ); -my $field1_sql = SQL::Translator::Producer::MySQL::create_field($field1); +my $field1_sql = $producer->create_field($field1); is($field1_sql, 'myfield VARCHAR(10)', 'Create field works'); -my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield', +my $field2 = SQL::Translator::Object::Column->new( name => 'myfield', table => $table, data_type => 'VARCHAR', size => 25, @@ -237,29 +226,29 @@ my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield', is_foreign_key => 0, is_unique => 0 ); -my $alter_field = SQL::Translator::Producer::MySQL::alter_field($field1, +my $alter_field = $producer->alter_field($field1, $field2); is($alter_field, 'ALTER TABLE mytable CHANGE COLUMN myfield myfield VARCHAR(25) NOT NULL', 'Alter field works'); -my $add_field = SQL::Translator::Producer::MySQL::add_field($field1); +my $add_field = $producer->add_field($field1); is($add_field, 'ALTER TABLE mytable ADD COLUMN myfield VARCHAR(10)', 'Add field works'); -my $drop_field = SQL::Translator::Producer::MySQL::drop_field($field2); +my $drop_field = $producer->drop_field($field2); is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield', 'Drop field works'); -my $field3 = SQL::Translator::Schema::Field->new( name => 'myfield', +my $field3 = SQL::Translator::Object::Column->new( name => 'myfield', table => $table, data_type => 'boolean', is_nullable => 0, is_foreign_key => 0, is_unique => 0 ); -my $field3_sql = SQL::Translator::Producer::MySQL::create_field($field3, { mysql_version => 4.1 }); +my $field3_sql = $producer->create_field($field3, { mysql_version => 4.1 }); is($field3_sql, 'myfield boolean NOT NULL', 'For Mysql >= 4, use boolean type'); -$field3_sql = SQL::Translator::Producer::MySQL::create_field($field3, { mysql_version => 3.22 }); +$field3_sql = $producer->create_field($field3, { mysql_version => 3.22 }); is($field3_sql, "myfield enum('0','1') NOT NULL", 'For Mysql < 4, use enum for boolean type'); -$field3_sql = SQL::Translator::Producer::MySQL::create_field($field3,); +$field3_sql = $producer->create_field($field3,); is($field3_sql, "myfield enum('0','1') NOT NULL", 'When no version specified, use enum for boolean type'); my $number_sizes = { @@ -270,7 +259,7 @@ my $number_sizes = { }; for my $size (keys %$number_sizes) { my $expected = $number_sizes->{$size}; - my $number_field = SQL::Translator::Schema::Field->new( + my $number_field = SQL::Translator::Object::Column->new( name => "numberfield_$expected", table => $table, data_type => 'number', @@ -281,7 +270,7 @@ for my $size (keys %$number_sizes) { ); is( - SQL::Translator::Producer::MySQL::create_field($number_field), + $producer->create_field($number_field), "numberfield_$expected $expected($size)", "Use $expected for NUMBER types of size $size" ); @@ -289,7 +278,7 @@ for my $size (keys %$number_sizes) { my $varchars; for my $size (qw/255 256 65535 65536/) { - $varchars->{$size} = SQL::Translator::Schema::Field->new( + $varchars->{$size} = SQL::Translator::Object::Column->new( name => "vch_$size", table => $table, data_type => 'varchar', @@ -300,75 +289,75 @@ for my $size (qw/255 256 65535 65536/) { is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{255}, { mysql_version => 5.000003 }), + $producer->create_field($varchars->{255}, { mysql_version => 5.000003 }), 'vch_255 varchar(255)', 'VARCHAR(255) is not substituted with TEXT for Mysql >= 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{255}, { mysql_version => 5.0 }), + $producer->create_field($varchars->{255}, { mysql_version => 5.0 }), 'vch_255 varchar(255)', 'VARCHAR(255) is not substituted with TEXT for Mysql < 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{255}), + $producer->create_field($varchars->{255}), 'vch_255 varchar(255)', 'VARCHAR(255) is not substituted with TEXT when no version specified', ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{256}, { mysql_version => 5.000003 }), + $producer->create_field($varchars->{256}, { mysql_version => 5.000003 }), 'vch_256 varchar(256)', 'VARCHAR(256) is not substituted with TEXT for Mysql >= 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{256}, { mysql_version => 5.0 }), + $producer->create_field($varchars->{256}, { mysql_version => 5.0 }), 'vch_256 text', 'VARCHAR(256) is substituted with TEXT for Mysql < 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{256}), + $producer->create_field($varchars->{256}), 'vch_256 text', 'VARCHAR(256) is substituted with TEXT when no version specified', ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65535}, { mysql_version => 5.000003 }), + $producer->create_field($varchars->{65535}, { mysql_version => 5.000003 }), 'vch_65535 varchar(65535)', 'VARCHAR(65535) is not substituted with TEXT for Mysql >= 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65535}, { mysql_version => 5.0 }), + $producer->create_field($varchars->{65535}, { mysql_version => 5.0 }), 'vch_65535 text', 'VARCHAR(65535) is substituted with TEXT for Mysql < 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65535}), + $producer->create_field($varchars->{65535}), 'vch_65535 text', 'VARCHAR(65535) is substituted with TEXT when no version specified', ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65536}, { mysql_version => 5.000003 }), + $producer->create_field($varchars->{65536}, { mysql_version => 5.000003 }), 'vch_65536 text', 'VARCHAR(65536) is substituted with TEXT for Mysql >= 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65536}, { mysql_version => 5.0 }), + $producer->create_field($varchars->{65536}, { mysql_version => 5.0 }), 'vch_65536 text', 'VARCHAR(65536) is substituted with TEXT for Mysql < 5.0.3' ); is ( - SQL::Translator::Producer::MySQL::create_field($varchars->{65536}), + $producer->create_field($varchars->{65536}), 'vch_65536 text', 'VARCHAR(65536) is substituted with TEXT when no version specified', ); { - my $view1 = SQL::Translator::Schema::View->new( name => 'view_foo', + my $view1 = SQL::Translator::Object::View->new( name => 'view_foo', fields => [qw/id name/], sql => 'SELECT id, name FROM thing', extra => { @@ -377,7 +366,7 @@ is ( mysql_security => 'DEFINER', }); my $create_opts = { add_replace_view => 1, no_comments => 1 }; - my $view1_sql1 = SQL::Translator::Producer::MySQL::create_view($view1, $create_opts); + my $view1_sql1 = $producer->create_view($view1, $create_opts); my $view_sql_replace = "CREATE OR REPLACE ALGORITHM = MERGE @@ -389,11 +378,11 @@ is ( is($view1_sql1, $view_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL'); - my $view2 = SQL::Translator::Schema::View->new( name => 'view_foo', + my $view2 = SQL::Translator::Object::View->new( name => 'view_foo', fields => [qw/id name/], sql => 'SELECT id, name FROM thing',); my $create2_opts = { add_replace_view => 0, no_comments => 1 }; - my $view1_sql2 = SQL::Translator::Producer::MySQL::create_view($view2, $create2_opts); + my $view1_sql2 = $producer->create_view($view2, $create2_opts); my $view_sql_noreplace = "CREATE VIEW view_foo ( id, name ) AS ( SELECT id, name FROM thing @@ -429,7 +418,7 @@ is ( # certain types do not support a size, see also: # http://dev.mysql.com/doc/refman/5.1/de/create-table.html for my $type (qw/date time timestamp datetime year/) { - my $field = SQL::Translator::Schema::Field->new( + my $field = SQL::Translator::Object::Column->new( name => "my$type", table => $table, data_type => $type, @@ -440,7 +429,7 @@ is ( is_foreign_key => 0, is_unique => 0 ); - my $sql = SQL::Translator::Producer::MySQL::create_field($field); + my $sql = $producer->create_field($field); is($sql, "my$type $type", "Skip length param for type $type"); } }