This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
loc_tools.pl: properly load fallback locales
authorTomasz Konojacki <me@xenu.pl>
Wed, 10 Jan 2018 03:49:08 +0000 (04:49 +0100)
committerKarl Williamson <khw@cpan.org>
Wed, 10 Jan 2018 17:28:54 +0000 (10:28 -0700)
It turns out that some tests using loc_tools.pl are being executed
from a different working directory than './t', which causes
do("./lib/locale/<locale>") to fail.

This fixes lib/warnings.t on Windows.

Discussion:
https://www.nntp.perl.org/group/perl.perl5.porters/2018/01/msg248652.html

t/loc_tools.pl

index d9dbfcd..fbe7242 100644 (file)
@@ -363,8 +363,8 @@ sub find_locales ($;$) {
         # Locales whose name differs if the utf8 bit is on are stored in these
         # two files with appropriate encodings.
         my $data_file = ($^H & 0x08 || (${^OPEN} || "") =~ /:utf8/)
-                        ? "./lib/locale/utf8"
-                        : "./lib/locale/latin1";
+                        ? _source_location() . "/lib/locale/utf8"
+                        : _source_location() . "/lib/locale/latin1";
         if (-e $data_file) {
             @Data = do $data_file;
         }
@@ -487,6 +487,20 @@ sub find_utf8_ctype_locale (;$) { # Return the name of a locale that core Perl
     return;
 }
 
+# returns full path to the directory containing the current source
+# file, inspired by mauke's Dir::Self
+sub _source_location {
+    require File::Spec;
+
+    my $caller_filename = (caller)[1];
+
+    return File::Spec->rel2abs(
+        File::Spec->catpath(
+            (File::Spec->splitpath($caller_filename))[0, 1]
+        )
+    );
+}
+
 1
 
 # Format of data is: locale_name, language_codes, country_codes, encodings