Bug 15150: Make t/ tests skip if Test::DBIx::Class absent
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 6 Nov 2015 13:29:21 +0000 (10:29 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 6 Nov 2015 15:25:27 +0000 (12:25 -0300)
Tests in t/ should always pass for building the Debian packages
for Koha. But we've started using Test::DBIx::Class for writing
mocked tests, and that lib is not (yet) packaged fro Debian 7+.

This means build is failing. Devs and jenkins use the lib from CPAN.

This patch makes the tests skip if the lib is absent.

To test:
- Install Test::DBIx::Class
  $ sudo cpanm Test::DBIx::Class
- Run the tests:
  $ prove t/
=> SUCCESS: Tests pass
- Uninstall Test::DBIx::Class
  $ sudo cpan -U Test::DBIx::Class
- Run the tests:
  $ prove t/
=> SUCCESS: Tests still pass (those needing the lib are skipped)
- Sign off :-D

Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com>
Works as advertised. All test pass successful

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/Biblio.t
t/Calendar.t
t/Images.t
t/ItemType.t
t/Koha.t
t/Letters.t
t/Matcher.t
t/Members_AttributeTypes.t
t/SocialData.t

index 8cf9c9d..0e709af 100755 (executable)
 
 use Modern::Perl;
 
-use Test::More tests => 46;
+use Test::More;
 use Test::MockModule;
 use Test::Warn;
 
+use Module::Load::Conditional qw/check_install/;
+
 BEGIN {
-        use_ok('C4::Biblio');
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 46;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
 }
 
+use_ok('C4::Biblio');
+
 use Test::DBIx::Class {
     schema_class => 'Koha::Schema',
     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
index 7fabe3a..37f11f4 100755 (executable)
@@ -1,20 +1,42 @@
-#!/usr/bin/env perl
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
+
+use Test::More;
+use Test::MockModule;
+
 use DateTime;
 use DateTime::Duration;
-use Test::More tests => 35;
-use Test::MockModule;
 use Koha::Cache;
 use Koha::DateUtils;
 
-BEGIN {
-    use_ok('Koha::Calendar');
+use Module::Load::Conditional qw/check_install/;
 
-    # This was the only test C4 had
-    # Remove when no longer used
-    #use_ok('C4::Calendar'); # not used anymore?
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 35;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
 }
+
+use_ok('Koha::Calendar');
+
 use Test::DBIx::Class {
     schema_class => 'Koha::Schema',
     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
@@ -298,3 +320,5 @@ my $day_after_christmas = DateTime->new(
                 '==', 40, 'Test parameter order not relevant (Days)' );
 
 }
+
+1;
index 274766b..0ee5ce6 100644 (file)
@@ -1,11 +1,35 @@
 #!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-#Testing C4 Images
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 8;
+
+use Test::More;
 use Test::MockModule;
 
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 8;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
+
 use_ok('C4::Images');
 
 use Test::DBIx::Class {
@@ -49,3 +73,5 @@ is( $imagenumbers[0], 1, 'imagenumber is 1' );
 is( $imagenumbers[1], 3, 'imagenumber is 3' );
 
 is( $imagenumbers[4], undef, 'imagenumber undef' );
+
+1;
index b10efdd..2f05c74 100755 (executable)
@@ -1,9 +1,35 @@
 #!/usr/bin/perl
 
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
 use Modern::Perl;
-use Test::More tests => 25;
+
+use Test::More;
 use t::lib::Mocks;
 
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 25;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
+
 use_ok('C4::ItemType');
 
 use Test::DBIx::Class {
@@ -90,3 +116,5 @@ is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' );
 
 $itemtype = C4::ItemType->get;
 is( $itemtype, undef, 'C4::ItemType->get should return unless if no parameter is given' );
+
+1;
index e4d46f2..3593368 100755 (executable)
--- a/t/Koha.t
+++ b/t/Koha.t
 use Modern::Perl;
 
 use C4::Context;
-use Test::More tests => 30;
+use Test::More;
 use Test::MockModule;
 
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 30;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
+
 use_ok('C4::Koha');
 
 use Test::DBIx::Class {
index ad70026..a072044 100755 (executable)
 
 use Modern::Perl;
 
-use DBI;
 use Test::MockModule;
-use Test::More tests => 6;
+use Test::More;
+
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 6;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
 
 use Test::DBIx::Class {
     schema_class => 'Koha::Schema',
index 2a4246c..652f061 100755 (executable)
@@ -1,16 +1,37 @@
 #!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-#testing C4 matcher
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
 
-use strict;
-use warnings;
-use Test::More tests => 11;
+use Test::More;
 use Test::MockModule;
 
+use Module::Load::Conditional qw/check_install/;
+
 BEGIN {
-    use_ok('C4::Matcher');
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 11;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
 }
 
+use_ok('C4::Matcher');
+
 use Test::DBIx::Class {
     schema_class => 'Koha::Schema',
     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
@@ -60,3 +81,5 @@ is( $testmatcher->code(), 'match on ISBN', 'testing code accessor' );
 $testmatcher->description('match on ISSN');
 
 is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' );
+
+1;
index 055e767..6bb58ae 100755 (executable)
@@ -1,15 +1,37 @@
 #!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# Tests 'fetch', 'fake db data', and 'checks for existant attributes'
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
+
 use Test::MockModule;
-use Test::More tests => 10;
+use Test::More;
+
+use Module::Load::Conditional qw/check_install/;
 
 BEGIN {
-    use_ok('C4::Members::AttributeTypes');
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 10;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
 }
 
+use_ok('C4::Members::AttributeTypes');
+
 use Test::DBIx::Class {
     schema_class => 'Koha::Schema',
     connect_info => ['dbi:SQLite:dbname=:memory:','',''],
index 3d6cd1a..8b6a93b 100644 (file)
@@ -1,11 +1,35 @@
 #!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-#Testing C4 SocialData
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 6;
+
+use Test::More;
 use Test::MockModule;
 
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 6;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
+
 BEGIN {
     use_ok('C4::SocialData');
 }
@@ -51,3 +75,5 @@ is( $report->{'without'}->[0]->{'original'},
 
 is( $report->{'without'}->[0]->{'isbn'}, '9780596526740',
     'testing get_report' );
+
+1;