Bug 21662: Add Contributors.yaml file
[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
27 =head1 DESCRIPTION
28
29 00-load.t: This script is called by the pre-commit git hook to test modules compile
30
31 =cut
32
33 # Loop through the C4:: modules
34 my $lib = File::Spec->rel2abs('C4');
35 find({
36     bydepth => 1,
37     no_chdir => 1,
38     wanted => sub {
39         my $m = $_;
40         return unless $m =~ s/[.]pm$//;
41
42         $m =~ s{^.*/C4/}{C4/};
43         $m =~ s{/}{::}g;
44         return if $m =~ /Auth_with_ldap/; # Dont test this, it will fail on use
45         return if $m =~ /SIPServer/; # SIP Server module has old package usage
46         use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
47     },
48 }, $lib);
49
50 # Loop through the Koha:: modules
51 $lib = File::Spec->rel2abs('Koha');
52 find(
53     {
54         bydepth  => 1,
55         no_chdir => 1,
56         wanted   => sub {
57             my $m = $_;
58             return unless $m =~ s/[.]pm$//;
59             $m =~ s{^.*/Koha/}{Koha/};
60             $m =~ s{/}{::}g;
61             if ( is_testable($m) ) {
62                 use_ok($m) || BAIL_OUT("***** PROBLEMS LOADING FILE '$m'");
63             }
64         },
65     },
66     $lib
67 );
68
69 # Optional modules are causing checks to fail
70 # This checks for the particular modules to determine
71 # if the testing is possible or not.
72 #
73 # Returns 1 if possible, 0 if not.
74 sub is_testable {
75     my ($module_name) = @_;
76     my @needed_module_names;
77     my $return_value = 1;
78     if ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Indexer/xsm ) {
79         @needed_module_names =
80           ( 'Catmandu::Importer::MARC', 'Catmandu::Store::ElasticSearch' );
81     }
82     elsif ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Search/xsm ) {
83         @needed_module_names = ( 'Catmandu::Store::ElasticSearch' );
84     }
85     elsif ( $module_name =~ /Koha::SearchEngine::Elasticsearch/xsm ) {
86         @needed_module_names = ( 'Search::Elasticsearch' );
87     }
88     elsif ( $module_name =~ /^Koha::ExternalContent/xsm ) {
89         @needed_module_names = ( 'WebService::ILS' );
90     }
91     foreach my $current_name (@needed_module_names) {
92         my $relative_pathname = $current_name;
93         $relative_pathname =~ s/::/\//gxsm;
94         $relative_pathname .= '.pm';
95         my $check_result = eval { require "$relative_pathname"; 1; };
96         if ($EVAL_ERROR) {
97             diag(
98 "Skipping testing of $module_name, because $current_name is not installed."
99             );
100             $return_value = 0;
101         }
102     }
103     return $return_value;
104 }
105
106 done_testing();
107