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