fully test package-version-block syntax
authorZefram <zefram@fysh.org>
Thu, 20 May 2010 20:48:03 +0000 (21:48 +0100)
committerDavid Golden <dagolden@cpan.org>
Thu, 20 May 2010 22:56:11 +0000 (18:56 -0400)
Extend the exhaustive package-version tests in t/op/packagev.t
to test each case using package-block syntax in addition to the
package-declaration syntax.

t/op/packagev.t

index 8e8f19f..f4e094c 100644 (file)
@@ -17,8 +17,8 @@ my @syntax_cases = (
 
 my @version_cases = <DATA>;
 
-plan tests => 5 * @syntax_cases + 5 * (grep { $_ !~ /^#/ } @version_cases)
-            + 3;
+plan tests => 7 * @syntax_cases + 7 * (grep { $_ !~ /^#/ } @version_cases)
+            + 2 * 3;
 
 use warnings qw/syntax/;
 use version;
@@ -34,6 +34,10 @@ for my $string ( @syntax_cases ) {
     is( $@, '', qq/eval "{$string}"/ );
     eval "{ $string }";
     is( $@, '', qq/eval "{ $string }"/ );
+    eval "${string}{}";
+    is( $@, '', qq/eval "${string}{}"/ );
+    eval "$string {}";
+    is( $@, '', qq/eval "$string {}"/ );
 }
 
 LINE:
@@ -52,20 +56,21 @@ for my $line (@version_cases) {
     $match =~ s/\s*\z//; # kill trailing spaces
 
     # First handle the 'package NAME VERSION' case
-    $withversion::VERSION = undef;
-    if ($package eq 'fail') {
-       eval "package withversion $v";
-       like($@, qr/$match/, "package withversion $v -> syntax error ($match)");
-       ok(! version::is_strict($v), qq{... and "$v" should also fail STRICT regex});
-    }
-    else {
-       my $ok = eval "package withversion $v; $v eq \$withversion::VERSION";
-       ok($ok, "package withversion $v")
-          or diag( $@ ? $@ : "and \$VERSION = $withversion::VERSION");
-       ok( version::is_strict($v), qq{... and "$v" should pass STRICT regex});
+    foreach my $suffix (";", "{}") {
+       $withversion::VERSION = undef;
+       if ($package eq 'fail') {
+           eval "package withversion $v$suffix";
+           like($@, qr/$match/, "package withversion $v$suffix -> syntax error ($match)");
+           ok(! version::is_strict($v), qq{... and "$v" should also fail STRICT regex});
+       }
+       else {
+           my $ok = eval "package withversion $v$suffix $v eq \$withversion::VERSION";
+           ok($ok, "package withversion $v$suffix")
+             or diag( $@ ? $@ : "and \$VERSION = $withversion::VERSION");
+           ok( version::is_strict($v), qq{... and "$v" should pass STRICT regex});
+       }
     }
 
-
     # Now check the version->new("V") case
     my $ver = undef;
     eval qq/\$ver = version->new("$v")/;
@@ -105,6 +110,8 @@ for my $line (@version_cases) {
 for my $v ("1", "1.23", "v1.2.3") {
     ok (run_perl (prog => "package Foo\n$v; print 1;"),
                           "New line between package name and version");
+    ok (run_perl (prog => "package Foo\n$v { print 1; }"),
+                          "New line between package name and version");
 }
 
 # The data is organized in tab delimited format with these columns: