* 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
use lib 't/lib';
use DBICTest;
+use DBICTest::Schema;
my $warnings;
eval {
use lib qw(t/lib);
use DBICTest;
+use DBICTest::Schema;
my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/;
$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;
# 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");
#------------------------------
#
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;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
+use DBICTest::Schema;
lives_ok {
DBICTest::Schema->load_classes('PunctuatedColumnName')
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();
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;
# 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');
# 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' });
# 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 => '`',
});
# 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');
}
# 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;
### 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');
}
{
- 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');
# 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) {
# 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'
);
### 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');
### 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);
},
) {
# 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 {
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') }) {
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
$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";
};
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 || '';
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(
}
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};
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');
plan tests => 6;
+require DBICTest::Schema;
my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
my $dbh = $schema->storage->dbh;
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||'???') );
}
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
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/],
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" });
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/],
) {
for my $quoted (0, 1) {
- $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+ $schema = DBICTest->connect_schema($dsn, $user, $pass, {
limit_dialect => $dialect,
%$opts,
$quoted
});
# 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 {
my $schema;
my $storage_idx = -1;
+require DBICTest::Schema;
sub get_schema {
DBICTest::Schema->connect($dsn, $user, $pass, {
on_connect_call => [
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 )) );
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
});
or
(not $dsn || $dsn2);
-DBICTest::Schema->load_classes('ArtistGUID');
-
# tests stolen from 748informix.t
plan skip_all => <<'EOF' unless $dsn || $dsn2;
_USER and _PASS to run these tests
EOF
+require DBICTest::Schema;
+DBICTest::Schema->load_classes('ArtistGUID');
+
my @info = (
[ $dsn, $user, $pass ],
[ $dsn2, $user2, $pass2 ],
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 = (
);
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
}
{
- 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/,
# 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');
# 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');
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') : ()),
or
(not $dsn || $dsn2);
+require DBICTest::Schema;
DBICTest::Schema->load_classes('ArtistGUID');
# Example DSNs (32bit only):
# 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
# Test for SQLT-related leaks
{
+ require DBICTest::Schema;
my $s = DBICTest::Schema->clone;
my @schemas = (
use lib 't/cdbi/testlib';
use DBIC::Test::SQLite;
+use DBICTest::Schema;
DBICTest::Schema::CD->load_components(qw/CDBICompat CDBICompat::Pager/);
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;
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' ],
my $schema;
{
- $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+ $schema = DBICTest->connect_schema($dsn, $user, $pass, {
on_connect_call => [ 'datetime_setup' ],
});
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,
});
." 'track'.";
}
+require DBICTest::Schema;
DBICTest::Schema->load_classes('EventSmallDT');
my @connect_info = (
next unless $dsn;
- $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+ $schema = DBICTest->connect_schema($dsn, $user, $pass, {
on_connect_call => 'datetime_setup'
});
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');
$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
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();
next unless $dsn;
- $schema = DBICTest::Schema->clone;
-
- $schema->connection($dsn, $user, $pass, {
+ $schema = DBICTest->connect_schema($dsn, $user, $pass, {
on_connect_call => 'datetime_setup',
});
"'event_small_dt'";
}
+require DBICTest::Schema;
DBICTest::Schema->load_classes('EventSmallDT');
my @storage_types = (
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 ();
my $schema;
+ require DBICTest::Schema;
+
if ($args{compose_connection}) {
$schema = DBICTest::Schema->compose_connection(
'DBICTest', $self->_database(%args)
}
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
]);
}
+sub connect_schema {
+ my $self = shift;
+ require DBICTest::Schema;
+ return DBICTest::Schema->connect(@_);
+}
+
1;
}
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;
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');
);
}
}
-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');
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 };
# 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
);
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
+use DBICTest::Schema;
{
package DBICTest::Legacy::Storage;
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
my $schema;
try {
- $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
+ $schema = DBICTest->connect_schema($dsn, $user, $pass, {
quote_names => 1
});
$schema->storage->ensure_connected;
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;
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;
use Test::Exception;
use DBICTest;
+use DBICTest::Schema;
use File::Temp ();
plan tests => 2;