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

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

Thread Previous | Thread Next
Karl Williamson
February 25, 2018 19:47
Re: [perl #132901] setlocale's return value is broken
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About