LP#1680312 Ensure oils_i18n_gettext keys are unique
authorDan Scott <dan@coffeecode.net>
Fri, 7 Apr 2017 18:19:22 +0000 (14:19 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 11 Apr 2017 14:13:34 +0000 (10:13 -0400)
To avoid inadvertent introduction of duplicate oils_18n_gettext() keys
in the data seed SQL, which will then prevent translated strings from
being able to be loaded, add a regression test.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Ben Shum <ben@evergreener.net>
Open-ILS/src/perlmods/t/24-sql-gettext-unique.t [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t b/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t
new file mode 100644 (file)
index 0000000..5df76ce
--- /dev/null
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::Output;
+
+my $num_tests = 0;
+
+my $data;
+{
+    open(my $fh, "<", "../sql/Pg/950.data.seed-values.sql")
+        or die "Can't open 950.data.seed-values.sql: $!";
+    local $/ = undef;
+    $data = <$fh>;
+}
+
+my $findi18n = qr/oils_i18n_gettext\((.*?)\'\s*\)/;
+my $intkey = qr/\s*(\d+)\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/;
+my $textkey = qr/\s*\'(.*?)\'\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/;
+
+my %found;
+my @caps = $data =~ m/$findi18n/gms;
+foreach my $cap (@caps) {
+    my $unique;
+    my @matches = $cap =~ m/$intkey/gms;
+    if (length($matches[0])) {
+        $unique = join('', $matches[0], $matches[2], $matches[3]);
+    } else {
+        @matches = $cap =~ m/$textkey/gms;
+        $unique = join('', $matches[0], $matches[2], $matches[3]);
+    }
+    isnt(exists($found{$unique}), 1, "oils_18n_gettext duplicate key: $cap'");
+    $found{"$unique"} = 1;
+    $num_tests++;
+    #print "$cap \n";
+}
+done_testing($num_tests);