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