From 26978cedca336428512ffb16add3ebb81d740895 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 29 Jul 2025 11:53:22 +0200 Subject: [PATCH] Bug 40541: Add missing new line at the end of files when missing We have insert_final_newline = true to ensure files will contain a new line at the end. However we have seen commits with "No new line" added in the git log. We should have a xt test to prevent more occurrences. We should also have a test at the QA script level: https://gitlab.com/koha-community/qa-test-tools/-/issues/96 Test plan: prove xt/find-missing-new-lines-at-the-end-of-file.t should return green. Remove the new line at the end of a file, eg. vim -b mainpage.pl :set noeol :wq Now prove xt/find-missing-new-lines-at-the-end-of-file.t is failing on mainpage.pl. --- ...ind-missing-new-lines-at-the-end-of-file.t | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 xt/find-missing-new-lines-at-the-end-of-file.t diff --git a/xt/find-missing-new-lines-at-the-end-of-file.t b/xt/find-missing-new-lines-at-the-end-of-file.t new file mode 100755 index 00000000000..b897acbbd90 --- /dev/null +++ b/xt/find-missing-new-lines-at-the-end-of-file.t @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use Modern::Perl; +use Test::PerlTidy; +use Test::More; +use Test::NoWarnings; + +use Koha::Devel::Files; + +my $dev_files = Koha::Devel::Files->new( { context => 'all' } ); +my @files; +push @files, $dev_files->ls_perl_files; +push @files, $dev_files->ls_tt_files; +push @files, $dev_files->ls_js_files; +push @files, $dev_files->ls_yml_files; +push @files, $dev_files->ls_css_files; + +#plan tests => scalar @files + 1; +plan tests => scalar @files; + +for my $file (@files) { + if ( -z $file ) { + + # File is empty + ok(1); + next; + } + open my $fh, '<', $file or die "Can't open file ($file): $!"; + seek $fh, -1, 2 or die "Can't seek ($file): $!"; + read $fh, my $char, 1; + close $fh; + is( $char, "\n", "$file should end with a new line" ); +} -- 2.34.1