From: Dagfinn Ilmari Mannsåker Date: Tue, 23 Sep 2014 18:33:37 +0000 (+0100) Subject: Only load DBICTest::Schema when needed in tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c2bc4e58c2146670960fc1a0a2ae802cb650506;p=dbsrgits%2FDBIx-Class-Historic.git Only load DBICTest::Schema when needed in tests Make sure to not vivify $DBIx::Class::VERSION, since before perl 5.16, this causes ->ensure_class_loaded to think the class is loaded. --- diff --git a/Changes b/Changes index 213fd73..cb3f5be 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ Revision history for DBIx::Class * Misc - Speed up skipping CDBICompat tests when dependencies are missing + - Avoid loading DBICTest::Schema unnecessarily in tests that + are being skipped 0.082800 2014-09-25 14:45 (UTC) * Known Issues diff --git a/t/102load_classes.t b/t/102load_classes.t index 8936014..c3039e5 100644 --- a/t/102load_classes.t +++ b/t/102load_classes.t @@ -4,6 +4,7 @@ use Test::More; use lib 't/lib'; use DBICTest; +use DBICTest::Schema; my $warnings; eval { diff --git a/t/103many_to_many_warning.t b/t/103many_to_many_warning.t index 2c42091..2dcc271 100644 --- a/t/103many_to_many_warning.t +++ b/t/103many_to_many_warning.t @@ -4,6 +4,7 @@ use Test::More; use lib qw(t/lib); use DBICTest; +use DBICTest::Schema; my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/; diff --git a/t/50fork.t b/t/50fork.t index af61dca..71c4808 100644 --- a/t/50fork.t +++ b/t/50fork.t @@ -24,7 +24,7 @@ if($num_children !~ /^[0-9]+$/ || $num_children < 10) { $num_children = 10; } -my $schema = DBICTest::Schema->connect($dsn, $user, $pass, { AutoCommit => 1 }); +my $schema = DBICTest->connect_schema($dsn, $user, $pass, { AutoCommit => 1 }); my $parent_rs; diff --git a/t/60core.t b/t/60core.t index 7930fce..d848a91 100644 --- a/t/60core.t +++ b/t/60core.t @@ -584,7 +584,7 @@ lives_ok (sub { my $newlink = $newbook->link}, "stringify to false value doesn't # make sure we got rid of the compat shims SKIP: { my $remove_version = 0.083; - skip "Remove in $remove_version", 3 if $DBIx::Class::VERSION < $remove_version; + skip "Remove in $remove_version", 3 if DBIx::Class->VERSION < $remove_version; for (qw/compare_relationship_keys pk_depends_on resolve_condition/) { ok (! DBIx::Class::ResultSource->can ($_), "$_ no longer provided by DBIx::Class::ResultSource, removed before $remove_version"); @@ -627,7 +627,7 @@ SKIP: { #------------------------------ # SKIP: { - skip "Something needs to be done before 0.09", 2 if $DBIx::Class::VERSION < 0.09; + skip "Something needs to be done before 0.09", 2 if DBIx::Class->VERSION < 0.09; my $row = $schema->resultset ('Artist')->next; diff --git a/t/63register_column.t b/t/63register_column.t index 21de95d..5579072 100644 --- a/t/63register_column.t +++ b/t/63register_column.t @@ -5,6 +5,7 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; +use DBICTest::Schema; lives_ok { DBICTest::Schema->load_classes('PunctuatedColumnName') diff --git a/t/63register_source.t b/t/63register_source.t index 6951962..017ca64 100644 --- a/t/63register_source.t +++ b/t/63register_source.t @@ -4,7 +4,6 @@ use warnings; use Test::Exception tests => 1; use lib qw(t/lib); use DBICTest; -use DBICTest::Schema; use DBIx::Class::ResultSource::Table; my $schema = DBICTest->init_schema(); diff --git a/t/71mysql.t b/t/71mysql.t index ef2c7de..2e54352 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -20,7 +20,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' unless ($dsn && $user); -my $schema = DBICTest::Schema->connect($dsn, $user, $pass, { quote_names => 1 }); +my $schema = DBICTest->connect_schema($dsn, $user, $pass, { quote_names => 1 }); my $dbh = $schema->storage->dbh; @@ -52,7 +52,7 @@ $dbh->do("CREATE TABLE books (id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, so # make sure sqlt_type overrides work (::Storage::DBI::mysql does this) { - my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); ok (!$schema->storage->_dbh, 'definitely not connected'); is ($schema->storage->sqlt_type, 'MySQL', 'sqlt_type correct pre-connection'); @@ -209,7 +209,7 @@ lives_ok { $cd->set_producers ([ $producer ]) } 'set_relationship doesnt die'; # with it (ribasushi, 2009/07/03) NULLINSEARCH: { - my $ansi_schema = DBICTest::Schema->connect ($dsn, $user, $pass, { on_connect_call => 'set_strict_mode' }); + my $ansi_schema = DBICTest->connect_schema ($dsn, $user, $pass, { on_connect_call => 'set_strict_mode' }); $ansi_schema->resultset('Artist')->create ({ name => 'last created artist' }); @@ -233,7 +233,7 @@ NULLINSEARCH: { # check for proper grouped counts { - my $ansi_schema = DBICTest::Schema->connect ($dsn, $user, $pass, { + my $ansi_schema = DBICTest->connect_schema ($dsn, $user, $pass, { on_connect_call => 'set_strict_mode', quote_char => '`', }); @@ -363,7 +363,7 @@ ZEROINSEARCH: { # make sure find hooks determine driver { - my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); $schema->resultset("Artist")->find(4); isa_ok($schema->storage->sql_maker, 'DBIx::Class::SQLMaker::MySQL'); } @@ -371,13 +371,13 @@ ZEROINSEARCH: { # make sure the mysql_auto_reconnect buggery is avoided { local $ENV{MOD_PERL} = 'boogiewoogie'; - my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); ok (! $schema->storage->_get_dbh->{mysql_auto_reconnect}, 'mysql_auto_reconnect unset regardless of ENV' ); # Make sure hardcore forking action still works even if mysql_auto_reconnect # is true (test inspired by ether) - my $schema_autorecon = DBICTest::Schema->connect($dsn, $user, $pass, { mysql_auto_reconnect => 1 }); + my $schema_autorecon = DBICTest->connect_schema($dsn, $user, $pass, { mysql_auto_reconnect => 1 }); my $orig_dbh = $schema_autorecon->storage->_get_dbh; weaken $orig_dbh; diff --git a/t/72pg.t b/t/72pg.t index 1e7ed0a..623a5a1 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -28,11 +28,12 @@ EOM ### load any test classes that are defined further down in the file via BEGIN blocks our @test_classes; #< array that will be pushed into by test classes defined in this file +require DBICTest::Schema; DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_classes; ### pre-connect tests (keep each test separate as to make sure rebless() runs) { - my $s = DBICTest::Schema->connect($dsn, $user, $pass); + my $s = DBICTest->connect_schema($dsn, $user, $pass); ok (!$s->storage->_dbh, 'definitely not connected'); @@ -54,7 +55,7 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class } { - my $s = DBICTest::Schema->connect($dsn, $user, $pass); + my $s = DBICTest->connect_schema($dsn, $user, $pass); # make sure sqlt_type overrides work (::Storage::DBI::Pg does this) ok (!$s->storage->_dbh, 'definitely not connected'); is ($s->storage->sqlt_type, 'PostgreSQL', 'sqlt_type correct pre-connection'); @@ -63,7 +64,7 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class # test LIMIT support { - my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); drop_test_schema($schema); create_test_schema($schema); for (1..6) { @@ -95,14 +96,14 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class # check if we indeed do support stuff my $test_server_supports_insert_returning = do { - my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info; + my $si = DBICTest->connect_schema($dsn, $user, $pass)->storage->_server_info; die "Unparseable Pg server version: $si->{dbms_version}\n" unless $si->{normalized_dbms_version}; $si->{normalized_dbms_version} < 8.002 ? 0 : 1; }; is ( - DBICTest::Schema->connect($dsn, $user, $pass)->storage->_use_insert_returning, + DBICTest->connect_schema($dsn, $user, $pass)->storage->_use_insert_returning, $test_server_supports_insert_returning, 'insert returning capability guessed correctly' ); @@ -123,7 +124,7 @@ for my $use_insert_returning ($test_server_supports_insert_returning ### test capability override { - my $s = DBICTest::Schema->connect($dsn, $user, $pass); + my $s = DBICTest->connect_schema($dsn, $user, $pass); ok (!$s->storage->_dbh, 'definitely not connected'); @@ -136,7 +137,7 @@ for my $use_insert_returning ($test_server_supports_insert_returning ### connect, create postgres-specific test schema - $schema = DBICTest::Schema->connect($dsn, $user, $pass); + $schema = DBICTest->connect_schema($dsn, $user, $pass); $schema->storage->ensure_connected; drop_test_schema($schema); @@ -366,7 +367,7 @@ lives_ok { $cds->update({ year => '2010' }) } 'Update on prefetched rs'; }, ) { # create a new schema - my $schema2 = DBICTest::Schema->connect($dsn, $user, $pass); + my $schema2 = DBICTest->connect_schema($dsn, $user, $pass); $schema2->source("Artist")->name("dbic_t_schema.artist"); $schema->txn_do( sub { diff --git a/t/72pg_bytea.t b/t/72pg_bytea.t index ac5b9c4..186ac89 100644 --- a/t/72pg_bytea.t +++ b/t/72pg_bytea.t @@ -15,7 +15,7 @@ my ($dsn, $dbuser, $dbpass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/} plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' unless ($dsn && $dbuser); -my $schema = DBICTest::Schema->connect($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); +my $schema = DBICTest->connect_schema($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); if ($schema->storage->_server_info->{normalized_dbms_version} >= 9.0) { if (not try { DBD::Pg->VERSION('2.17.2') }) { diff --git a/t/73oracle.t b/t/73oracle.t index 87be799..f6da1a1 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -62,6 +62,7 @@ $ENV{NLS_LANG} = "AMERICAN"; 1; } +require DBICTest::Schema; DBICTest::Schema->load_classes('ArtistFQN'); # This is in Core now, but it's here just to test that it doesn't break diff --git a/t/73oracle_blob.t b/t/73oracle_blob.t index 2a78d36..e3b89b8 100644 --- a/t/73oracle_blob.t +++ b/t/73oracle_blob.t @@ -23,7 +23,7 @@ $ENV{NLS_COMP} = "BINARY"; $ENV{NLS_LANG} = "AMERICAN"; my $v = do { - my $si = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info; + my $si = DBICTest->connect_schema($dsn, $user, $pass)->storage->_server_info; $si->{normalized_dbms_version} or die "Unparseable Oracle server version: $si->{dbms_version}\n"; }; @@ -43,7 +43,7 @@ my $dbh; my $schema; for my $opt (@tryopt) { - my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opt); + my $schema = DBICTest->connect_schema($dsn, $user, $pass, $opt); $dbh = $schema->storage->dbh; my $q = $schema->storage->sql_maker->quote_char || ''; diff --git a/t/73oracle_hq.t b/t/73oracle_hq.t index 6d27a05..26b9bd7 100644 --- a/t/73oracle_hq.t +++ b/t/73oracle_hq.t @@ -24,8 +24,8 @@ plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test.' plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_oracle') unless DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_oracle'); -use DBICTest::Schema::Artist; -BEGIN { +{ + require DBICTest::Schema::Artist; DBICTest::Schema::Artist->add_column('parentid'); DBICTest::Schema::Artist->has_many( @@ -40,9 +40,8 @@ BEGIN { } use DBICTest; -use DBICTest::Schema; -my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +my $schema = DBICTest->connect_schema($dsn, $user, $pass); note "Oracle Version: " . $schema->storage->_server_info->{dbms_version}; diff --git a/t/745db2.t b/t/745db2.t index 9123330..88bfd3c 100644 --- a/t/745db2.t +++ b/t/745db2.t @@ -18,7 +18,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_DB2_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test' unless ($dsn && $user); -my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +my $schema = DBICTest->connect_schema($dsn, $user, $pass); my $name_sep = $schema->storage->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR'); diff --git a/t/746db2_400.t b/t/746db2_400.t index 3a5d902..cb5213b 100644 --- a/t/746db2_400.t +++ b/t/746db2_400.t @@ -21,6 +21,7 @@ plan skip_all => 'Set $ENV{DBICTEST_DB2_400_DSN}, _USER and _PASS to run this te plan tests => 6; +require DBICTest::Schema; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); my $dbh = $schema->storage->dbh; diff --git a/t/746mssql.t b/t/746mssql.t index e4a9de0..598b7a2 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -18,7 +18,7 @@ plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this unless ($dsn && $user); { - my $srv_ver = DBICTest::Schema->connect($dsn, $user, $pass)->storage->_server_info->{dbms_version}; + my $srv_ver = DBICTest->connect_schema($dsn, $user, $pass)->storage->_server_info->{dbms_version}; ok ($srv_ver, 'Got a test server version on fresh schema: ' . ($srv_ver||'???') ); } @@ -64,7 +64,7 @@ my %opts = ( for my $opts_name (keys %opts) { SKIP: { my $opts = $opts{$opts_name}{opts}; - $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); + $schema = DBICTest->connect_schema($dsn, $user, $pass, $opts); try { $schema->storage->ensure_connected @@ -168,7 +168,7 @@ SQL lives_ok ( sub { # start a new connection, make sure rebless works - my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); + my $schema = DBICTest->connect_schema($dsn, $user, $pass, $opts); $schema->populate ('Owners', [ [qw/id name /], [qw/1 wiggle/], @@ -193,7 +193,7 @@ SQL lives_ok (sub { # start a new connection, make sure rebless works # test an insert with a supplied identity, followed by one without - my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); + my $schema = DBICTest->connect_schema($dsn, $user, $pass, $opts); for (2, 1) { my $id = $_ * 20 ; $schema->resultset ('Owners')->create ({ id => $id, name => "troglodoogle $id" }); @@ -205,7 +205,7 @@ SQL lives_ok ( sub { # start a new connection, make sure rebless works - my $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); + my $schema = DBICTest->connect_schema($dsn, $user, $pass, $opts); $schema->populate ('BooksInLibrary', [ [qw/source owner title /], [qw/Library 1 secrets0/], @@ -235,7 +235,7 @@ SQL ) { for my $quoted (0, 1) { - $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { limit_dialect => $dialect, %$opts, $quoted @@ -420,7 +420,7 @@ SQL }); # start disconnected to make sure insert works on an un-reblessed storage - $schema = DBICTest::Schema->connect($dsn, $user, $pass, $opts); + $schema = DBICTest->connect_schema($dsn, $user, $pass, $opts); my $row; lives_ok { diff --git a/t/746sybase.t b/t/746sybase.t index af1f7a3..a8356ba 100644 --- a/t/746sybase.t +++ b/t/746sybase.t @@ -29,6 +29,7 @@ eval "require DBIx::Class::Storage::$_;" for @storage_types; my $schema; my $storage_idx = -1; +require DBICTest::Schema; sub get_schema { DBICTest::Schema->connect($dsn, $user, $pass, { on_connect_call => [ diff --git a/t/747mssql_ado.t b/t/747mssql_ado.t index 3fd7af6..19362dd 100644 --- a/t/747mssql_ado.t +++ b/t/747mssql_ado.t @@ -19,6 +19,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PAS plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ADO_DSN}, _USER and _PASS to run this test' unless ($dsn && $user); +require DBICTest::Schema; DBICTest::Schema->load_classes(qw/VaryingMAX ArtistGUID/); my %binstr = ( 'small' => join('', map { chr($_) } ( 1 .. 127 )) ); diff --git a/t/748informix.t b/t/748informix.t index 42bdac8..e289d28 100644 --- a/t/748informix.t +++ b/t/748informix.t @@ -17,7 +17,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS plan skip_all => 'Set $ENV{DBICTEST_INFORMIX_DSN}, _USER and _PASS to run this test' unless $dsn; -my $schema = DBICTest::Schema->connect($dsn, $user, $pass, { +my $schema = DBICTest->connect_schema($dsn, $user, $pass, { auto_savepoint => 1 }); diff --git a/t/749sqlanywhere.t b/t/749sqlanywhere.t index 396e103..0b66bb5 100644 --- a/t/749sqlanywhere.t +++ b/t/749sqlanywhere.t @@ -23,8 +23,6 @@ plan skip_all => 'Test needs ' . or (not $dsn || $dsn2); -DBICTest::Schema->load_classes('ArtistGUID'); - # tests stolen from 748informix.t plan skip_all => <<'EOF' unless $dsn || $dsn2; @@ -32,6 +30,9 @@ Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN}, _USER and _PASS to run these tests EOF +require DBICTest::Schema; +DBICTest::Schema->load_classes('ArtistGUID'); + my @info = ( [ $dsn, $user, $pass ], [ $dsn2, $user2, $pass2 ], diff --git a/t/74mssql.t b/t/74mssql.t index 263fecb..c0c3e42 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -18,13 +18,13 @@ plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missin 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}; + my $srv_ver = DBICTest->connect_schema($dsn, $user, $pass)->storage->_server_info->{dbms_version}; ok ($srv_ver, 'Got a test server version on fresh schema: ' . ($srv_ver||'???') ); } my $schema; -my $testdb_supports_placeholders = DBICTest::Schema->connect($dsn, $user, $pass) +my $testdb_supports_placeholders = DBICTest->connect_schema($dsn, $user, $pass) ->storage ->_supports_typeless_placeholders; my @test_storages = ( @@ -33,7 +33,7 @@ my @test_storages = ( ); for my $storage_type (@test_storages) { - $schema = DBICTest::Schema->connect($dsn, $user, $pass); + $schema = DBICTest->connect_schema($dsn, $user, $pass); if ($storage_type =~ /NoBindVars\z/) { # since we want to use the nobindvar - disable the capability so the @@ -272,8 +272,7 @@ SQL } { - my $schema = DBICTest::Schema->clone; - $schema->connection($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); like $schema->storage->sql_maker->{limit_dialect}, qr/^(?:Top|RowNumberOver)\z/, @@ -284,8 +283,7 @@ SQL # test op-induced autoconnect lives_ok (sub { - my $schema = DBICTest::Schema->clone; - $schema->connection($dsn, $user, $pass); + my $schema = DBICTest->connect_schema($dsn, $user, $pass); my $artist = $schema->resultset ('Artist')->search ({}, { order_by => 'artistid' })->next; is ($artist->id, 1, 'Artist retrieved successfully'); @@ -294,7 +292,7 @@ lives_ok (sub { # test AutoCommit=0 { local $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK} = 1; - my $schema2 = DBICTest::Schema->connect($dsn, $user, $pass, { AutoCommit => 0 }); + my $schema2 = DBICTest->connect_schema($dsn, $user, $pass, { AutoCommit => 0 }); my $rs = $schema2->resultset('Money'); diff --git a/t/750firebird.t b/t/750firebird.t index d092379..c1e625a 100644 --- a/t/750firebird.t +++ b/t/750firebird.t @@ -47,7 +47,7 @@ for my $prefix (keys %$env2optdep) { SKIP: { 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, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { auto_savepoint => 1, quote_names => 1, ($dsn !~ /ODBC/ ? (on_connect_call => 'use_softcommit') : ()), diff --git a/t/751msaccess.t b/t/751msaccess.t index bf4cdac..cadf140 100644 --- a/t/751msaccess.t +++ b/t/751msaccess.t @@ -23,6 +23,7 @@ plan skip_all => 'Test needs ' . or (not $dsn || $dsn2); +require DBICTest::Schema; DBICTest::Schema->load_classes('ArtistGUID'); # Example DSNs (32bit only): diff --git a/t/94versioning.t b/t/94versioning.t index a154d8f..8dde154 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -33,7 +33,7 @@ BEGIN { # this is just to grab a lock { - my $s = DBICTest::Schema->connect($dsn, $user, $pass); + my $s = DBICTest->connect_schema($dsn, $user, $pass); } # in case it came from the env diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index 0b36850..e076e14 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -19,6 +19,7 @@ BEGIN { # Test for SQLT-related leaks { + require DBICTest::Schema; my $s = DBICTest::Schema->clone; my @schemas = ( diff --git a/t/cdbi/sweet/08pager.t b/t/cdbi/sweet/08pager.t index f645276..d745883 100644 --- a/t/cdbi/sweet/08pager.t +++ b/t/cdbi/sweet/08pager.t @@ -5,6 +5,7 @@ use Test::More; use lib 't/cdbi/testlib'; use DBIC::Test::SQLite; +use DBICTest::Schema; DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/); diff --git a/t/cdbi/testlib/MyBase.pm b/t/cdbi/testlib/MyBase.pm index bf55635..fa66258 100644 --- a/t/cdbi/testlib/MyBase.pm +++ b/t/cdbi/testlib/MyBase.pm @@ -34,7 +34,7 @@ if ($err) { 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); + my $x = DBICTest->connect_schema(@connect); } $dbh = DBI->connect(@connect) or die DBI->errstr; diff --git a/t/inflate/datetime_firebird.t b/t/inflate/datetime_firebird.t index c958d6b..670fcdf 100644 --- a/t/inflate/datetime_firebird.t +++ b/t/inflate/datetime_firebird.t @@ -37,7 +37,7 @@ for my $prefix (keys %$env2optdep) { SKIP: { 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, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { quote_char => '"', name_sep => '.', on_connect_call => [ 'datetime_setup' ], diff --git a/t/inflate/datetime_informix.t b/t/inflate/datetime_informix.t index 8bbd524..a44f81a 100644 --- a/t/inflate/datetime_informix.t +++ b/t/inflate/datetime_informix.t @@ -25,7 +25,7 @@ EOF my $schema; { - $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { on_connect_call => [ 'datetime_setup' ], }); diff --git a/t/inflate/datetime_msaccess.t b/t/inflate/datetime_msaccess.t index f012199..b2f2a8c 100644 --- a/t/inflate/datetime_msaccess.t +++ b/t/inflate/datetime_msaccess.t @@ -39,7 +39,7 @@ for my $connect_info (@connect_info) { next unless $dsn; - my $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + my $schema = DBICTest->connect_schema($dsn, $user, $pass, { on_connect_call => 'datetime_setup', quote_names => 1, }); diff --git a/t/inflate/datetime_mssql.t b/t/inflate/datetime_mssql.t index edbac14..862aa7f 100644 --- a/t/inflate/datetime_mssql.t +++ b/t/inflate/datetime_mssql.t @@ -37,6 +37,7 @@ if (not ($dsn || $dsn2 || $dsn3)) { ." 'track'."; } +require DBICTest::Schema; DBICTest::Schema->load_classes('EventSmallDT'); my @connect_info = ( @@ -53,7 +54,7 @@ for my $connect_info (@connect_info) { next unless $dsn; - $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { on_connect_call => 'datetime_setup' }); diff --git a/t/inflate/datetime_mysql.t b/t/inflate/datetime_mysql.t index 44699ab..e1821db 100644 --- a/t/inflate/datetime_mysql.t +++ b/t/inflate/datetime_mysql.t @@ -7,13 +7,13 @@ use Test::Warn; use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); use DBICTest; -use DBICTest::Schema; use DBIx::Class::_Util 'sigwarn_silencer'; plan skip_all => 'Inflation tests need ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_mysql') unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_mysql'); { + require DBICTest::Schema; DBICTest::Schema->load_classes('EventTZ'); local $SIG{__WARN__} = sigwarn_silencer( qr/extra \=\> .+? has been deprecated/ ); DBICTest::Schema->load_classes('EventTZDeprecated'); diff --git a/t/inflate/datetime_oracle.t b/t/inflate/datetime_oracle.t index 9182f23..1bf0498 100644 --- a/t/inflate/datetime_oracle.t +++ b/t/inflate/datetime_oracle.t @@ -24,7 +24,7 @@ $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1'; $ENV{NLS_SORT} = "BINARY"; $ENV{NLS_COMP} = "BINARY"; -my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +my $schema = DBICTest->connect_schema($dsn, $user, $pass); # older oracles do not support a TIMESTAMP datatype my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9 diff --git a/t/inflate/datetime_pg.t b/t/inflate/datetime_pg.t index c02e9f8..d213500 100644 --- a/t/inflate/datetime_pg.t +++ b/t/inflate/datetime_pg.t @@ -10,6 +10,7 @@ use DBICTest; plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt_pg') unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt_pg'); +require DBICTest::Schema; DBICTest::Schema->load_classes('EventTZPg'); my $schema = DBICTest->init_schema(); diff --git a/t/inflate/datetime_sqlanywhere.t b/t/inflate/datetime_sqlanywhere.t index 676665f..c17573b 100644 --- a/t/inflate/datetime_sqlanywhere.t +++ b/t/inflate/datetime_sqlanywhere.t @@ -43,9 +43,7 @@ foreach my $info (@info) { next unless $dsn; - $schema = DBICTest::Schema->clone; - - $schema->connection($dsn, $user, $pass, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { on_connect_call => 'datetime_setup', }); diff --git a/t/inflate/datetime_sybase.t b/t/inflate/datetime_sybase.t index 597f6a3..ad84e80 100644 --- a/t/inflate/datetime_sybase.t +++ b/t/inflate/datetime_sybase.t @@ -24,6 +24,7 @@ if (not ($dsn && $user)) { "'event_small_dt'"; } +require DBICTest::Schema; DBICTest::Schema->load_classes('EventSmallDT'); my @storage_types = ( diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index aa20b0c..49df060 100644 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -5,7 +5,7 @@ use strict; use warnings; use DBICTest::Util 'local_umask'; -use DBICTest::Schema; +use DBICTest::RunMode; use DBICTest::Util::LeakTracer qw/populate_weakregistry assert_empty_weakregistry/; use Carp; use Path::Class::File (); @@ -314,6 +314,8 @@ sub init_schema { my $schema; + require DBICTest::Schema; + if ($args{compose_connection}) { $schema = DBICTest::Schema->compose_connection( 'DBICTest', $self->_database(%args) @@ -343,7 +345,11 @@ sub init_schema { } END { + # Make sure we run after any cleanup in other END blocks + require B; + push @{ B::end_av()->object_2svref }, sub { assert_empty_weakregistry($weak_registry, 'quiet'); + }; } =head2 deploy_schema @@ -570,4 +576,10 @@ sub populate_schema { ]); } +sub connect_schema { + my $self = shift; + require DBICTest::Schema; + return DBICTest::Schema->connect(@_); +} + 1; diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index cdc7a02..c68d7fd 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -257,7 +257,11 @@ sub clone { } END { - assert_empty_weakregistry($weak_registry, 'quiet'); + # Make sure we run after any cleanup in other END blocks + require B; + push @{ B::end_av()->object_2svref }, sub { + assert_empty_weakregistry($weak_registry, 'quiet'); + }; } 1; diff --git a/t/resultset_class.t b/t/resultset_class.t index 607c1f2..884f590 100644 --- a/t/resultset_class.t +++ b/t/resultset_class.t @@ -7,6 +7,7 @@ unshift(@INC, './t/lib'); use lib 't/lib'; use DBICTest; +use DBICTest::Schema; is(DBICTest::Schema->source('Artist')->resultset_class, 'DBICTest::BaseResultSet', 'default resultset class'); ok(!Class::Inspector->loaded('DBICNSTest::ResultSet::A'), 'custom resultset class not loaded'); diff --git a/t/sqlmaker/limit_dialects/custom.t b/t/sqlmaker/limit_dialects/custom.t index 89c4788..15064c2 100644 --- a/t/sqlmaker/limit_dialects/custom.t +++ b/t/sqlmaker/limit_dialects/custom.t @@ -22,7 +22,7 @@ use DBICTest ':DiffSQL'; ); } } -my $s = DBICTest::Schema->connect (DBICTest->_database); +my $s = DBICTest->connect_schema (DBICTest->_database); $s->storage->sql_maker_class ('DBICTest::SQLMaker::CustomDialect'); my $rs = $s->resultset ('CD'); diff --git a/t/sqlmaker/mysql.t b/t/sqlmaker/mysql.t index 0e2ad29..7307363 100644 --- a/t/sqlmaker/mysql.t +++ b/t/sqlmaker/mysql.t @@ -6,7 +6,7 @@ use Test::More; use lib qw(t/lib); use DBICTest ':DiffSQL'; -my $schema = DBICTest::Schema->connect (DBICTest->_database, { quote_char => '`' }); +my $schema = DBICTest->connect_schema (DBICTest->_database, { quote_char => '`' }); # cheat require DBIx::Class::Storage::DBI::mysql; *DBIx::Class::Storage::DBI::mysql::_get_server_version = sub { 5 }; diff --git a/t/storage/deploy.t b/t/storage/deploy.t index 61610ba..bb1c7cc 100644 --- a/t/storage/deploy.t +++ b/t/storage/deploy.t @@ -21,7 +21,7 @@ local $ENV{DBI_DSN}; # instance, but no conninfo) # there ought to be more code like this in the wild like( - DBICTest::Schema->connect->deployment_statements('SQLite'), + DBICTest->connect_schema->deployment_statements('SQLite'), qr/\bCREATE TABLE artist\b/i # ensure quoting *is* disabled ); diff --git a/t/storage/deprecated_exception_source_bind_attrs.t b/t/storage/deprecated_exception_source_bind_attrs.t index f6dca5a..27dfdfc 100644 --- a/t/storage/deprecated_exception_source_bind_attrs.t +++ b/t/storage/deprecated_exception_source_bind_attrs.t @@ -6,6 +6,7 @@ use Test::Warn; use Test::Exception; use lib qw(t/lib); use DBICTest; +use DBICTest::Schema; { package DBICTest::Legacy::Storage; diff --git a/t/storage/global_destruction.t b/t/storage/global_destruction.t index 4fb49cb..f308765 100644 --- a/t/storage/global_destruction.t +++ b/t/storage/global_destruction.t @@ -29,7 +29,7 @@ for my $type (qw/PG MYSQL SQLite/) { unless DBIx::Class::Optional::Dependencies->req_ok_for('test_rdbms_mysql'); } - my $schema = DBICTest::Schema->connect (@dsn); + my $schema = DBICTest->connect_schema (@dsn); # emulate a singleton-factory, just cache the object *somewhere in a different package* # to induce out-of-order destruction diff --git a/t/storage/quote_names.t b/t/storage/quote_names.t index 6492f25..6d9bc76 100644 --- a/t/storage/quote_names.t +++ b/t/storage/quote_names.t @@ -105,7 +105,7 @@ for my $db (sort { my $schema; try { - $schema = DBICTest::Schema->connect($dsn, $user, $pass, { + $schema = DBICTest->connect_schema($dsn, $user, $pass, { quote_names => 1 }); $schema->storage->ensure_connected; diff --git a/t/storage/savepoints.t b/t/storage/savepoints.t index 0c56afc..613eb14 100644 --- a/t/storage/savepoints.t +++ b/t/storage/savepoints.t @@ -42,7 +42,7 @@ for ('', keys %$env2optdep) { SKIP: { 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 }); + $schema = DBICTest->connect_schema ($dsn,$user,$pass,{ auto_savepoint => 1 }); my $create_sql; $schema->storage->ensure_connected; @@ -234,6 +234,8 @@ for ('', keys %$env2optdep) { SKIP: { done_testing; +# XXX: The leak tests fail if this is END compiled before (and thus +# executed after) the one in DBICTest::BaseSchema END { eval { $schema->storage->dbh->do ("DROP TABLE artist") } if defined $schema; undef $schema; diff --git a/t/zzzzzzz_sqlite_deadlock.t b/t/zzzzzzz_sqlite_deadlock.t index b0e8f3b..4aa2030 100644 --- a/t/zzzzzzz_sqlite_deadlock.t +++ b/t/zzzzzzz_sqlite_deadlock.t @@ -12,6 +12,7 @@ BEGIN { use Test::Exception; use DBICTest; +use DBICTest::Schema; use File::Temp (); plan tests => 2;