View | Details | Raw Unified | Return to bug 29324
Collapse All | Expand All

(-)a/xt/find-license-problems.t (-8 / +24 lines)
Lines 24-39 Link Here
24
# along with Koha; if not, see <http://www.gnu.org/licenses>.
24
# along with Koha; if not, see <http://www.gnu.org/licenses>.
25
25
26
use Modern::Perl;
26
use Modern::Perl;
27
use Test::More;
27
use Test::More tests => 1;
28
28
29
use File::Spec;
29
use File::Spec;
30
use File::Find;
30
use File::Find;
31
31
32
my @files;
32
my @files;
33
33
sub wanted {
34
sub wanted {
34
    my $name = $File::Find::name;
35
    my $name = $File::Find::name;
35
    push @files, $name
36
    push @files, $name
36
        unless $name =~ /\/(\.git|koha-tmpl|node_modules|swagger-ui)(\/.*)?$/ ||
37
        unless $name =~ /\/(\.git|installer\/data\/mysql\/db_revs|koha-tmpl|node_modules|swagger-ui|Koha.Schema.Result)(\/.*)?$/ ||
37
               $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip|patch)$/ ||
38
               $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
               $name =~ m[(xt/find-license-problems|xt/fix-old-fsf-address|misc/translator/po2json)] ||
39
               ! -f $name;
40
               ! -f $name;
Lines 41-47 sub wanted { Link Here
41
42
42
find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
43
find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir());
43
44
44
foreach my $name (@files) {
45
my @fails;
46
foreach my $name (sort @files) {
45
    open( my $fh, '<', $name ) || die "cannot open file $name $!";
47
    open( my $fh, '<', $name ) || die "cannot open file $name $!";
46
    my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense,
48
    my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense,
47
        $hasfranklinst, $is_not_us, $needs_copyright ) = (0)x8;
49
        $hasfranklinst, $is_not_us, $needs_copyright ) = (0)x8;
Lines 55-70 foreach my $name (@files) { Link Here
55
        $haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|;
57
        $haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|;
56
        $hasfranklinst    = 1 if ( $line =~ /51 Franklin Street/ );
58
        $hasfranklinst    = 1 if ( $line =~ /51 Franklin Street/ );
57
        $is_not_us        = 1 if $line =~ m|This file is part of the Zebra server|;
59
        $is_not_us        = 1 if $line =~ m|This file is part of the Zebra server|;
58
        $needs_copyright  = 1 if $line =~ m|This file is part of Koha| || $name =~ /(.*).pl/ || $name =~ /(.*).pm/;
60
        $needs_copyright  = 1 if $line =~ m|This file is part of Koha| || $name =~ /\.(pl|pm)/;
59
    }
61
    }
60
    close $fh;
62
    close $fh;
61
    next unless $hascopyright || $needs_copyright;
63
    next unless $hascopyright || $needs_copyright;
62
    next if $is_not_us;
64
    next if $is_not_us;
63
    is(    $hascopyright
65
    my $diagnostics = license_info( $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst );
66
    push @fails, [ $name, $diagnostics ] if $diagnostics;
67
}
68
is( scalar @fails, 0, 'No files without license problems anymore!' );
69
70
if( grep { $_ eq '-v' } @ARGV ) {
71
    map { print "File ". $_->[0]. ": ". $_->[1]. "\n"; } @fails;
72
}
73
74
sub license_info {
75
    my ( $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst ) = @_;
76
    return sprintf(
77
        "hascopyright=%s, needs_copyright=%s, hasgpl=%s, hasv3=%s, hasorlater=%s, haslinktolicense=%s, hasfranklinst=%s",
78
        $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst
79
        )
80
        unless $hascopyright
64
        && $hasgpl
81
        && $hasgpl
65
        && $hasv3
82
        && $hasv3
66
        && $hasorlater
83
        && $hasorlater
67
        && $haslinktolicense
84
        && $haslinktolicense
68
        && !$hasfranklinst,  1 ) or diag(sprintf "File %s has wrong copyright: hascopyright=%s, hasgpl=%s, hasv3=%s, hasorlater=%s, haslinktolicense=%s, hasfranklinst=%s", $name, $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst);
85
        && !$hasfranklinst;
86
    return;
69
}
87
}
70
done_testing;
71
- 

Return to bug 29324