test array delegation edge cases
[gitmo/Moose.git] / t / 010_basics / 007_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 }
2fee26f1 25
26 no Moose;
27 undef $@;
28 eval '$foo = 5;';
29 ::ok(!$@, "... no error after no Moose");
30
31 {
32 my $warn;
33 local $SIG{__WARN__} = sub { $warn = $_[0] };
34
35 ::ok(!$warn, '... no warning yet');
36
37 eval 'my $bar = 1 + "hello"';
38
39 ::ok(!$warn, '... still no warning');
40 }
c235cd98 41}
42
43# and for roles ...
44{
45 package Bar;
46 use Moose::Role;
d03bd989 47
c235cd98 48 eval '$foo = 5;';
49 ::ok($@, '... got an error because strict is on');
50 ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
d03bd989 51
c235cd98 52 {
53 my $warn;
54 local $SIG{__WARN__} = sub { $warn = $_[0] };
55
56 ::ok(!$warn, '... no warning yet');
d03bd989 57
c235cd98 58 eval 'my $bar = 1 + "hello"';
d03bd989 59
c235cd98 60 ::ok($warn, '... got a warning');
61 ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
62 }
2fee26f1 63
64 no Moose::Role;
65 undef $@;
66 eval '$foo = 5;';
67 ::ok(!$@, "... no error after no Moose::Role");
68
69 {
70 my $warn;
71 local $SIG{__WARN__} = sub { $warn = $_[0] };
72
73 ::ok(!$warn, '... no warning yet');
74
75 eval 'my $bar = 1 + "hello"';
76
77 ::ok(!$warn, '... still no warning');
78 }
6fde788b 79}
80
81# and for exporters
82{
83 package Bar;
84 use Moose::Exporter;
85
2fee26f1 86 eval '$foo2 = 5;';
6fde788b 87 ::ok($@, '... got an error because strict is on');
2fee26f1 88 ::like($@, qr/Global symbol \"\$foo2\" requires explicit package name at/, '... got the right error');
6fde788b 89
90 {
91 my $warn;
92 local $SIG{__WARN__} = sub { $warn = $_[0] };
93
94 ::ok(!$warn, '... no warning yet');
95
96 eval 'my $bar = 1 + "hello"';
97
98 ::ok($warn, '... got a warning');
99 ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
100 }
2fee26f1 101
102 no Moose::Exporter;
103 undef $@;
104 eval '$foo = 5;';
105 ::ok(!$@, "... no error after no Moose::Exporter");
106
107 {
108 my $warn;
109 local $SIG{__WARN__} = sub { $warn = $_[0] };
110
111 ::ok(!$warn, '... no warning yet');
112
113 eval 'my $bar = 1 + "hello"';
114
115 ::ok(!$warn, '... still no warning');
116 }
6fde788b 117}
a28e50e4 118
119done_testing;