From f576d0f1bc71c730a10da893025da7034cf0eff7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Jul 2025 10:31:18 +0200 Subject: [PATCH] Bug 40402: Make xt/find-license-problems.t process files that are in the git index And only those files. Currently the test is failing with 02:52:31 koha_1 | # Failed test at xt/find-license-problems.t line 65. 02:52:31 koha_1 | # got: '0' 02:52:31 koha_1 | # expected: '1' 02:52:33 koha_1 | # File ./misc/translator/po/LICENSE has wrong copyright: hasgpl=1, hasv3=1, hasorlater=1, haslinktolicense=0, hasfranklinst=0 02:52:33 koha_1 | # Looks like you failed 1 test of 1381. 02:52:33 koha_1 | [00:51:24] xt/find-license-problems.t Because a LICENSE file has been added to koha-l10n, and now this test fails on it. https://gitlab.com/koha-community/koha-l10n/-/commit/27ab9ff4d2462c3f95cd54ae4a2e53ce7d2f6a65 But we should not test files that are not part of the git index. Test plan: 0. Do not apply this patch 1. Edit xt/find-license-problems.t, add warn scalar(@files); 2. Run `prove xt/find-license-problems.t` => Notice that 4056 files are processed Note that you need to have a clean git repo. You can run the following git command BUT BEWARE /*\ it will remove all changes not committed `git clean -d -f` 3. Apply this patch, prove again => Tests are passing, with the same number of tests xt/find-license-problems.t .. ok All tests successful. Files=1, Tests=4056 Note that I think we lost one file, as Test::NoWarnings is adding a test. But I don't think it is worth the trouble to find out which one is missing. Signed-off-by: Lucas Gass Signed-off-by: Tomas Cohen Arazi --- xt/find-license-problems.t | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/xt/find-license-problems.t b/xt/find-license-problems.t index 5f93516aa54..92edba9353e 100755 --- a/xt/find-license-problems.t +++ b/xt/find-license-problems.t @@ -25,22 +25,20 @@ use Modern::Perl; use Test::More; +use Test::NoWarnings; -use File::Spec; -use File::Find; +my @files = map { + chomp; + my $name = $_; + !( $name =~ m{^koha-tmpl/} + || $name =~ m{\.(gif|jpg|odt|ogg|pdf|png|po|psd|svg|swf|zip)$} + || $name =~ m{xt/find-license-problems|xt/fix-old-fsf-address|misc/translator/po2json} + || !-f $name ) + ? $_ + : () +} `git ls-tree -r HEAD --name-only`; # only files part of git -my @files; - -sub wanted { - my $name = $File::Find::name; - push @files, $name - unless $name =~ /\/(\.git|koha-tmpl|node_modules|swagger-ui)(\/.*)?$/ - || $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; -} - -find( { wanted => \&wanted, no_chdir => 1 }, File::Spec->curdir() ); +plan tests => scalar(@files) + 1; foreach my $name (@files) { open( my $fh, '<', $name ) || die "cannot open file $name $!"; @@ -60,8 +58,12 @@ foreach my $name (@files) { $is_not_us = 1 if $line =~ m|This file is part of the Zebra server|; } close $fh; - next unless $hascopyright; - next if $is_not_us; + + if ( !$hascopyright || $is_not_us ) { + pass(); + next; + } + is( $hasgpl && $hasv3 && $hasorlater && $haslinktolicense && !$hasfranklinst, 1 ) or diag( sprintf @@ -69,4 +71,3 @@ foreach my $name (@files) { $name, $hasgpl, $hasv3, $hasorlater, $haslinktolicense, $hasfranklinst ); } -done_testing; -- 2.50.1