From: Peter Rabbitson Date: Fri, 25 Nov 2011 10:44:16 +0000 (+0100) Subject: More robust test suite skip-checks, check ENV before loading modules X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=49b3a2641;p=dbsrgits%2FDBIx-Class-Historic.git More robust test suite skip-checks, check ENV before loading modules --- diff --git a/t/51threadtxn.t b/t/51threadtxn.t index 7b11a7b..1245fab 100644 --- a/t/51threadtxn.t +++ b/t/51threadtxn.t @@ -21,13 +21,13 @@ use threads; use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); -plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_pg') - unless DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_pg'); my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' . ' (note: creates and drops a table named artist!)' unless ($dsn && $user); +plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_pg') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_pg'); my $num_children = $ENV{DBICTEST_THREAD_STRESS} || 1; if($num_children !~ /^[0-9]+$/ || $num_children < 10) { diff --git a/t/74mssql.t b/t/74mssql.t index 2470c7f..0ccaa23 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -14,14 +14,15 @@ use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); use DBICTest; -plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mssql_sybase') - unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mssql_sybase'); - my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' unless ($dsn); + +plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mssql_sybase') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mssql_sybase'); + { my $srv_ver = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info->{dbms_version}; ok ($srv_ver, 'Got a test server version on fresh schema: ' . ($srv_ver||'???') ); diff --git a/t/750firebird.t b/t/750firebird.t index 1b4166d..ec45419 100644 --- a/t/750firebird.t +++ b/t/750firebird.t @@ -8,23 +8,21 @@ use lib qw(t/lib); use DBICTest; use Scope::Guard (); -my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_FIREBIRD_${_}" } qw/DSN USER PASS/}; -my ($dsn2, $user2, $pass2) = @ENV{map { "DBICTEST_FIREBIRD_INTERBASE_${_}" } qw/DSN USER PASS/}; -my ($dsn3, $user3, $pass3) = @ENV{map { "DBICTEST_FIREBIRD_ODBC_${_}" } qw/DSN USER PASS/}; - -plan skip_all => 'Test needs ' . - (join ' or ', map { $_ ? $_ : () } - DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_firebird'), - DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_firebird_interbase'), - DBIx::Class::Optional::Dependencies->req_missing_for('test_rdbms_firebird_odbc')) - unless - $dsn && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_firebird') - or - $dsn2 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_firebird_interbase') - or - $dsn3 && DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_firebird_odbc') - or - (not $dsn || $dsn2 || $dsn3); +my $env2optdep = { + DBICTEST_FIREBIRD => 'test_rdbms_firebird', + DBICTEST_FIREBIRD_INTERBASE => 'test_rdbms_firebird_interbase', + DBICTEST_FIREBIRD_ODBC => 'test_rdbms_firebird_odbc', +}; + +plan skip_all => join (' ', + 'Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN}', + 'and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN},', + '_USER and _PASS to run these tests.', + + 'WARNING: this test creates and drops the tables "artist", "bindtype_test" and', + '"sequence_test"; the generators "gen_artist_artistid", "pkid1_seq", "pkid2_seq"', + 'and "nonpkid_seq" and the trigger "artist_bi".', +) unless grep { $ENV{"${_}_DSN"} } keys %$env2optdep; # tests stolen from 749sybase_asa.t @@ -35,29 +33,17 @@ plan skip_all => 'Test needs ' . # Example ODBC DSN: # dbi:ODBC:Driver=Firebird;Dbname=/var/lib/firebird/2.5/data/hlaghdb.fdb -plan skip_all => <<'EOF' unless $dsn || $dsn2 || $dsn3; -Set $ENV{DBICTEST_FIREBIRD_DSN} and/or $ENV{DBICTEST_FIREBIRD_INTERBASE_DSN} -and/or $ENV{DBICTEST_FIREBIRD_ODBC_DSN}, -_USER and _PASS to run these tests. - -WARNING: this test creates and drops the tables "artist", "bindtype_test" and -"sequence_test"; the generators "gen_artist_artistid", "pkid1_seq", "pkid2_seq" -and "nonpkid_seq" and the trigger "artist_bi". -EOF - -my @info = ( - [ $dsn, $user, $pass ], - [ $dsn2, $user2, $pass2 ], - [ $dsn3, $user3, $pass3 ], -); - my $schema; -foreach my $conn_idx (0..$#info) { - my ($dsn, $user, $pass) = @{ $info[$conn_idx] || [] }; +for my $prefix (keys %$env2optdep) { SKIP: { + + my ($dsn, $user, $pass) = map { $ENV{"${prefix}_$_"} } qw/DSN USER PASS/; next unless $dsn; + skip ("Testing with ${prefix}_DSN needs " . DBIx::Class::Optional::Dependencies->req_missing_for( $env2optdep->{$prefix} ), 1) + unless DBIx::Class::Optional::Dependencies->req_ok_for($env2optdep->{$prefix}); + $schema = DBICTest::Schema->connect($dsn, $user, $pass, { auto_savepoint => 1, quote_char => q["], @@ -294,7 +280,7 @@ EOF }; } } -} +}} done_testing; diff --git a/t/84serialize.t b/t/84serialize.t index dedf8da..04e16cb 100644 --- a/t/84serialize.t +++ b/t/84serialize.t @@ -55,23 +55,36 @@ my %stores = ( return $fire; }, - ($ENV{DBICTEST_MEMCACHED}) - ? do { - require Cache::Memcached; - my $memcached = Cache::Memcached->new( - { servers => [ $ENV{DBICTEST_MEMCACHED} ] } ); - - my $key = 'tmp_dbic_84serialize_memcached_test'; - - ( memcached => sub { - $memcached->set( $key, $_[0], 60 ); - local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema; - return $memcached->get($key); - }); - } : () - , ); +if ($ENV{DBICTEST_MEMCACHED}) { + if (DBIx::Class::Optional::Dependencies->req_ok_for ('test_memcached')) { + my $memcached = Cache::Memcached->new( + { servers => [ $ENV{DBICTEST_MEMCACHED} ] } + ); + + my $key = 'tmp_dbic_84serialize_memcached_test'; + + $stores{memcached} = sub { + $memcached->set( $key, $_[0], 60 ); + local $DBIx::Class::ResultSourceHandle::thaw_schema = $schema; + return $memcached->get($key); + }; + } + else { + SKIP: { + skip 'Memcached tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_memcached'), 1; + } + } +} +else { + SKIP: { + skip 'Set $ENV{DBICTEST_MEMCACHED} to run the memcached serialization tests', 1; + } +} + + + for my $name (keys %stores) { my $store = $stores{$name}; diff --git a/t/94versioning.t b/t/94versioning.t index e6eb0e2..09ce788 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -23,7 +23,11 @@ BEGIN { require DBIx::Class; plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') - unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy'); + + plan skip_all => + 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql'); } use_ok('DBICVersion_v1'); diff --git a/t/cdbi/22-deflate_order.t b/t/cdbi/22-deflate_order.t index 1de3f87..cdb8c0d 100644 --- a/t/cdbi/22-deflate_order.t +++ b/t/cdbi/22-deflate_order.t @@ -8,11 +8,6 @@ if ($@) { plan (skip_all => "Time::Piece::MySQL, Class::Trigger and DBIx::ContextualFetch required: $@"); } -plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' - unless ($ENV{DBICTEST_MYSQL_DSN} && $ENV{DBICTEST_MYSQL_USER}); - -plan tests => 3; - use lib 't/cdbi/testlib'; use_ok ('Log'); @@ -27,3 +22,4 @@ $log->update; ok eval { $log->datetime_stamp }, "Have datetime after update"; diag $@ if $@; +done_testing; diff --git a/t/cdbi/columns_as_hashes.t b/t/cdbi/columns_as_hashes.t index 6a9b1bc..06fc149 100644 --- a/t/cdbi/columns_as_hashes.t +++ b/t/cdbi/columns_as_hashes.t @@ -90,8 +90,11 @@ warning_is { # Emulate that Class::DBI inflates immediately SKIP: { - skip "Need MySQL to run this test", 3 unless eval { require MyFoo }; - + unless (eval { require MyFoo }) { + my ($err) = $@ =~ /([^\n]+)/; + skip $err, 3 + } + my $foo = MyFoo->insert({ name => 'Whatever', tdate => '1949-02-01', diff --git a/t/cdbi/testlib/MyBase.pm b/t/cdbi/testlib/MyBase.pm index 6821a39..7885ed5 100644 --- a/t/cdbi/testlib/MyBase.pm +++ b/t/cdbi/testlib/MyBase.pm @@ -8,6 +8,24 @@ use DBI; our $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') +} + +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}); $dbh = DBI->connect(@connect) or die DBI->errstr; my @table;