test that we can use the exact current strictures version
[p5sagit/strictures.git] / t / strictures.t
CommitLineData
967e00d7 1BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 }
5ab06a4d 2
9f180a36 3sub _eval { eval $_[0] }
4
5use strict;
6use warnings;
7use Test::More qw(no_plan);
8
967e00d7 9sub capture_hints {
b4f4fcfc 10 my $code = shift;
b4f4fcfc 11 $code .= q{
12 ;
9f180a36 13 my @h;
14 BEGIN { @h = ( $^H, ${^WARNING_BITS} ) }
15 @h;
b4f4fcfc 16 };
9f180a36 17 my ($hints, $warning_bits) = _eval $code or die $@;
18 # ignore lexicalized hints
19 $hints &= ~ 0x20000;
20 $warning_bits = unpack "H*", $warning_bits
21 if defined $warning_bits;
b4f4fcfc 22 return ($hints, $warning_bits);
967e00d7 23}
eae006ee 24
b4f4fcfc 25sub compare_hints {
26 my ($code_want, $code_got, $name) = @_;
27 my ($want_hints, $want_warnings) = capture_hints $code_want;
28 my ($hints, $warnings) = capture_hints $code_got;
29 is($hints, $want_hints, "Hints correct for $name");
30 is($warnings, $want_warnings, "Warnings correct for $name");
eae006ee 31}
32
b4f4fcfc 33compare_hints q{
eae006ee 34 use strict;
35 use warnings FATAL => 'all';
b4f4fcfc 36},
37q{
967e00d7 38 use strictures 1;
b4f4fcfc 39},
40 'version 1';
eae006ee 41
b4f4fcfc 42compare_hints q{
23c0b85d 43 use strict;
b4f4fcfc 44 use warnings 'all';
45 use warnings FATAL => @strictures::WARNING_CATEGORIES;
46 no warnings FATAL => @strictures::V2_NONFATAL;
47 use warnings @strictures::V2_NONFATAL;
48 no warnings @strictures::V2_DISABLE;
49},
50q{
23c0b85d 51 use strictures 2;
b4f4fcfc 52},
53 'version 2';
23c0b85d 54
91b5f6b6 55my $v;
56eval { $v = strictures->VERSION; 1 } or diag $@;
57is $v, $strictures::VERSION, '->VERSION returns version correctly';
58
3d4f7774 59my $next = int $strictures::VERSION + 1;
cd782762 60eval qq{ use strictures $next; };
18069754 61
cd782762 62like $@, qr/strictures version $next required/,
63 "Can't use strictures $next (this is version $v)";
a086d4e2 64
65eval qq{ use strictures $strictures::VERSION; };
66
67is $@, '',
68 "Can use current strictures version";