This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add test case for [perl #123171]
authorKarl Williamson <khw@cpan.org>
Wed, 7 Jan 2015 04:05:43 +0000 (21:05 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 7 Jan 2015 04:41:25 +0000 (21:41 -0700)
This looks for a non-English locale to test with, as the bug appears
only in such locales.  The fix to the referenced ticket broke the .t
file in non-English locales, and this commit fixes it.  If no
non-English locale is found, the code runs anyway, using an English one.

Part of the commit came from Slaven Rezic.

ext/POSIX/t/wrappers.t

index 5b9f6d6..01049a0 100644 (file)
@@ -10,6 +10,7 @@ plan(skip_all => "POSIX is unavailable")
 require POSIX;
 require Symbol;
 require File::Temp;
+require 'loc_tools.pl';
 
 use constant NOT_HERE => 'this-file-should-not-exist';
 
@@ -21,6 +22,24 @@ my $temp_file = $temp_fh->filename;
 # exit, fork, waitpid, sleep in waitpid.t
 # errno in posix.t
 
+if ($Config{d_setlocale}) {
+    my $non_english_locale;
+    local $! = 1;
+    my $english_message = "$!"; # Should be C locale since not in scope of
+                                # "use locale"
+    for $non_english_locale (find_locales(&POSIX::LC_MESSAGES,
+                                          'reasonable_locales_only'))
+    {
+        use locale;
+        setlocale(&POSIX::LC_MESSAGES, $non_english_locale);
+        $! = 1;
+        last if "$!" ne $english_message;
+    }
+
+    # If we found a locale whose message wasn't in English, we have
+    # setlocale() to it.
+}
+
 is(POSIX::abs(-42), 42, 'abs');
 is(POSIX::abs(-3.14), 3.14, 'abs');
 is(POSIX::abs(POSIX::exp(1)), CORE::exp(1), 'abs');
@@ -115,8 +134,10 @@ is(POSIX::sprintf('%o', 42), '52', 'sprintf');
 is(POSIX::sqrt(256), 16, 'sqrt');
 is_deeply([POSIX::stat($temp_file)], [stat $temp_file], 'stat');
 {
+    use locale;
     local $! = 2;
     my $error = "$!";
+    no locale;
     is(POSIX::strerror(2), $error, 'strerror');
 }