From: Dagfinn Ilmari Mannsåker Date: Tue, 23 Sep 2014 16:03:59 +0000 (+0100) Subject: Use Optional::Dependencies for CDBICompat and its tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c8dc7d333;p=dbsrgits%2FDBIx-Class.git Use Optional::Dependencies for CDBICompat and its tests This allows the test to check for them before loading DBICTest and DBIC, thus speeding up the test skips a lot (down from 14s to 1s for 'prove -l t/cdbi' on my Linux box, and down from 1026s to 871s for the whole test suite on a Windows VM). --- diff --git a/Changes b/Changes index d75824c..213fd73 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,9 @@ Revision history for DBIx::Class * Fixes - Fix $rs->create() with no values on Oracle + * Misc + - Speed up skipping CDBICompat tests when dependencies are missing + 0.082800 2014-09-25 14:45 (UTC) * Known Issues - Passing large amounts of objects with stringification overload diff --git a/lib/DBIx/Class/CDBICompat.pm b/lib/DBIx/Class/CDBICompat.pm index f2bb881..b87c997 100644 --- a/lib/DBIx/Class/CDBICompat.pm +++ b/lib/DBIx/Class/CDBICompat.pm @@ -4,20 +4,9 @@ use strict; use warnings; use base qw/DBIx::Class::Core DBIx::Class::DB/; -# Modules CDBICompat needs that DBIx::Class does not. -my @Extra_Modules = qw( - Class::Trigger - DBIx::ContextualFetch - Clone -); - -my @didnt_load; -for my $module (@Extra_Modules) { - push @didnt_load, $module unless eval qq{require $module}; +unless (DBIx::Class::Optional::Dependencies->req_ok_for('cdbicompat')) { + __PACKAGE__->throw_exception(Class::Optional::Dependencies->req_missing_for('cdbicompat') . ' are missing and are required for CDBICompat'); } -__PACKAGE__->throw_exception("@{[ join ', ', @didnt_load ]} are missing and are required for CDBICompat") - if @didnt_load; - __PACKAGE__->load_own_components(qw/ Constraints diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index 7b73889..48f8164 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -255,13 +255,34 @@ my $reqs = { test_cdbicompat => { req => { - 'Class::DBI::Plugin::DeepAbstractSearch' => '0', %$datetime_basic, 'Time::Piece::MySQL' => '0', 'Date::Simple' => '3.03', }, }, + test_cdbicompat_deepabstractsearch => { + req => { + 'Class::DBI::Plugin::DeepAbstractSearch' => '0', + }, + }, + + cdbicompat => { + req => { + 'Class::Trigger' => '0', + 'DBIx::ContextualFetch' => '0', + 'Clone' => '0', + }, + }, + + cdbicompat => { + req => { + 'Class::Trigger' => '0', + 'DBIx::ContextualFetch' => '0', + 'Clone' => '0', + }, + }, + # this is just for completeness as SQLite # is a core dep of DBIC for testing rdbms_sqlite => { diff --git a/t/cdbi/71_column_object.t b/t/cdbi/71_column_object.t index cc998c3..045b07a 100644 --- a/t/cdbi/71_column_object.t +++ b/t/cdbi/71_column_object.t @@ -6,6 +6,11 @@ use warnings; use Test::More; +BEGIN { + eval { require Class::DBI::Column } + or plan skip_all => 'Class::DBI::Column required for this test'; +} + use lib 't/cdbi/testlib'; use ColumnObject; diff --git a/t/cdbi/testlib/DBIC/Test/SQLite.pm b/t/cdbi/testlib/DBIC/Test/SQLite.pm index 905ed88..e17c408 100644 --- a/t/cdbi/testlib/DBIC/Test/SQLite.pm +++ b/t/cdbi/testlib/DBIC/Test/SQLite.pm @@ -41,14 +41,16 @@ use Test::More; # change too much BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 } -use lib 't/lib'; -use DBICTest; - BEGIN { - eval { require DBIx::Class::CDBICompat } - or plan skip_all => 'Class::DBI required for this test'; + require DBIx::Class::Optional::Dependencies; + DBIx::Class::Optional::Dependencies->req_ok_for($_) + or plan skip_all => DBIx::Class::Optional::Dependencies->req_missing_for($_) . ' required for this test' + for qw(cdbicompat test_cdbicompat); } +use lib 't/lib'; +use DBICTest; + use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/CDBICompat Core DB/);