develooper Front page | perl.perl5.porters | Postings from February 2018

Re: [perl #132901] setlocale's return value is broken

Thread Previous | Thread Next
From:
Karl Williamson
Date:
February 25, 2018 19:47
Subject:
Re: [perl #132901] setlocale's return value is broken
Message ID:
c8da47f5-2ddc-28ff-df25-f59b1fbe4798@khwilliamson.com
On 02/25/2018 10:21 AM, Slaven Rezic wrote:
> $ env LC_ALL=de_DE.UTF-8 ./perl -Ilib -MTest::More=no_plan -MPOSIX=setlocale,LC_ALL -e 'is setlocale(LC_ALL), "de_DE.UTF-8"'
> not ok 1
> #   Failed test at -e line 1.
> #          got: '�^'
> #     expected: 'de_DE.UTF-8'
> 1..1
> # Looks like you failed 1 test of 1.

I realize now in looking at the tests why there is not already a test 
for this.  The reason is that the return from setlocale is explictly 
documented to be opaque; not necessarily human readable.  It is required 
only that a future setlocale() changing the locale to the value returned 
properly work.

That said, I know of no system that actually doesn't return a human 
readable name, but it may not exactly match the input one.  It might be 
missing (or gained) a hyphen, or the casing may be different.  And where 
individual categories aren't all the same, LC_ALL is represented 
differently on different systems.  (On Linux, it is a list of the 
individual categories and their values with each component separated by 
a semi-colon).

I suppose a test could be written which strips off the hyphens and 
lowercases everything, and then do the comparison, and then we could 
skip or adjust this test if any platforms showed up if failed for.

I'm open to hearing ideas.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About