X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi%2Ftestlib%2FMyBase.pm;h=c06f17921b83a1a066409ffb5deb647d4c107008;hb=4b8a53eabdb1629bacdb95f04ca8fc3718ca7c58;hp=eeb7cf0d8dc08635568bd879059d46c5b976bda1;hpb=50891152d0b24649bfd67bdba97feec86b11c064;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi/testlib/MyBase.pm b/t/cdbi/testlib/MyBase.pm index eeb7cf0..c06f179 100644 --- a/t/cdbi/testlib/MyBase.pm +++ b/t/cdbi/testlib/MyBase.pm @@ -2,14 +2,38 @@ package # hide from PAUSE MyBase; use strict; +use DBI; + +use lib 't/lib'; +use DBICTest; + use base qw(DBIx::Class::CDBICompat); -use DBI; +our $dbh; -use vars qw/$dbh/; +my $err; +if (! $ENV{DBICTEST_MYSQL_DSN} ) { + $err = 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'; +} +elsif ( ! DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql') ) { + $err = 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql') +} -# temporary, might get switched to the new test framework someday -my @connect = ("dbi:mysql:test", "", "", { PrintError => 0}); +if ($err) { + my $t = eval { Test::Builder->new }; + if ($t and ! $t->current_test) { + $t->skip_all ($err); + } + else { + die "$err\n"; + } +} + +my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0}); +# this is only so we grab a lock on mysql +{ + my $x = DBICTest::Schema->connect(@connect); +} $dbh = DBI->connect(@connect) or die DBI->errstr; my @table; @@ -19,30 +43,30 @@ END { $dbh->do("DROP TABLE $_") foreach @table } __PACKAGE__->connection(@connect); sub set_table { - my $class = shift; - $class->table($class->create_test_table); + my $class = shift; + $class->table($class->create_test_table); } sub create_test_table { - my $self = shift; - my $table = $self->next_available_table; - my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; - push @table, $table; - $dbh->do($create); - return $table; + my $self = shift; + my $table = $self->next_available_table; + my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; + push @table, $table; + $dbh->do($create); + return $table; } sub next_available_table { - my $self = shift; - my @tables = sort @{ - $dbh->selectcol_arrayref( - qq{ + my $self = shift; + my @tables = sort @{ + $dbh->selectcol_arrayref( + qq{ SHOW TABLES } - ) - }; - my $table = $tables[-1] || "aaa"; - return "z$table"; + ) + }; + my $table = $tables[-1] || "aaa"; + return "z$table"; } 1;