Remove duplicate entries from MANIFEST
[p5sagit/p5-mst-13.2.git] / t / op / packagev.t
CommitLineData
91152fc1 1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9# XXX remove this later -- dagolden, 2010-01-13
10# local *STDERR = *STDOUT;
11
12my @syntax_cases = (
13 'package Foo',
14 'package Bar 1.23',
15 'package Baz v1.2.3',
16);
17
18my @version_cases = <DATA>;
19
20plan tests => 5 * @syntax_cases + 5 * grep { $_ !~ /^#/ } @version_cases;
21
22use warnings qw/syntax/;
23use version;
24
25for my $string ( @syntax_cases ) {
26 eval "$string";
27 is( $@, '', qq/eval "$string"/ );
28 eval "$string;";
29 is( $@, '', qq/eval "$string;"/ );
30 eval "$string ;";
31 is( $@, '', qq/eval "$string ;"/ );
32 eval "{$string}";
33 is( $@, '', qq/eval "{$string}"/ );
34 eval "{ $string }";
35 is( $@, '', qq/eval "{ $string }"/ );
36}
37
38LINE:
39for my $line (@version_cases) {
40 chomp $line;
41 # comments in data section are just diagnostics
42 if ($line =~ /^#/) {
43 diag $line;
44 next LINE;
45 }
46
47 my ($v, $package, $quoted, $bare, $match) = split /\t+/, $line;
48 my $warning = "";
49 local $SIG{__WARN__} = sub { $warning .= $_[0] . "\n" };
50 $match = defined $match ? $match : "";
51 $match =~ s/\s*\z//; # kill trailing spaces
52
53 # First handle the 'package NAME VERSION' case
54 $withversion::VERSION = undef;
55 if ($package eq 'fail') {
56 eval "package withversion $v";
57 like($@, qr/$match/, "package withversion $v -> syntax error ($match)");
58 ok(! version::is_strict($v), qq{... and "$v" should also fail STRICT regex});
59 }
60 else {
61 my $ok = eval "package withversion $v; $v eq \$withversion::VERSION";
62 ok($ok, "package withversion $v")
63 or diag( $@ ? $@ : "and \$VERSION = $withversion::VERSION");
64 ok( version::is_strict($v), qq{... and "$v" should pass STRICT regex});
65 }
66
67
68 # Now check the version->new("V") case
69 my $ver = undef;
70 eval qq/\$ver = version->new("$v")/;
71 if ($quoted eq 'fail') {
72 like($@, qr/$match/, qq{version->new("$v") -> invalid format ($match)})
73 or diag( $@ ? $@ : "and \$ver = $ver" );
74 ok( ! version::is_lax($v), qq{... and "$v" should fail LAX regex});
75 }
76 else {
77 is($@, "", qq{version->new("$v")});
78 ok( version::is_lax($v), qq{... and "$v" should pass LAX regex});
79 }
80
81 # Now check the version->new(V) case, unless we're skipping it
82 if ( $bare eq 'na' ) {
83 pass( "... skipping version->new($v)" );
84 next LINE;
85 }
86 $ver = undef;
87 eval qq/\$ver = version->new($v)/;
88 if ($bare eq 'fail') {
89 like($@, qr/$match/m, qq{... and unquoted version->new($v) has same error})
90 or diag( $@ ? $@ : "and \$ver = $ver" );
91 }
92 else {
93 is($@, "", qq{... and version->new($v) is ok});
94 }
95}
96
97
98# The data is organized in tab delimited format with these columns:
99#
100# value package version->new version->new regex
101# quoted unquoted
102#
103# For each value, it is tested using eval in the following expressions
104#
105# package foo $value; # column 2
106# and
107# my $ver = version->new("$value"); # column 3
108# and
109# my $ver = version->new($value); # column 4
110#
111# The second through fourth columns can contain 'pass' or 'fail'.
112#
113# For any column with 'pass', the tests makes sure that no warning/error
114# was thrown. For any column with 'fail', the tests make sure that the
115# error thrown matches the regex in the last column. The unquoted column
116# may also have 'na' indicating that it's pointless to test as behavior
117# is subject to the perl parser before a stringifiable value is available
118# to version->new
119#
120# If all columns are marked 'pass', the regex column is left empty.
121#
122# there are multiple ways that underscores can fail depending on strict
123# vs lax format so these test do not distinguish between them
124#
125# If the DATA line begins with a # mark, it is used as a diag comment
126__DATA__
1271.00 pass pass pass
1281.00001 pass pass pass
1290.123 pass pass pass
13012.345 pass pass pass
13142 pass pass pass
1320 pass pass pass
1330.0 pass pass pass
134v1.2.3 pass pass pass
135v1.2.3.4 pass pass pass
136v0.1.2 pass pass pass
137v0.0.0 pass pass pass
13801 fail pass pass no leading zeros
13901.0203 fail pass pass no leading zeros
140v01 fail pass pass no leading zeros
141v01.02.03 fail pass pass no leading zeros
142.1 fail pass pass 0 before decimal required
143.1.2 fail pass pass 0 before decimal required
1441. fail pass pass fractional part required
1451.a fail fail na fractional part required
1461._ fail fail na fractional part required
1471.02_03 fail pass pass underscore
148v1.2_3 fail pass pass underscore
149v1.02_03 fail pass pass underscore
150v1.2_3_4 fail fail fail underscore
151v1.2_3.4 fail fail fail underscore
1521.2_3.4 fail fail fail underscore
1530_ fail fail na underscore
1541_ fail fail na underscore
1551_. fail fail na underscore
1561.1_ fail fail na underscore
1571.02_03_04 fail fail na underscore
1581.2.3 fail pass pass dotted-decimal versions must begin with 'v'
159v1.2 fail pass pass dotted-decimal versions require at least three parts
160v0 fail pass pass dotted-decimal versions require at least three parts
161v1 fail pass pass dotted-decimal versions require at least three parts
162v.1.2.3 fail fail na dotted-decimal versions require at least three parts
163v fail fail na dotted-decimal versions require at least three parts
164v1.2345.6 fail pass pass maximum 3 digits between decimals
165undef fail pass pass non-numeric data
1661a fail fail na non-numeric data
1671.2a3 fail fail na non-numeric data
168bar fail fail na non-numeric data
169_ fail fail na non-numeric data