X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstrictures.t;h=ad8ec108b5e5a2e73702d571b74a252dc9d63ab5;hb=3d4f7774b1c23f9e06a612d06e2b9683a884cc4c;hp=41d39a59fe8ba046909dfcb3c3aeb329300b9886;hpb=967e00d7d5e8094ad88b79db3c0ae7db9b55d473;p=p5sagit%2Fstrictures.git diff --git a/t/strictures.t b/t/strictures.t index 41d39a5..ad8ec10 100644 --- a/t/strictures.t +++ b/t/strictures.t @@ -1,37 +1,63 @@ BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 } -use Test::More qw(no_plan); +sub _eval { eval $_[0] } -our ($hints, $warning_bits); +use strict; +use warnings; +use Test::More qw(no_plan); sub capture_hints { + my $code = shift; + $code .= q{ + ; + my @h; + BEGIN { @h = ( $^H, ${^WARNING_BITS} ) } + @h; + }; + my ($hints, $warning_bits) = _eval $code or die $@; # ignore lexicalized hints - $hints = $^H & ~ 0x20000; - $warning_bits = defined ${^WARNING_BITS} ? (unpack "H*", ${^WARNING_BITS}) : undef; + $hints &= ~ 0x20000; + $warning_bits = unpack "H*", $warning_bits + if defined $warning_bits; + return ($hints, $warning_bits); } -sub test_hints { - my $name = shift; - my $want_hints = $hints; - my $want_bits = $warning_bits; - capture_hints; - is($hints, $want_hints, "Hints ok for $name"); - is($warning_bits, $want_bits, "Warnings ok for $name"); +sub compare_hints { + my ($code_want, $code_got, $name) = @_; + my ($want_hints, $want_warnings) = capture_hints $code_want; + my ($hints, $warnings) = capture_hints $code_got; + is($hints, $want_hints, "Hints correct for $name"); + is($warnings, $want_warnings, "Warnings correct for $name"); } -{ +compare_hints q{ use strict; use warnings FATAL => 'all'; - BEGIN { capture_hints } -} - -{ +}, +q{ use strictures 1; - BEGIN { test_hints "version 1" } -} +}, + 'version 1'; + +compare_hints q{ + use strict; + use warnings 'all'; + use warnings FATAL => @strictures::WARNING_CATEGORIES; + no warnings FATAL => @strictures::V2_NONFATAL; + use warnings @strictures::V2_NONFATAL; + no warnings @strictures::V2_DISABLE; +}, +q{ + use strictures 2; +}, + 'version 2'; my $v; eval { $v = strictures->VERSION; 1 } or diag $@; is $v, $strictures::VERSION, '->VERSION returns version correctly'; -ok(!eval q{use strictures 2; 1; }, "Can't use strictures 2 (this is version 1)"); +my $next = int $strictures::VERSION + 1; +eval qq{ use strictures $next; }; + +like $@, qr/strictures version $next required/, + "Can't use strictures $next (this is version $v)";