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