Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / basics / always_strict_warnings.t
CommitLineData
c235cd98 1#!/usr/bin/perl
2
a28e50e4 3use Test::More;
c235cd98 4
5# for classes ...
6{
7 package Foo;
8 use Moose;
d03bd989 9
c235cd98 10 eval '$foo = 5;';
11 ::ok($@, '... got an error because strict is on');
12 ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
d03bd989 13
c235cd98 14 {
15 my $warn;
16 local $SIG{__WARN__} = sub { $warn = $_[0] };
17
18 ::ok(!$warn, '... no warning yet');
d03bd989 19
c235cd98 20 eval 'my $bar = 1 + "hello"';
d03bd989 21
c235cd98 22 ::ok($warn, '... got a warning');
23 ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
24 }
25}
26
27# and for roles ...
28{
29 package Bar;
30 use Moose::Role;
d03bd989 31
c235cd98 32 eval '$foo = 5;';
33 ::ok($@, '... got an error because strict is on');
34 ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
d03bd989 35
c235cd98 36 {
37 my $warn;
38 local $SIG{__WARN__} = sub { $warn = $_[0] };
39
40 ::ok(!$warn, '... no warning yet');
d03bd989 41
c235cd98 42 eval 'my $bar = 1 + "hello"';
d03bd989 43
c235cd98 44 ::ok($warn, '... got a warning');
45 ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
46 }
6fde788b 47}
48
49# and for exporters
50{
51 package Bar;
52 use Moose::Exporter;
53
aee0741b 54 eval '$foo = 5;';
6fde788b 55 ::ok($@, '... got an error because strict is on');
aee0741b 56 ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
6fde788b 57
58 {
59 my $warn;
60 local $SIG{__WARN__} = sub { $warn = $_[0] };
61
62 ::ok(!$warn, '... no warning yet');
63
64 eval 'my $bar = 1 + "hello"';
65
66 ::ok($warn, '... got a warning');
67 ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
68 }
69}
a28e50e4 70
71done_testing;