From 6daf09496ab37a8b2a57d2791a87ea120b077480 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Tue, 11 Feb 2025 23:14:41 +0100
Subject: [PATCH] Bug 38664: Add a xt test for TT files

---
 misc/devel/tidy.pl |  3 +--
 xt/tt_tidy.t       | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 xt/tt_tidy.t

diff --git a/misc/devel/tidy.pl b/misc/devel/tidy.pl
index 88b53f88658..c3f22e635ea 100755
--- a/misc/devel/tidy.pl
+++ b/misc/devel/tidy.pl
@@ -50,7 +50,6 @@ my @exceptions = qw(
     misc/cronjobs/rss/lastAcquired-2.0.tt
     misc/cronjobs/rss/longestUnseen.tt
     misc/cronjobs/rss/mostReserved.tt
-    t/db_dependent/misc/translator/sample.tt
 );
 
 @files = array_minus( @files, @exceptions );
@@ -121,7 +120,7 @@ sub get_js_files {
 }
 
 sub get_tt_files {
-    my @files = qx{git ls-files '*.tt' '*.inc' ':(exclude)Koha/ILL/Backend/' ':(exclude)doc-head-open.inc'};
+    my @files = qx{git ls-files '*.tt' '*.inc' ':(exclude)Koha/ILL/Backend/' ':(exclude)*doc-head-open.inc'};
     chomp for @files;
     return @files;
 }
diff --git a/xt/tt_tidy.t b/xt/tt_tidy.t
new file mode 100644
index 00000000000..dfb3de2f8cf
--- /dev/null
+++ b/xt/tt_tidy.t
@@ -0,0 +1,53 @@
+#/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+use threads;    # used for parallel
+use File::Slurp qw( read_file );
+use Test::More;
+use Test::Strict;
+use Parallel::ForkManager;
+use Sys::CPU;
+
+my @tt_files =
+    qx{git ls-files '*.tt' '*.inc' ':(exclude)Koha/ILL/Backend/' ':(exclude)*doc-head-open.inc' ':(exclude)misc/cronjobs/rss'};
+
+$Test::Strict::TEST_STRICT = 0;
+
+my $ncpu;
+if ( $ENV{KOHA_PROVE_CPUS} ) {
+    $ncpu = $ENV{KOHA_PROVE_CPUS};
+} else {
+    $ncpu = Sys::CPU::cpu_count();
+}
+
+my $pm = Parallel::ForkManager->new($ncpu);
+
+foreach my $filepath (@tt_files) {
+    $pm->start and next;
+
+    chomp $filepath;
+    my $tidy    = qx{perl misc/devel/tidy.pl --silent --no-write $filepath};
+    my $content = read_file $filepath;
+    ok( $content eq $tidy, "$filepath should be kept tidy" );
+
+    $pm->finish;
+}
+
+$pm->wait_all_children;
+
+done_testing;
-- 
2.34.1