Remove numbers from our tests
[gitmo/Moose.git] / t / basics / always_strict_warnings.t
diff --git a/t/basics/always_strict_warnings.t b/t/basics/always_strict_warnings.t
new file mode 100644 (file)
index 0000000..a10d94a
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# for classes ...
+{
+    package Foo;
+    use Moose;
+
+    eval '$foo = 5;';
+    ::ok($@, '... got an error because strict is on');
+    ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
+
+    {
+        my $warn;
+        local $SIG{__WARN__} = sub { $warn = $_[0] };
+
+        ::ok(!$warn, '... no warning yet');
+
+        eval 'my $bar = 1 + "hello"';
+
+        ::ok($warn, '... got a warning');
+        ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
+    }
+}
+
+# and for roles ...
+{
+    package Bar;
+    use Moose::Role;
+
+    eval '$foo = 5;';
+    ::ok($@, '... got an error because strict is on');
+    ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
+
+    {
+        my $warn;
+        local $SIG{__WARN__} = sub { $warn = $_[0] };
+
+        ::ok(!$warn, '... no warning yet');
+
+        eval 'my $bar = 1 + "hello"';
+
+        ::ok($warn, '... got a warning');
+        ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
+    }
+}
+
+# and for exporters
+{
+    package Bar;
+    use Moose::Exporter;
+
+    eval '$foo = 5;';
+    ::ok($@, '... got an error because strict is on');
+    ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
+
+    {
+        my $warn;
+        local $SIG{__WARN__} = sub { $warn = $_[0] };
+
+        ::ok(!$warn, '... no warning yet');
+
+        eval 'my $bar = 1 + "hello"';
+
+        ::ok($warn, '... got a warning');
+        ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
+    }
+}
+
+done_testing;