Front page | perl.perl5.porters |
Postings from April 2014
Re: lib/locale.t warnings
Thread Previous
|
Thread Next
From:
Dave Mitchell
Date:
April 14, 2014 14:58
Subject:
Re: lib/locale.t warnings
Message ID:
20140414144323.GF18018@iabyn.com
On Wed, Mar 05, 2014 at 01:10:42PM -0700, Karl Williamson wrote:
> On 02/24/2014 04:31 AM, Dave Mitchell wrote:
> >On Sun, Feb 23, 2014 at 06:00:26PM +0000, Dave Mitchell wrote:
> >>On Sun, Feb 23, 2014 at 10:47:09AM -0700, Karl Williamson wrote:
> >>>On 02/23/2014 07:50 AM, Dave Mitchell wrote:
> >>>>I haven't been following the recent locale.t threads very closely, since
> >>>>they seem to relate to test failures on platforms I don't use.
> >>>>However, recently, I've started seeing *warnings* generated by locale.t.
> >>>>For example on today's blead v5.19.9-28-gdca36a0, on Linux I see:
> >>>>
> >>>>$ ./perl harness run/locale.t
> >>>>run/locale.t .. 8/19 sh: warning: setlocale: LC_ALL: cannot change locale (invalid): No such file or directory
> >>>>sh: warning: setlocale: LC_ALL: cannot change locale (invalid): No such file or directory
> >>>>run/locale.t .. ok
> >>>>All tests successful.
> >>>>Files=1, Tests=19, 1 wallclock secs ( 0.03 usr 0.01 sys + 0.68 cusr 0.09 csys = 0.81 CPU)
> >>>>Result: PASS
> >>>>
> >>>>It appears to be this part of the test file:
> >>>>
> >>>> local $ENV{LC_ALL} = "invalid";
> >>>> local $ENV{LC_NUMERIC} = "invalid";
> >>>> local $ENV{LANG} = $_;
> >>>>
> >>>> # Can't turn off the warnings, so send them to /dev/null
> >>>> fresh_perl_is(<<'EOF', "$difference", { stderr => "devnull" },
> >>>> ....
> >>>>
> >>>>And it appears to be that fresh_perl_is() is spawning a shell which then
> >>>>spawns perl, which runs the test code. But the invalid LC_ALL is seen by
> >>>>the intervening shell, which is generating the warnings.
> >>>>
> >>>>I'm not sure what the best workaround is.
> >>>>
> >>>
> >>>I don't get that on my Linux. What sh are you using?
> >>
> >>$ rpm -qf /bin/sh
> >>bash-4.2.45-1.fc18.x86_64
> >>
> >>This is Fedora 18.
> >
> >and here it is demoed:
> >
> > $ LC_ALL=invalid /bin/sh -c 'echo yes'
> > /bin/sh: warning: setlocale: LC_ALL: cannot change locale (invalid): No such file or directory
> > yes
> > $
> >
> >
> >
>
> Note that when this happens, the test is not actually testing what
> it purports to be, as the environment variable doesn't get changed
> (at least on dromedary and my Ubuntu); hence the test might as well
> be skipped.
I don't understand what you mean here. Even though the shell warns
about LC_ALL etc being invalid, it still passes those invalid env vars
untouched to the scriptlet, which still outputs 4.2 or 4,2 as appropriate.
Anyway, I've fixed this (I hope) by temporarily closing STDERR:
commit ff4377fe256e32a3bc10175c01dd6c68c9ce7ddb
Author: David Mitchell <davem@iabyn.com>
AuthorDate: Mon Apr 14 15:26:18 2014 +0100
Commit: David Mitchell <davem@iabyn.com>
CommitDate: Mon Apr 14 15:37:17 2014 +0100
run/locale.t: silence shell warnings
A couple of tests do
local $ENV{LC_ALL} = "invalid";
fresh_perl_is(...);
this causes a shell to be invoked with an invalid locale. Some shells
such as bash, become very noisy in this case:
$ LC_ALL=invalid /bin/sh -c 'echo yes'
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (invalid): No such file or directory
yes
$
Silence these warnings by temporarily closing STDERR. Since the
fresh_perl_is() scripts themselves are run with STDERR set to /dev/null
anyway, this isn't a hardship.
Affected files ...
M t/run/locale.t
Differences ...
diff --git a/t/run/locale.t b/t/run/locale.t
index f522e0f..8287214 100644
--- a/t/run/locale.t
+++ b/t/run/locale.t
@@ -200,6 +200,15 @@ EOF
"Uses the above test to verify that on Windows the system default locale has lower priority than LC_NUMERIC");
}
+
+ # within this block, STDERR is closed. This is because fresh_perl_is()
+ # forks a shell, and some shells (like bash) can complain noisily when
+ #LC_ALL or similar is set to an invalid value
+
+ {
+ open my $saved_stderr, ">&STDERR" or die "Can't dup STDERR: $!";
+ close STDERR;
+
for ($different) {
local $ENV{LC_ALL} = "invalid";
local $ENV{LC_NUMERIC} = "invalid";
@@ -239,6 +248,9 @@ EOF
}
}
+ open STDERR, ">&", $saved_stderr or die "Can't dup \$saved_stderr: $!";
+ }
+
for ($different) {
local $ENV{LC_NUMERIC} = $_;
local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC
--
Monto Blanco... scorchio!
Thread Previous
|
Thread Next