From 02aba72f9af3ac175d1dfacad3955de025cd7130 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 16 Jul 2013 22:02:46 -0600 Subject: [PATCH] Move some tests from cpan/version to t/run Commit fb7942811c8097ed2e61fd35a90345226546176a recently moved version.pm to cpan. Earlier, in commit b127e37e51c21b0a36755dcd19811be931a03d83, I had added tests to version's .t that arguably belonged elsewhere. I did this because I thought that this .t was the only one around that had the infrastructure already written to allow such tests to easily be added, and it was in /lib so p5p controlled it. (That infrastructure being finding locales with the decimal point not a dot.) Since then, I found that t/run/locale.t has similar infrastructure. Given that version now may end up being cpan upstream, I thought it best to move those tests to t/run/locale.t I notice that changes to this .t prior to these no longer were careful to avoid 'use locale' in case the platform doesn't support it, and there have been no field problems; so I just went ahead and did a 'use locale' too. --- cpan/version/t/07locale.t | 16 ++++------------ t/run/locale.t | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/cpan/version/t/07locale.t b/cpan/version/t/07locale.t index fe8e0e5..d6dc8c9 100644 --- a/cpan/version/t/07locale.t +++ b/cpan/version/t/07locale.t @@ -7,7 +7,7 @@ use File::Basename; use File::Temp qw/tempfile/; use POSIX qw/locale_h/; -use Test::More tests => 9; +use Test::More tests => 7; use Config; BEGIN { @@ -15,8 +15,8 @@ BEGIN { } SKIP: { - skip 'No locale testing for Perl < 5.6.0', 8 if $] < 5.006; - skip 'No locale testing without d_setlocale', 8 if(!$Config{d_setlocale}); + skip 'No locale testing for Perl < 5.6.0', 6 if $] < 5.006; + skip 'No locale testing without d_setlocale', 6 if(!$Config{d_setlocale}); # test locale handling my $warning; @@ -36,7 +36,7 @@ SKIP: { $loc = setlocale( LC_ALL, $_); last if localeconv()->{decimal_point} eq ','; } - skip 'Cannot test locale handling without a comma locale', 7 + skip 'Cannot test locale handling without a comma locale', 5 unless $loc and localeconv()->{decimal_point} eq ','; diag ("Testing locale handling with $loc") unless $ENV{PERL_CORE}; @@ -49,14 +49,6 @@ SKIP: { ok ($v eq "1.23", "Locale doesn't apply to version objects"); ok ($v == $ver, "Comparison to locale floating point"); - { - no locale; - ok ("$ver eq '1.23'", "Outside of scope of use locale"); - } - - ok("\"$ver\"+1 gt 2.22" && \"$ver\"+1 lt 2.24", - "Can do math when radix is not a dot"); # [perl 115800] - setlocale( LC_ALL, $orig_loc); # reset this before possible skip skip 'Cannot test RT#46921 with Perl < 5.008', 1 if ($] < 5.008); diff --git a/t/run/locale.t b/t/run/locale.t index d01e3bc..4422317 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -62,7 +62,7 @@ EOF # try to find out a locale where LC_NUMERIC makes a difference my $original_locale = setlocale(LC_NUMERIC); -my ($base, $different, $difference); +my ($base, $different, $comma, $difference); for ("C", @locales) { # prefer C for the base if available BEGIN { if($Config{d_setlocale}) { @@ -76,9 +76,10 @@ for ("C", @locales) { # prefer C for the base if available } else { $different ||= $_; $difference ||= $s; + $comma ||= $_ if localeconv()->{decimal_point} eq ','; } - last if $base && $different; + last if $base && $different && $comma; } setlocale(LC_NUMERIC, $original_locale); @@ -167,7 +168,6 @@ EOF "", {}, "version does not clobber version (via eval)"); } - for ($different) { local $ENV{LC_NUMERIC} = $_; local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC @@ -180,6 +180,37 @@ EOF EOF "sprintf() and printf() look at LC_NUMERIC regardless of constant folding"); } + + unless ($comma) { + skip("no locale available where LC_NUMERIC is a comma", 2); + } + else { + + fresh_perl_is(<<"EOF", + my \$i = 1.5; + { + use locale; + use POSIX; + POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma"); + print \$i, "\n"; + } + print \$i, "\n"; +EOF + "1,5\n1.5", {}, "Radix print properly in locale scope, and without"); + + fresh_perl_is(<<"EOF", + my \$i = 1.5; # Should be exactly representable as a base 2 + # fraction, so can use 'eq' below + use locale; + use POSIX; + POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma"); + print \$i, "\n"; + \$i += 1; + print \$i, "\n"; +EOF + "1,5\n2,5", {}, "Can do math when radix is a comma"); # [perl 115800] + } + } # SKIP -sub last { 9 } +sub last { 11 } -- 2.7.4