From eb1092c9c2ae3efa8005d4dee17097b38eaa4bee Mon Sep 17 00:00:00 2001 From: Francesc Guasch Date: Tue, 24 Oct 2023 12:35:36 +0200 Subject: [PATCH] test: warn of possible duplicated strings issue #2001 --- t/90_pos.t | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/t/90_pos.t b/t/90_pos.t index 066e58b98..cc2a15b61 100644 --- a/t/90_pos.t +++ b/t/90_pos.t @@ -12,14 +12,57 @@ my $MSGUNIQ = `which msguniq`; chomp $MSGUNIQ; ok($MSGUNIQ,"msguniq required to test po files"); +sub test_duplicated { + my $file = shift; + open my $in,"<", $file or die "$! $file"; + my $msgid; + my %found; + my $string; + my @warnings; + while (my $line = <$in>) { + my ($msgstr) = $line =~ /^msgstr/; + if ($msgstr && $string) { + my $string_lc = uc($string); + if($found{$string_lc}) { + push@warnings,("'$string' duplicated in line ".$found{$string_lc}." and $."); + } + $found{$string_lc}=$.; + $string = undef; + next; + } + my ($string1) = $line =~ /^msgid "(.*)"/; + if (defined $string1) { + $string = $string1; + next; + } + if (!defined $string1 && defined $string) { + my ($string2) = $line =~ /^"(.*)"/; + if (defined $string2) { + $msgid=0; + $string = "$string$string2"; + } + } + next if !$string; + } + + close $in; + if (@warnings){ + diag("Warning: duplicated strings found in $file"); + diag(join("\n",map {" - $_" } @warnings)); + } +} + my @po; opendir my $po,$DIR_PO or die "$! $DIR_PO"; while (my $file = readdir $po) { - next if $file !~ /\.po/; + next if $file !~ /\.po$/; push @po,($file); } closedir $po; +for my $file (@po) { + test_duplicated("$DIR_PO/$file"); +} SKIP: { skip("Missing msguniq", scalar @po) if !$MSGUNIQ;