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