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