From 8aa56900a4f8bf6267039f13accace6fa88c9364 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 26 Jul 2023 13:04:25 +0000 Subject: [PATCH] Bug 29324: (QA follow-up) Polishing Content-Type: text/plain; charset=utf-8 Making the verbose output a bit more manageable with -v option. If we just run the test, we get the total of files with license problems. Added Koha/Schema/Result as exception. Sorts results on file name. --- xt/find-license-problems.t | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/xt/find-license-problems.t b/xt/find-license-problems.t index 0e1323c5ef..eb21cc1b14 100755 --- a/xt/find-license-problems.t +++ b/xt/find-license-problems.t @@ -24,16 +24,17 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More; +use Test::More tests => 1; use File::Spec; use File::Find; my @files; + sub wanted { my $name = $File::Find::name; push @files, $name - unless $name =~ /\/(\.git|koha-tmpl|node_modules|swagger-ui)(\/.*)?$/ || + unless $name =~ /\/(\.git|installer\/data\/mysql\/db_revs|koha-tmpl|node_modules|swagger-ui|Koha.Schema.Result)(\/.*)?$/ || $name =~ /\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip|patch)$/ || $name =~ m[(xt/find-license-problems|xt/fix-old-fsf-address|misc/translator/po2json)] || ! -f $name; @@ -41,7 +42,8 @@ sub wanted { find({ wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir()); -foreach my $name (@files) { +my @fails; +foreach my $name (sort @files) { open( my $fh, '<', $name ) || die "cannot open file $name $!"; my ( $hascopyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst, $is_not_us, $needs_copyright ) = (0)x8; @@ -55,16 +57,31 @@ foreach my $name (@files) { $haslinktolicense = 1 if $line =~ m|http://www\.gnu\.org/licenses|; $hasfranklinst = 1 if ( $line =~ /51 Franklin Street/ ); $is_not_us = 1 if $line =~ m|This file is part of the Zebra server|; - $needs_copyright = 1 if $line =~ m|This file is part of Koha| || $name =~ /(.*).pl/ || $name =~ /(.*).pm/; + $needs_copyright = 1 if $line =~ m|This file is part of Koha| || $name =~ /\.(pl|pm)/; } close $fh; next unless $hascopyright || $needs_copyright; next if $is_not_us; - is( $hascopyright + my $diagnostics = license_info( $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst ); + push @fails, [ $name, $diagnostics ] if $diagnostics; +} +is( scalar @fails, 0, 'No files without license problems anymore!' ); + +if( grep { $_ eq '-v' } @ARGV ) { + map { print "File ". $_->[0]. ": ". $_->[1]. "\n"; } @fails; +} + +sub license_info { + my ( $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst ) = @_; + return sprintf( + "hascopyright=%s, needs_copyright=%s, hasgpl=%s, hasv3=%s, hasorlater=%s, haslinktolicense=%s, hasfranklinst=%s", + $hascopyright, $needs_copyright, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst + ) + unless $hascopyright && $hasgpl && $hasv3 && $hasorlater && $haslinktolicense - && !$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); + && !$hasfranklinst; + return; } -done_testing; -- 2.30.2