From: Dagfinn Ilmari Mannsåker Date: Sat, 13 Jun 2015 20:10:21 +0000 (+0100) Subject: Convert the tests with multiple DBDs to new optdeps system X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=ffd4ce367abb2ebc8bfa611e091b5f3b181ab795 Convert the tests with multiple DBDs to new optdeps system XXX: Needs refactoring. --- diff --git a/t/10_07mssql_common.t b/t/10_07mssql_common.t index 4bf8721..da3b49d 100644 --- a/t/10_07mssql_common.t +++ b/t/10_07mssql_common.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; use Test::Exception; -use DBIx::Class::Optional::Dependencies; +use DBIx::Class::Schema::Loader::Optional::Dependencies; use DBIx::Class::Schema::Loader::Utils qw/warnings_exist_silent sigwarn_silencer/; use Try::Tiny; use File::Path 'rmtree'; @@ -29,22 +29,35 @@ my $schema; my (%dsns, $common_version); -for (qw/MSSQL MSSQL_ODBC MSSQL_ADO/) { - next unless $ENV{"DBICTEST_${_}_DSN"}; +my %env2optdep = ( + MSSQL => 'test_rdbms_mssql_sybase', + MSSQL_ODBC => 'test_rdbms_mssql_odbc', + MSSQL_ADO => 'test_rdbms_mssql_ado', +); - (my $dep_group = lc "rdbms_$_") =~ s/mssql$/mssql_sybase/; - if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) { - diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group) - . " to test with $_"; +plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map + { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" } + values %env2optdep +) unless scalar grep + { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) } + values %env2optdep +; + +for my $type (keys %env2optdep) { + my %conninfo; + @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS); + next unless $conninfo{dsn}; + + my $dep_group = $env2optdep{$type}; + if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) { + diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group); next; } - $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"}; - $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"}; - $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"}; + $dsns{$type} = \%conninfo; require DBI; - my $dbh = DBI->connect (@{$dsns{$_}}{qw/dsn user password/}, { RaiseError => 1, PrintError => 0} ); + my $dbh = DBI->connect (@{$dsns{$type}}{qw/dsn user password/}, { RaiseError => 1, PrintError => 0} ); my $srv_ver = eval { $dbh->get_info(18) || @@ -58,9 +71,6 @@ for (qw/MSSQL MSSQL_ODBC MSSQL_ADO/) { } } -plan skip_all => 'You need to set the DBICTEST_MSSQL_DSN, _USER and _PASS and/or the DBICTEST_MSSQL_ODBC_DSN, _USER and _PASS environment variables' - unless %dsns; - my $mssql_2008_new_data_types = { date => { data_type => 'date' }, time => { data_type => 'time' }, diff --git a/t/10_08sqlanywhere_common.t b/t/10_08sqlanywhere_common.t index 6f1f58e..da9837b 100644 --- a/t/10_08sqlanywhere_common.t +++ b/t/10_08sqlanywhere_common.t @@ -20,24 +20,30 @@ use constant EXTRA_DUMP_DIR => "$tdir/sqlanywhere_extra_dump"; # # Setting them to zero is preferred. -my %dsns; -for (qw(SQLANYWHERE SQLANYWHERE_ODBC)) { - next unless $ENV{"DBICTEST_${_}_DSN"}; +my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(SQLANYWHERE SQLANYWHERE_ODBC); + +plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map + { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" } + values %env2optdep +) unless scalar grep + { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) } + values %env2optdep +; - my $dep_group = lc "rdbms_$_"; - if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) { - diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group) - . " to test with $_"; +my %dsns; +for my $type (keys %env2optdep) { + my %conninfo; + @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS); + next unless $conninfo{dsn}; + + my $dep_group = $env2optdep{$type}; + if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) { + diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group); next; } - $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"}; - $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"}; - $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"}; -}; - -plan skip_all => 'You need to set the DBICTEST_SQLANYWHERE_DSN, _USER and _PASS and/or the DBICTEST_SQLANYWHERE_ODBC_DSN, _USER and _PASS environment variables' - unless %dsns; + $dsns{$type} = \%conninfo; +} my ($schema, $schemas_created); # for cleanup in END for extra tests diff --git a/t/10_09firebird_common.t b/t/10_09firebird_common.t index 50b74be..358c60a 100644 --- a/t/10_09firebird_common.t +++ b/t/10_09firebird_common.t @@ -2,32 +2,38 @@ use strict; use warnings; use Test::More; use Scope::Guard (); -use DBIx::Class::Optional::Dependencies; +use DBIx::Class::Schema::Loader::Optional::Dependencies; use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/; use lib qw(t/lib); use dbixcsl_common_tests; -my %dsns; -for (qw(FIREBIRD FIREBIRD_ODBC FIREBIRD_INTERBASE)) { - next unless $ENV{"DBICTEST_${_}_DSN"}; +my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(FIREBIRD FIREBIRD_INTERBASE FIREBIRD_ODBC); + +plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map + { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" } + values %env2optdep +) unless scalar grep + { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) } + values %env2optdep +; - my $dep_group = lc "rdbms_$_"; - if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) { - diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group) - . " to test with $_"; +my %dsns; +for my $type (keys %env2optdep) { + my %conninfo; + @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS); + next unless $conninfo{dsn}; + + my $dep_group = $env2optdep{$type}; + if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) { + diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group); next; } - $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"}; - $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"}; - $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"}; - $dsns{$_}{connect_info_opts} = { on_connect_call => 'use_softcommit' } - if /\AFIREBIRD(?:_INTERBASE)?\z/; + $dsns{$type} = \%conninfo; + $dsns{$type}{connect_info_opts} = { on_connect_call => 'use_softcommit' } + if $type =~ /\AFIREBIRD(?:_INTERBASE)?\z/; }; -plan skip_all => 'You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN, _USER and _PASS environment variables' - unless %dsns; - my $schema; my $tester = dbixcsl_common_tests->new( diff --git a/t/10_11msaccess_common.t b/t/10_11msaccess_common.t index 6736d9d..e0c85bc 100644 --- a/t/10_11msaccess_common.t +++ b/t/10_11msaccess_common.t @@ -6,24 +6,30 @@ use DBIx::Class::Schema::Loader::DBI::ODBC::ACCESS (); use lib qw(t/lib); use dbixcsl_common_tests; -my %dsns; -for (qw(MSACCESS_ODBC MSACCESS_ADO)) { - next unless $ENV{"DBICTEST_${_}_DSN"}; +my %env2optdep = map { $_ => lc "test_rdbms_$_" } qw(MSACCESS_ODBC MSACCESS_ADO); + +plan skip_all => 'requirements not satisfied: ' . (join ' OR ', map + { "[ @{[ DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for( $_ ) ]} ]" } + values %env2optdep +) unless scalar grep + { DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for( $_ ) } + values %env2optdep +; - my $dep_group = lc "rdbms_$_"; - if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) { - diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group) - . " to test with $_"; +my %dsns; +for my $type (keys %env2optdep) { + my %conninfo; + @conninfo{qw(dsn user password)} = map { $ENV{"DBICTEST_${type}_$_"} } qw(DSN USER PASS); + next unless $conninfo{dsn}; + + my $dep_group = $env2optdep{$type}; + if (!DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for($dep_group)) { + diag "Testing with DBICTEST_${type}_DSN needs " . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for($dep_group); next; } - $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"}; - $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"}; - $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"}; -}; - -plan skip_all => 'You need to set the DBICTEST_MSACCESS_ODBC_DSN, _USER and _PASS and/or the DBICTEST_MSACCESS_ADO_DSN, _USER and _PASS environment variables' - unless %dsns; + $dsns{$type} = \%conninfo; +} my %ado_extra_types = ( 'tinyint' => { data_type => 'tinyint', original => { data_type => 'byte' } },