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