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