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