Bug 23696: take deleted biblios into account when building oai sets
[koha.git] / xt / find-license-problems.t
blob50e607edeae4603eebc94d6ecb57c64c14444a43
1 #!/usr/bin/perl
3 # Find copyright and license problems in Koha source files. At this
4 # time it only looks for references to the old FSF address in GPLv2
5 # license notices, but it might in the future be extended to look for
6 # other things, too.
8 # Copyright 2010 Catalyst IT Ltd
9 # Copyright 2020 Koha Development Team
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 3 of the License, or
16 # (at your option) any later version.
18 # Koha is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use Modern::Perl;
27 use Test::More;
29 use File::Spec;
30 use File::Find;
32 my @files;
33 sub wanted {
34 my $name = $File::Find::name;
35 push @files, $name
36 unless $name =~ /\/(\.git|koha-tmpl|node_modules|swagger-ui)(\/.*)?$/ ||
37 $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip|patch)$/ ||
38 $name =~ m[(xt/find-license-problems|xt/fix-old-fsf-address|misc/translator/po2json)] ||
39 ! -f $name;
42 find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
44 foreach my $name (@files) {
45 open( my $fh, '<', $name ) || die "cannot open file $name $!";
46 my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense,
47 $hasfranklinst, $is_not_us ) = (0)x7;
48 while ( my $line = <$fh> ) {
49 $hascopyright = 1 if ( $line =~ /^(#|--)?\s*Copyright.*\d\d/ );
50 $hasgpl = 1 if ( $line =~ /GNU General Public License/ );
51 $hasv3 = 1 if ( $line =~ /either version 3/ );
52 $hasorlater = 1
53 if ( $line =~ /any later version/
54 || $line =~ /at your option/ );
55 $haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|;
56 $hasfranklinst = 1 if ( $line =~ /51 Franklin Street/ );
57 $is_not_us = 1 if $line =~ m|This file is part of the Zebra server|;
59 close $fh;
60 next unless $hascopyright;
61 next if $is_not_us;
62 is( $hasgpl
63 && $hasv3
64 && $hasorlater
65 && $haslinktolicense
66 && !$hasfranklinst, 1 ) or diag(sprintf "File %s has wrong copyright: hasgpl=%s, hasv3=%s, hasorlater=%s, haslinktolicense=%s, hasfranklinst=%s", $name, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst);
68 done_testing;