Commit | Line | Data |
967e00d7 |
1 | BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 } |
5ab06a4d |
2 | |
9f180a36 |
3 | sub _eval { eval $_[0] } |
4 | |
5 | use strict; |
6 | use warnings; |
7 | use Test::More qw(no_plan); |
8 | |
967e00d7 |
9 | sub 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 |
25 | sub 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 |
33 | compare_hints q{ |
eae006ee |
34 | use strict; |
35 | use warnings FATAL => 'all'; |
b4f4fcfc |
36 | }, |
37 | q{ |
967e00d7 |
38 | use strictures 1; |
b4f4fcfc |
39 | }, |
40 | 'version 1'; |
eae006ee |
41 | |
b4f4fcfc |
42 | compare_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 | }, |
50 | q{ |
23c0b85d |
51 | use strictures 2; |
b4f4fcfc |
52 | }, |
53 | 'version 2'; |
23c0b85d |
54 | |
91b5f6b6 |
55 | my $v; |
56 | eval { $v = strictures->VERSION; 1 } or diag $@; |
57 | is $v, $strictures::VERSION, '->VERSION returns version correctly'; |
58 | |
3d4f7774 |
59 | my $next = int $strictures::VERSION + 1; |
cd782762 |
60 | eval qq{ use strictures $next; }; |
18069754 |
61 | |
cd782762 |
62 | like $@, qr/strictures version $next required/, |
63 | "Can't use strictures $next (this is version $v)"; |
a086d4e2 |
64 | |
717b8bce |
65 | eval qq{ use strictures {version => $next}; }; |
66 | |
67 | like $@, qr/Major version specified as $next - not supported/, |
68 | "Can't use strictures version option $next (this is version $v)"; |
69 | |
70 | eval qq{ use strictures {version => undef}; }; |
71 | |
72 | like $@, qr/Major version specified as undef - not supported/, |
73 | "Can't use strictures version option undef"; |
74 | |
a086d4e2 |
75 | eval qq{ use strictures $strictures::VERSION; }; |
76 | |
77 | is $@, '', |
78 | "Can use current strictures version"; |