This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
warn if ++ or -- are unable to change the value because it's beyond
[perl5.git] / lib / version.t
CommitLineData
129318bd 1#! /usr/local/perl -w
a7ad731c
HS
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'
a7ad731c
HS
4
5#########################
6
34ba6322 7use Test::More qw(no_plan);
72287d96 8use Data::Dumper;
c8a14fb6
RGS
9require Test::Harness;
10no warnings 'once';
11*Verbose = \$Test::Harness::Verbose;
a7ad731c 12
137d6fc0 13diag "Tests with base class" unless $ENV{PERL_CORE};
a7ad731c 14
5eb567df 15BEGIN {
43eaf59d 16 use_ok("version", 0.50); # If we made it this far, we are ok.
5eb567df
RGS
17}
18
137d6fc0
JP
19BaseTests("version");
20
21diag "Tests with empty derived class" unless $ENV{PERL_CORE};
22
23package version::Empty;
43eaf59d 24use base version;
137d6fc0 25$VERSION = 0.01;
43eaf59d
SP
26no warnings 'redefine';
27*::qv = sub { return bless version::qv(shift), __PACKAGE__; };
137d6fc0 28
e0218a61
JP
29package version::Bad;
30use base version;
31sub new { my($self,$n)=@_; bless \$n, $self }
32
137d6fc0 33package main;
e0218a61 34my $testobj = version::Empty->new(1.002_003);
137d6fc0
JP
35isa_ok( $testobj, "version::Empty" );
36ok( $testobj->numify == 1.002003, "Numified correctly" );
9137345a
JP
37ok( $testobj->stringify eq "1.002003", "Stringified correctly" );
38ok( $testobj->normal eq "v1.2.3", "Normalified correctly" );
137d6fc0 39
e0218a61 40my $verobj = version->new("1.2.4");
137d6fc0
JP
41ok( $verobj > $testobj, "Comparison vs parent class" );
42ok( $verobj gt $testobj, "Comparison vs parent class" );
43BaseTests("version::Empty");
44
e0218a61
JP
45diag "tests with bad subclass" unless $ENV{PERL_CORE};
46$testobj = version::Bad->new(1.002_003);
47isa_ok( $testobj, "version::Bad" );
48eval { my $string = $testobj->numify };
49like($@, qr/Invalid version object/,
50 "Bad subclass numify");
51eval { my $string = $testobj->normal };
52like($@, qr/Invalid version object/,
53 "Bad subclass normal");
54eval { my $string = $testobj->stringify };
55like($@, qr/Invalid version object/,
56 "Bad subclass stringify");
57eval { my $test = $testobj > 1.0 };
58like($@, qr/Invalid version object/,
59 "Bad subclass vcmp");
60
c0b17f21
JP
61# dummy up a redundant call to satify David Wheeler
62local $SIG{__WARN__} = sub { die $_[0] };
63eval 'use version;';
64unlike ($@, qr/^Subroutine main::qv redefined/,
65 "Only export qv once per package (to prevent redefined warnings).");
66
137d6fc0
JP
67sub BaseTests {
68
317f7c8a
RGS
69 my ($CLASS, $no_qv) = @_;
70
71 # Insert your test code below, the Test module is use()ed here so read
72 # its man page ( perldoc Test ) for help writing this test script.
73
74 # Test bare number processing
75 diag "tests with bare numbers" if $Verbose;
76 $version = $CLASS->new(5.005_03);
8cb289bd 77 is ( "$version" , "5.00503" , '5.005_03 eq 5.00503' );
317f7c8a 78 $version = $CLASS->new(1.23);
8cb289bd 79 is ( "$version" , "1.23" , '1.23 eq "1.23"' );
317f7c8a
RGS
80
81 # Test quoted number processing
82 diag "tests with quoted numbers" if $Verbose;
83 $version = $CLASS->new("5.005_03");
8cb289bd 84 is ( "$version" , "5.005_03" , '"5.005_03" eq "5.005_03"' );
317f7c8a 85 $version = $CLASS->new("v1.23");
8cb289bd 86 is ( "$version" , "v1.23" , '"v1.23" eq "v1.23"' );
317f7c8a
RGS
87
88 # Test stringify operator
89 diag "tests with stringify" if $Verbose;
90 $version = $CLASS->new("5.005");
91 is ( "$version" , "5.005" , '5.005 eq "5.005"' );
92 $version = $CLASS->new("5.006.001");
8cb289bd 93 is ( "$version" , "5.006.001" , '5.006.001 eq v5.6.1' );
317f7c8a 94 $version = $CLASS->new("1.2.3_4");
8cb289bd 95 is ( "$version" , "1.2.3_4" , 'alpha version 1.2.3_4 eq v1.2.3_4' );
317f7c8a
RGS
96
97 # test illegal formats
98 diag "test illegal formats" if $Verbose;
99 eval {my $version = $CLASS->new("1.2_3_4")};
100 like($@, qr/multiple underscores/,
101 "Invalid version format (multiple underscores)");
102
103 eval {my $version = $CLASS->new("1.2_3.4")};
104 like($@, qr/underscores before decimal/,
105 "Invalid version format (underscores before decimal)");
106
107 eval {my $version = $CLASS->new("1_2")};
108 like($@, qr/alpha without decimal/,
109 "Invalid version format (alpha without decimal)");
110
111 # for this first test, just upgrade the warn() to die()
112 eval {
113 local $SIG{__WARN__} = sub { die $_[0] };
114 $version = $CLASS->new("1.2b3");
115 };
116 my $warnregex = "Version string '.+' contains invalid data; ".
117 "ignoring: '.+'";
118
119 like($@, qr/$warnregex/,
120 "Version string contains invalid data; ignoring");
121
122 # from here on out capture the warning and test independently
f34c6aaf 123 {
317f7c8a
RGS
124 my $warning;
125 local $SIG{__WARN__} = sub { $warning = $_[0] };
126 $version = $CLASS->new("99 and 44/100 pure");
127
128 like($warning, qr/$warnregex/,
129 "Version string contains invalid data; ignoring");
8cb289bd 130 is ("$version", "99", '$version eq "99"');
317f7c8a
RGS
131 ok ($version->numify == 99.0, '$version->numify == 99.0');
132 ok ($version->normal eq "v99.0.0", '$version->normal eq v99.0.0');
133
134 $version = $CLASS->new("something");
135 like($warning, qr/$warnregex/,
136 "Version string contains invalid data; ignoring");
137 ok (defined $version, 'defined $version');
138
139 # reset the test object to something reasonable
140 $version = $CLASS->new("1.2.3");
141
142 # Test boolean operator
143 ok ($version, 'boolean');
144
145 # Test class membership
146 isa_ok ( $version, $CLASS );
147
148 # Test comparison operators with self
149 diag "tests with self" if $Verbose;
8cb289bd 150 is ( $version <=> $version, 0, '$version <=> $version == 0' );
317f7c8a
RGS
151 ok ( $version == $version, '$version == $version' );
152
317f7c8a
RGS
153 # Test Numeric Comparison operators
154 # test first with non-object
8cb289bd 155 $version = $CLASS->new("5.006.001");
317f7c8a
RGS
156 $new_version = "5.8.0";
157 diag "numeric tests with non-objects" if $Verbose;
158 ok ( $version == $version, '$version == $version' );
159 ok ( $version < $new_version, '$version < $new_version' );
160 ok ( $new_version > $version, '$new_version > $version' );
161 ok ( $version != $new_version, '$version != $new_version' );
162
163 # now test with existing object
164 $new_version = $CLASS->new($new_version);
165 diag "numeric tests with objects" if $Verbose;
166 ok ( $version < $new_version, '$version < $new_version' );
167 ok ( $new_version > $version, '$new_version > $version' );
168 ok ( $version != $new_version, '$version != $new_version' );
169
170 # now test with actual numbers
171 diag "numeric tests with numbers" if $Verbose;
172 ok ( $version->numify() == 5.006001, '$version->numify() == 5.006001' );
173 ok ( $version->numify() <= 5.006001, '$version->numify() <= 5.006001' );
174 ok ( $version->numify() < 5.008, '$version->numify() < 5.008' );
175 #ok ( $version->numify() > v5.005_02, '$version->numify() > 5.005_02' );
176
177 # test with long decimals
178 diag "Tests with extended decimal versions" if $Verbose;
179 $version = $CLASS->new(1.002003);
8cb289bd 180 ok ( $version == "1.2.3", '$version == "1.2.3"');
317f7c8a
RGS
181 ok ( $version->numify == 1.002003, '$version->numify == 1.002003');
182 $version = $CLASS->new("2002.09.30.1");
8cb289bd 183 ok ( $version == "2002.9.30.1",'$version == 2002.9.30.1');
317f7c8a
RGS
184 ok ( $version->numify == 2002.009030001,
185 '$version->numify == 2002.009030001');
186
187 # now test with alpha version form with string
188 $version = $CLASS->new("1.2.3");
189 $new_version = "1.2.3_4";
8cb289bd
RGS
190 diag "numeric tests with alpha-style non-objects" if $Verbose;
191 ok ( $version < $new_version, '$version < $new_version' );
192 ok ( $new_version > $version, '$new_version > $version' );
193 ok ( $version != $new_version, '$version != $new_version' );
317f7c8a
RGS
194
195 $version = $CLASS->new("1.2.4");
196 diag "numeric tests with alpha-style non-objects"
197 if $Verbose;
198 ok ( $version > $new_version, '$version > $new_version' );
199 ok ( $new_version < $version, '$new_version < $version' );
200 ok ( $version != $new_version, '$version != $new_version' );
201
202 # now test with alpha version form with object
203 $version = $CLASS->new("1.2.3");
204 $new_version = $CLASS->new("1.2.3_4");
205 diag "tests with alpha-style objects" if $Verbose;
206 ok ( $version < $new_version, '$version < $new_version' );
207 ok ( $new_version > $version, '$new_version > $version' );
208 ok ( $version != $new_version, '$version != $new_version' );
209 ok ( !$version->is_alpha, '!$version->is_alpha');
210 ok ( $new_version->is_alpha, '$new_version->is_alpha');
211
212 $version = $CLASS->new("1.2.4");
213 diag "tests with alpha-style objects" if $Verbose;
214 ok ( $version > $new_version, '$version > $new_version' );
215 ok ( $new_version < $version, '$new_version < $version' );
216 ok ( $version != $new_version, '$version != $new_version' );
217
218 $version = $CLASS->new("1.2.3.4");
219 $new_version = $CLASS->new("1.2.3_4");
220 diag "tests with alpha-style objects with same subversion"
221 if $Verbose;
222 ok ( $version > $new_version, '$version > $new_version' );
223 ok ( $new_version < $version, '$new_version < $version' );
224 ok ( $version != $new_version, '$version != $new_version' );
225
226 diag "test implicit [in]equality" if $Verbose;
227 $version = $CLASS->new("v1.2.3");
228 $new_version = $CLASS->new("1.2.3.0");
229 ok ( $version == $new_version, '$version == $new_version' );
230 $new_version = $CLASS->new("1.2.3_0");
231 ok ( $version == $new_version, '$version == $new_version' );
232 $new_version = $CLASS->new("1.2.3.1");
233 ok ( $version < $new_version, '$version < $new_version' );
234 $new_version = $CLASS->new("1.2.3_1");
235 ok ( $version < $new_version, '$version < $new_version' );
236 $new_version = $CLASS->new("1.1.999");
237 ok ( $version > $new_version, '$version > $new_version' );
238
239 # that which is not expressly permitted is forbidden
240 diag "forbidden operations" if $Verbose;
241 ok ( !eval { ++$version }, "noop ++" );
242 ok ( !eval { --$version }, "noop --" );
243 ok ( !eval { $version/1 }, "noop /" );
244 ok ( !eval { $version*3 }, "noop *" );
245 ok ( !eval { abs($version) }, "noop abs" );
137d6fc0 246
c8a14fb6 247SKIP: {
317f7c8a
RGS
248 skip "version require'd instead of use'd, cannot test qv", 3
249 if defined $no_qv;
250 # test the qv() sub
251 diag "testing qv" if $Verbose;
252 $version = qv("1.2");
8cb289bd 253 is ( "$version", "v1.2", 'qv("1.2") == "1.2.0"' );
317f7c8a 254 $version = qv(1.2);
8cb289bd 255 is ( "$version", "v1.2", 'qv(1.2) == "1.2.0"' );
317f7c8a 256 isa_ok( qv('5.008'), $CLASS );
c8a14fb6 257}
137d6fc0 258
317f7c8a
RGS
259 # test creation from existing version object
260 diag "create new from existing version" if $Verbose;
261 ok (eval {$new_version = $CLASS->new($version)},
262 "new from existing object");
263 ok ($new_version == $version, "class->new($version) identical");
264 $new_version = $version->new();
265 isa_ok ($new_version, $CLASS );
8cb289bd 266 is ($new_version, "0", "version->new() doesn't clone");
317f7c8a 267 $new_version = $version->new("1.2.3");
8cb289bd 268 is ($new_version, "1.2.3" , '$version->new("1.2.3") works too');
317f7c8a
RGS
269
270 # test the CVS revision mode
271 diag "testing CVS Revision" if $Verbose;
272 $version = new $CLASS qw$Revision: 1.2$;
8cb289bd 273 ok ( $version == "1.2.0", 'qw$Revision: 1.2$ == 1.2.0' );
317f7c8a 274 $version = new $CLASS qw$Revision: 1.2.3.4$;
8cb289bd 275 ok ( $version == "1.2.3.4", 'qw$Revision: 1.2.3.4$ == 1.2.3.4' );
317f7c8a
RGS
276
277 # test the CPAN style reduced significant digit form
278 diag "testing CPAN-style versions" if $Verbose;
279 $version = $CLASS->new("1.23_01");
8cb289bd 280 is ( "$version" , "1.23_01", "CPAN-style alpha version" );
317f7c8a
RGS
281 ok ( $version > 1.23, "1.23_01 > 1.23");
282 ok ( $version < 1.24, "1.23_01 < 1.24");
283
284 # test reformed UNIVERSAL::VERSION
285 diag "Replacement UNIVERSAL::VERSION tests" if $Verbose;
f34c6aaf
JP
286
287 my $error_regex = $] < 5.006
288 ? 'version \d required'
289 : 'does not define \$...::VERSION';
317f7c8a 290
f34c6aaf
JP
291 {
292 open F, ">aaa.pm" or die "Cannot open aaa.pm: $!\n";
293 print F "package aaa;\n\$aaa::VERSION=0.58;\n1;\n";
294 close F;
295
8cb289bd 296 $version = 0.58;
f34c6aaf
JP
297 eval "use lib '.'; use aaa $version";
298 unlike($@, qr/aaa version $version/,
299 'Replacement eval works with exact version');
300
301 # test as class method
302 $new_version = "aaa"->VERSION;
8cb289bd 303 cmp_ok($new_version,'==',$version, "Called as class method");
8dd04980 304
f34c6aaf
JP
305 eval "print Completely::Unknown::Module->VERSION";
306 if ( $] < 5.008 ) {
307 unlike($@, qr/$error_regex/,
308 "Don't freak if the module doesn't even exist");
309 }
310 else {
311 unlike($@, qr/defines neither package nor VERSION/,
312 "Don't freak if the module doesn't even exist");
313 }
314
315 # this should fail even with old UNIVERSAL::VERSION
8cb289bd 316 $version += 0.01;
f34c6aaf
JP
317 eval "use lib '.'; use aaa $version";
318 like($@, qr/aaa version $version/,
319 'Replacement eval works with incremented version');
320
321 $version =~ s/0+$//; #convert to string and remove trailing 0's
322 chop($version); # shorten by 1 digit, should still succeed
323 eval "use lib '.'; use aaa $version";
324 unlike($@, qr/aaa version $version/,
325 'Replacement eval works with single digit');
326
327 # this would fail with old UNIVERSAL::VERSION
8cb289bd 328 $version += 0.1;
f34c6aaf
JP
329 eval "use lib '.'; use aaa $version";
330 like($@, qr/aaa version $version/,
331 'Replacement eval works with incremented digit');
332 unlink 'aaa.pm';
333 }
317f7c8a
RGS
334
335 { # dummy up some variously broken modules for testing
336 open F, ">xxx.pm" or die "Cannot open xxx.pm: $!\n";
337 print F "1;\n";
338 close F;
f34c6aaf
JP
339
340 eval "use lib '.'; use xxx 3;";
317f7c8a 341 if ( $] < 5.008 ) {
f34c6aaf
JP
342 like($@, qr/$error_regex/,
343 'Replacement handles modules without package or VERSION');
c8a14fb6 344 }
317f7c8a 345 else {
f34c6aaf
JP
346 like($@, qr/defines neither package nor VERSION/,
347 'Replacement handles modules without package or VERSION');
c8a14fb6 348 }
f34c6aaf 349 eval "use lib '.'; use xxx; \$version = xxx->VERSION";
317f7c8a
RGS
350 unlike ($@, qr/$error_regex/,
351 'Replacement handles modules without package or VERSION');
f34c6aaf 352 ok (!defined($version), "Called as class method");
317f7c8a
RGS
353 unlink 'xxx.pm';
354 }
355
356 { # dummy up some variously broken modules for testing
357 open F, ">yyy.pm" or die "Cannot open yyy.pm: $!\n";
358 print F "package yyy;\n#look ma no VERSION\n1;\n";
359 close F;
360 eval "use lib '.'; use yyy 3;";
f34c6aaf 361 like ($@, qr/$error_regex/,
317f7c8a
RGS
362 'Replacement handles modules without VERSION');
363 eval "use lib '.'; use yyy; print yyy->VERSION";
f34c6aaf 364 unlike ($@, qr/$error_regex/,
317f7c8a
RGS
365 'Replacement handles modules without VERSION');
366 unlink 'yyy.pm';
367 }
368
369 { # dummy up some variously broken modules for testing
370 open F, ">zzz.pm" or die "Cannot open zzz.pm: $!\n";
371 print F "package zzz;\n\@VERSION = ();\n1;\n";
372 close F;
373 eval "use lib '.'; use zzz 3;";
f34c6aaf 374 like ($@, qr/$error_regex/,
317f7c8a
RGS
375 'Replacement handles modules without VERSION');
376 eval "use lib '.'; use zzz; print zzz->VERSION";
f34c6aaf 377 unlike ($@, qr/$error_regex/,
317f7c8a
RGS
378 'Replacement handles modules without VERSION');
379 unlink 'zzz.pm';
380 }
381
137d6fc0 382SKIP: {
ac0e6a2f
RGS
383 skip 'Cannot test bare v-strings with Perl < 5.6.0', 4
384 if $] < 5.006_000;
317f7c8a
RGS
385 diag "Tests with v-strings" if $Verbose;
386 $version = $CLASS->new(1.2.3);
8cb289bd 387 ok("$version" == "v1.2.3", '"$version" == 1.2.3');
317f7c8a
RGS
388 $version = $CLASS->new(1.0.0);
389 $new_version = $CLASS->new(1);
390 ok($version == $new_version, '$version == $new_version');
317f7c8a
RGS
391 skip "version require'd instead of use'd, cannot test qv", 1
392 if defined $no_qv;
393 $version = qv(1.2.3);
8cb289bd 394 ok("$version" == "v1.2.3", 'v-string initialized qv()');
317f7c8a
RGS
395 }
396
397 diag "Tests with real-world (malformed) data" if $Verbose;
398
399 # trailing zero testing (reported by Andreas Koenig).
400 $version = $CLASS->new("1");
401 ok($version->numify eq "1.000", "trailing zeros preserved");
402 $version = $CLASS->new("1.0");
403 ok($version->numify eq "1.000", "trailing zeros preserved");
404 $version = $CLASS->new("1.0.0");
405 ok($version->numify eq "1.000000", "trailing zeros preserved");
406 $version = $CLASS->new("1.0.0.0");
407 ok($version->numify eq "1.000000000", "trailing zeros preserved");
408
409 # leading zero testing (reported by Andreas Koenig).
410 $version = $CLASS->new(".7");
411 ok($version->numify eq "0.700", "leading zero inferred");
412
413 # leading space testing (reported by Andreas Koenig).
414 $version = $CLASS->new(" 1.7");
415 ok($version->numify eq "1.700", "leading space ignored");
416
417 # RT 19517 - deal with undef and 'undef' initialization
8cb289bd
RGS
418 ok("$version" ne 'undef', "Undef version comparison #1");
419 ok("$version" ne undef, "Undef version comparison #2");
317f7c8a
RGS
420 $version = $CLASS->new('undef');
421 unlike($warning, qr/^Version string 'undef' contains invalid data/,
422 "Version string 'undef'");
423
424 $version = $CLASS->new(undef);
425 like($warning, qr/^Use of uninitialized value/,
426 "Version string 'undef'");
8cb289bd
RGS
427 ok($version == 'undef', "Undef version comparison #3");
428 ok($version == undef, "Undef version comparison #4");
317f7c8a
RGS
429 eval "\$version = \$CLASS->new()"; # no parameter at all
430 unlike($@, qr/^Bizarre copy of CODE/, "No initializer at all");
8cb289bd
RGS
431 ok($version == 'undef', "Undef version comparison #5");
432 ok($version == undef, "Undef version comparison #6");
317f7c8a
RGS
433
434 $version = $CLASS->new(0.000001);
435 unlike($warning, qr/^Version string '1e-06' contains invalid data/,
436 "Very small version objects");
f34c6aaf 437 }
e0218a61 438
317f7c8a
RGS
439SKIP: {
440 # dummy up a legal module for testing RT#19017
441 open F, ">www.pm" or die "Cannot open www.pm: $!\n";
442 print F <<"EOF";
c8a14fb6
RGS
443package www;
444use version; \$VERSION = qv('0.0.4');
4451;
446EOF
317f7c8a
RGS
447 close F;
448
449 eval "use lib '.'; use www 0.000008;";
ac0e6a2f 450 like ($@, qr/^www version 0.000008 required/,
317f7c8a
RGS
451 "Make sure very small versions don't freak");
452 eval "use lib '.'; use www 1;";
8cb289bd 453 like ($@, qr/^www version 1 required/,
317f7c8a
RGS
454 "Comparing vs. version with no decimal");
455 eval "use lib '.'; use www 1.;";
8cb289bd 456 like ($@, qr/^www version 1 required/,
317f7c8a
RGS
457 "Comparing vs. version with decimal only");
458
ac0e6a2f 459 if ( $] < 5.006_000 ) {
d69f6151 460 unlink 'www.pm';
ac0e6a2f 461 skip 'Cannot "use" extended versions with Perl < 5.6.0', 3;
d69f6151 462 }
ac0e6a2f
RGS
463 eval "use lib '.'; use www v0.0.8;";
464 my $regex = "^www version v0.0.8 required";
465 like ($@, qr/$regex/, "Make sure very small versions don't freak");
317f7c8a 466
ac0e6a2f
RGS
467 $regex =~ s/8/4/; # set for second test
468 eval "use lib '.'; use www v0.0.4;";
469 unlike($@, qr/$regex/, 'Succeed - required == VERSION');
8cb289bd 470 cmp_ok ( "www"->VERSION, 'eq', '0.0.4', 'No undef warnings' );
317f7c8a
RGS
471
472 unlink 'www.pm';
473 }
474
475 open F, ">vvv.pm" or die "Cannot open vvv.pm: $!\n";
476 print F <<"EOF";
92dcf8ce
JP
477package vvv;
478use base qw(version);
4791;
480EOF
317f7c8a
RGS
481 close F;
482 # need to eliminate any other qv()'s
483 undef *main::qv;
484 ok(!defined(&{"main\::qv"}), "make sure we cleared qv() properly");
485 eval "use lib '.'; use vvv;";
486 ok(defined(&{"main\::qv"}), "make sure we exported qv() properly");
487 isa_ok( qv(1.2), "vvv");
488 unlink 'vvv.pm';
d69f6151
JP
489
490SKIP: {
ac0e6a2f
RGS
491 if ( $] < 5.006_000 ) {
492 skip 'Cannot "use" extended versions with Perl < 5.6.0', 3;
493 }
494 open F, ">uuu.pm" or die "Cannot open uuu.pm: $!\n";
495 print F <<"EOF";
496package uuu;
497\$VERSION = 1.0;
4981;
499EOF
500 close F;
501 eval "use lib '.'; use uuu 1.001;";
502 like ($@, qr/^uuu version 1.001 required/,
503 "User typed numeric so we error with numeric");
504 eval "use lib '.'; use uuu v1.1.0;";
505 like ($@, qr/^uuu version v1.1.0 required/,
506 "User typed extended so we error with extended");
507 unlink 'uuu.pm';
508 }
509
510SKIP: {
d69f6151 511 # test locale handling
f34c6aaf
JP
512 my $warning;
513 local $SIG{__WARN__} = sub { $warning = $_[0] };
d69f6151
JP
514 my $ver = 1.23; # has to be floating point number
515 my $loc;
516 while (<DATA>) {
517 chomp;
518 $loc = POSIX::setlocale( &POSIX::LC_ALL, $_);
519 last if POSIX::localeconv()->{decimal_point} eq ',';
520 }
521 skip 'Cannot test locale handling without a comma locale', 4
522 unless ( $loc and ($ver eq '1,23') );
523
524 diag ("Testing locale handling with $loc") if $Verbose;
525
526 my $v = $CLASS->new($ver);
527 unlike($warning,qr/Version string '1,23' contains invalid data/,
528 "Process locale-dependent floating point");
8cb289bd 529 is ($v, "1.23", "Locale doesn't apply to version objects");
d69f6151
JP
530 ok ($v == $ver, "Comparison to locale floating point");
531 }
f34c6aaf
JP
532
533 eval 'my $v = $CLASS->new("1._1");';
534 unlike($@, qr/^Invalid version format \(alpha with zero width\)/,
535 "Invalid version format 1._1");
ac0e6a2f 536
c812d146
JP
537 {
538 my $warning;
539 local $SIG{__WARN__} = sub { $warning = $_[0] };
540 eval 'my $v = $CLASS->new(~0);';
541 unlike($@, qr/Integer overflow in version/, "Too large version");
542 like($warning, qr/Integer overflow in version/, "Too large version");
543 }
544
72287d96
JP
545 {
546 # http://rt.cpan.org/Public/Bug/Display.html?id=30004
547 my $v1 = $CLASS->new("v0.1_1");
548 (my $alpha1 = Dumper($v1)) =~ s/.+'alpha' => ([^,]+),.+/$1/ms;
549 my $v2 = $CLASS->new($v1);
550 (my $alpha2 = Dumper($v2)) =~ s/.+'alpha' => ([^,]+),.+/$1/ms;
551 is $alpha2, $alpha1, "Don't fall for Data::Dumper's tricks";
552 }
553
554
137d6fc0 555}
cb5772bb
RGS
556
5571;
d69f6151
JP
558
559__DATA__
560af_ZA
561af_ZA.utf8
562an_ES
563an_ES.utf8
564az_AZ.utf8
565be_BY
566be_BY.utf8
567bg_BG
568bg_BG.utf8
569br_FR
570br_FR@euro
571br_FR.utf8
572bs_BA
573bs_BA.utf8
574ca_ES
575ca_ES@euro
576ca_ES.utf8
577cs_CZ
578cs_CZ.utf8
579da_DK
580da_DK.utf8
581de_AT
582de_AT@euro
583de_AT.utf8
584de_BE
585de_BE@euro
586de_BE.utf8
587de_DE
588de_DE@euro
589de_DE.utf8
590de_LU
591de_LU@euro
592de_LU.utf8
593el_GR
594el_GR.utf8
595en_DK
596en_DK.utf8
597es_AR
598es_AR.utf8
599es_BO
600es_BO.utf8
601es_CL
602es_CL.utf8
603es_CO
604es_CO.utf8
605es_EC
606es_EC.utf8
607es_ES
608es_ES@euro
609es_ES.utf8
610es_PY
611es_PY.utf8
612es_UY
613es_UY.utf8
614es_VE
615es_VE.utf8
616et_EE
617et_EE.iso885915
618et_EE.utf8
619eu_ES
620eu_ES@euro
621eu_ES.utf8
622fi_FI
623fi_FI@euro
624fi_FI.utf8
625fo_FO
626fo_FO.utf8
627fr_BE
628fr_BE@euro
629fr_BE.utf8
630fr_CA
631fr_CA.utf8
632fr_CH
633fr_CH.utf8
634fr_FR
635fr_FR@euro
636fr_FR.utf8
637fr_LU
638fr_LU@euro
639fr_LU.utf8
640gl_ES
641gl_ES@euro
642gl_ES.utf8
643hr_HR
644hr_HR.utf8
645hu_HU
646hu_HU.utf8
647id_ID
648id_ID.utf8
649is_IS
650is_IS.utf8
651it_CH
652it_CH.utf8
653it_IT
654it_IT@euro
655it_IT.utf8
656ka_GE
657ka_GE.utf8
658kk_KZ
659kk_KZ.utf8
660kl_GL
661kl_GL.utf8
662lt_LT
663lt_LT.utf8
664lv_LV
665lv_LV.utf8
666mk_MK
667mk_MK.utf8
668mn_MN
669mn_MN.utf8
670nb_NO
671nb_NO.utf8
672nl_BE
673nl_BE@euro
674nl_BE.utf8
675nl_NL
676nl_NL@euro
677nl_NL.utf8
678nn_NO
679nn_NO.utf8
680no_NO
681no_NO.utf8
682oc_FR
683oc_FR.utf8
684pl_PL
685pl_PL.utf8
686pt_BR
687pt_BR.utf8
688pt_PT
689pt_PT@euro
690pt_PT.utf8
691ro_RO
692ro_RO.utf8
693ru_RU
694ru_RU.koi8r
695ru_RU.utf8
696ru_UA
697ru_UA.utf8
698se_NO
699se_NO.utf8
700sh_YU
701sh_YU.utf8
702sk_SK
703sk_SK.utf8
704sl_SI
705sl_SI.utf8
706sq_AL
707sq_AL.utf8
708sr_CS
709sr_CS.utf8
710sv_FI
711sv_FI@euro
712sv_FI.utf8
713sv_SE
714sv_SE.iso885915
715sv_SE.utf8
716tg_TJ
717tg_TJ.utf8
718tr_TR
719tr_TR.utf8
720tt_RU.utf8
721uk_UA
722uk_UA.utf8
723vi_VN
724vi_VN.tcvn
725wa_BE
726wa_BE@euro
727wa_BE.utf8
728