From: Zefram Date: Thu, 20 May 2010 20:48:03 +0000 (+0100) Subject: fully test package-version-block syntax X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=36f77d7116441b32ff6c10307a116e105b7eabb4;p=p5sagit%2Fp5-mst-13.2.git fully test package-version-block syntax 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. --- diff --git a/t/op/packagev.t b/t/op/packagev.t index 8e8f19f..f4e094c 100644 --- a/t/op/packagev.t +++ b/t/op/packagev.t @@ -17,8 +17,8 @@ my @syntax_cases = ( my @version_cases = ; -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: