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