Bug 11401: (followup) make tests run on absent deps
authorTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 14 Nov 2014 18:28:55 +0000 (15:28 -0300)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 14 Nov 2014 18:32:25 +0000 (15:32 -0300)
The current code breaks if a dependency is missing. The evals are
rearranged so there's no error on missing dependency.

To reproduce:
- Have a dependency for t/NorwegianPatronDB.t removed
- Run
  $ prove t/NorwegianPatronDB.t
=> FAIL: You see an error similar to this (may vary depending on the lib you removed):

t/NorwegianPatronDB.t .. You tried to plan twice at t/NorwegianPatronDB.t line 37.

- Apply the patch
- Run
  $ prove t/NorwegianPatronDB.t
=> SUCCESS: Tests are skipped on missing lib

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
t/NorwegianPatronDB.t

index 4f05d91..1f0808c 100644 (file)
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 73;
+use Test::More;
 use Test::MockModule;
 use t::lib::Mocks;
 use Data::Dumper;
 
 # Check that all the modules we need are installed, or bail out
 BEGIN {
+    my $missing_lib;
     eval {
         require Test::DBIx::Class;
         1;
     } or do {
-        plan skip_all => "Test::DBIx::Class is not available";
+        $missing_lib = "Test::DBIx::Class";
     };
-}
-BEGIN {
+
     eval {
         require SOAP::Lite;
         1;
     } or do {
-        plan skip_all => "SOAP::Lite is not available";
+        $missing_lib = "SOAP::Lite";
     };
-}
-BEGIN {
+
     eval {
         require Crypt::GCrypt;
         1;
     } or do {
-        plan skip_all => "Crypt::GCrypt is not available";
+        $missing_lib = "Crypt::GCrypt";
     };
-}
-BEGIN {
+
     eval {
         require Convert::BaseN;
         1;
     } or do {
-        plan skip_all => "Convert::BaseN is not available";
+        $missing_lib = "Convert::BaseN";
     };
+
+    if ( $missing_lib ) {
+        plan skip_all => $missing_lib . " is not available.";
+    } else {
+        # Everything good
+        plan tests => 73;
+    }
 }
 
 use Test::DBIx::Class {