Skip to content

Commit

Permalink
test: warn of possible duplicated strings
Browse files Browse the repository at this point in the history
issue #2001
  • Loading branch information
frankiejol committed Oct 24, 2023
1 parent 59176eb commit eb1092c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion t/90_pos.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eb1092c

Please sign in to comment.