1#! /usr/local/perl -w 2# Before `make install' is performed this script should be runnable with 3# `make test'. After `make install' it should work as `perl test.pl' 4 5######################### 6 7use File::Basename; 8use File::Temp qw/tempfile/; 9use POSIX qw/locale_h/; 10use Test::More tests => 7; 11use Config; 12 13BEGIN { 14 use_ok('version', 0.9909); 15} 16 17SKIP: { 18 skip 'No locale testing for Perl < 5.6.0', 6 if $] < 5.006; 19 skip 'No locale testing without d_setlocale', 6 20 if(!$Config{d_setlocale}); 21 22 # test locale handling 23 my $warning; 24 25 local $SIG{__WARN__} = sub { $warning = $_[0] }; 26 27 my $ver = 1.23; # has to be floating point number 28 my $loc; 29 my $orig_loc = setlocale(LC_NUMERIC); 30 ok ($ver eq "1.23", 'Not using locale yet'); # Don't use is(), 31 # because have to 32 # evaluate in current 33 # scope 34 use if $^O !~ /android/, 'locale'; 35 36 while (<DATA>) { 37 chomp; 38 $loc = setlocale( LC_ALL, $_); 39 last if $loc && localeconv()->{decimal_point} eq ','; 40 } 41 skip 'Cannot test locale handling without a comma locale', 5 42 unless $loc and localeconv()->{decimal_point} eq ','; 43 44 setlocale(LC_NUMERIC, $loc); 45 $ver = 1.23; # has to be floating point number 46 ok ($ver eq "1,23", "Using locale: $loc"); 47 $v = version->new($ver); 48 unlike($warning, qr/Version string '1,23' contains invalid data/, 49 "Process locale-dependent floating point"); 50 ok ($v eq "1.23", "Locale doesn't apply to version objects"); 51 ok ($v == $ver, "Comparison to locale floating point"); 52 53 setlocale( LC_ALL, $orig_loc); # reset this before possible skip 54 skip 'Cannot test RT#46921 with Perl < 5.008', 1 55 if ($] < 5.008); 56 skip 'Cannot test RT#46921 with pure Perl module', 1 57 if exists $INC{'version/vpp.pm'}; 58 my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1); 59 (my $package = basename($filename)) =~ s/\.pm$//; 60 print $fh <<"EOF"; 61package $package; 62use locale; 63use POSIX qw(locale_h); 64\$^W = 1; 65use version; 66setlocale (LC_ALL, '$loc'); 67use version ; 68eval "use Socket 1.7"; 69setlocale( LC_ALL, '$orig_loc'); 701; 71EOF 72 close $fh; 73 74 eval "use lib '.'; use $package;"; 75 unlike($warning, qr"Version string '1,7' contains invalid data", 76 'Handle locale action-at-a-distance'); 77 } 78 79__DATA__ 80af_ZA 81af_ZA.utf8 82an_ES 83an_ES.utf8 84az_AZ.utf8 85be_BY 86be_BY.utf8 87bg_BG 88bg_BG.utf8 89br_FR 90br_FR@euro 91br_FR.utf8 92bs_BA 93bs_BA.utf8 94ca_ES 95ca_ES@euro 96ca_ES.utf8 97cs_CZ 98cs_CZ.utf8 99da_DK 100da_DK.utf8 101de_AT 102de_AT@euro 103de_AT.utf8 104de_BE 105de_BE@euro 106de_BE.utf8 107de_DE 108de_DE@euro 109de_DE.utf8 110de_LU 111de_LU@euro 112de_LU.utf8 113el_GR 114el_GR.utf8 115en_DK 116en_DK.utf8 117es_AR 118es_AR.utf8 119es_BO 120es_BO.utf8 121es_CL 122es_CL.utf8 123es_CO 124es_CO.utf8 125es_EC 126es_EC.utf8 127es_ES 128es_ES@euro 129es_ES.utf8 130es_PY 131es_PY.utf8 132es_UY 133es_UY.utf8 134es_VE 135es_VE.utf8 136et_EE 137et_EE.iso885915 138et_EE.utf8 139eu_ES 140eu_ES@euro 141eu_ES.utf8 142fi_FI 143fi_FI@euro 144fi_FI.utf8 145fo_FO 146fo_FO.utf8 147fr_BE 148fr_BE@euro 149fr_BE.utf8 150fr_CA 151fr_CA.utf8 152fr_CH 153fr_CH.utf8 154fr_FR 155fr_FR@euro 156fr_FR.utf8 157fr_LU 158fr_LU@euro 159fr_LU.utf8 160gl_ES 161gl_ES@euro 162gl_ES.utf8 163hr_HR 164hr_HR.utf8 165hu_HU 166hu_HU.utf8 167id_ID 168id_ID.utf8 169is_IS 170is_IS.utf8 171it_CH 172it_CH.utf8 173it_IT 174it_IT@euro 175it_IT.utf8 176ka_GE 177ka_GE.utf8 178kk_KZ 179kk_KZ.utf8 180kl_GL 181kl_GL.utf8 182lt_LT 183lt_LT.utf8 184lv_LV 185lv_LV.utf8 186mk_MK 187mk_MK.utf8 188mn_MN 189mn_MN.utf8 190nb_NO 191nb_NO.utf8 192nl_BE 193nl_BE@euro 194nl_BE.utf8 195nl_NL 196nl_NL@euro 197nl_NL.utf8 198nn_NO 199nn_NO.utf8 200no_NO 201no_NO.utf8 202oc_FR 203oc_FR.utf8 204pl_PL 205pl_PL.utf8 206pt_BR 207pt_BR.utf8 208pt_PT 209pt_PT@euro 210pt_PT.utf8 211ro_RO 212ro_RO.utf8 213ru_RU 214ru_RU.koi8r 215ru_RU.utf8 216ru_UA 217ru_UA.utf8 218se_NO 219se_NO.utf8 220sh_YU 221sh_YU.utf8 222sk_SK 223sk_SK.utf8 224sl_SI 225sl_SI.utf8 226sq_AL 227sq_AL.utf8 228sr_CS 229sr_CS.utf8 230sv_FI 231sv_FI@euro 232sv_FI.utf8 233sv_SE 234sv_SE.iso885915 235sv_SE.utf8 236tg_TJ 237tg_TJ.utf8 238tr_TR 239tr_TR.utf8 240tt_RU.utf8 241uk_UA 242uk_UA.utf8 243vi_VN 244vi_VN.tcvn 245wa_BE 246wa_BE@euro 247wa_BE.utf8 248