Bug 11592: MARCView and ISBD followup
[koha.git] / t / 00-load.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (c) 2016   Mark Tompsett -- is_testable()
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Test::More;
23 use File::Spec;
24 use File::Find;
25 use English qw( -no_match_vars );
26 use t::lib::Mocks;
27
28 =head1 DESCRIPTION
29
30 00-load.t: This script is called by the pre-commit git hook to test modules compile
31
32 =cut
33
34 my $context_module = t::lib::Mocks::mock_dbh;
35
36 # Loop through the C4:: modules
37 my $lib = File::Spec->rel2abs('C4');
38 find({
39     bydepth => 1,
40     no_chdir => 1,
41     wanted => sub {
42         my $m = $_;
43         return unless $m =~ s/[.]pm$//;
44
45         $m =~ s{^.*/C4/}{C4/};
46         $m =~ s{/}{::}g;
47         return if $m =~ /Auth_with_ldap/; # Dont test this, it will fail on use
48         return if $m =~ /SIPServer/; # SIP Server module has old package usage
49         use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
50     },
51 }, $lib);
52
53 # Loop through the Koha:: modules
54 $lib = File::Spec->rel2abs('Koha');
55 find(
56     {
57         bydepth  => 1,
58         no_chdir => 1,
59         wanted   => sub {
60             my $m = $_;
61             return unless $m =~ s/[.]pm$//;
62             $m =~ s{^.*/Koha/}{Koha/};
63             $m =~ s{/}{::}g;
64             if ( is_testable($m) ) {
65                 use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
66             }
67         },
68     },
69     $lib
70 );
71
72 # Optional modules are causing checks to fail
73 # This checks for the particular modules to determine
74 # if the testing is possible or not.
75 #
76 # Returns 1 if possible, 0 if not.
77 sub is_testable {
78     my ($module_name) = @_;
79     my @needed_module_names;
80     my $return_value = 1;
81     if ( $module_name =~ /Koha::NorwegianPatronDB/xsm ) {
82         @needed_module_names =
83           ( 'SOAP::Lite', 'Crypt::GCrypt', 'Digest::SHA', 'Convert::BaseN' );
84     }
85     elsif ( $module_name =~ /Koha::ElasticSearch::Indexer/xsm ) {
86         @needed_module_names =
87           ( 'Catmandu::Importer::MARC', 'Catmandu::Store::ElasticSearch' );
88     }
89     elsif ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Search/xsm ) {
90         @needed_module_names = ( 'Catmandu::Store::ElasticSearch' );
91     }
92     foreach my $current_name (@needed_module_names) {
93         my $relative_pathname = $current_name;
94         $relative_pathname =~ s/::/\//gxsm;
95         $relative_pathname .= '.pm';
96         my $check_result = eval { require "$relative_pathname"; 1; };
97         if ($EVAL_ERROR) {
98             diag(
99 "Skipping testing of $module_name, because $current_name is not installed."
100             );
101             $return_value = 0;
102         }
103     }
104     return $return_value;
105 }
106
107 done_testing();
108
109 1;