Add tests for strict constructors
gfx [Sat, 20 Feb 2010 05:41:20 +0000 (14:41 +0900)]
t/001_mouse/068-strict-constructor.t [new file with mode: 0644]

diff --git a/t/001_mouse/068-strict-constructor.t b/t/001_mouse/068-strict-constructor.t
new file mode 100644 (file)
index 0000000..801118c
--- /dev/null
@@ -0,0 +1,49 @@
+#!perl
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+{
+    package MyClass;
+    use Mouse;
+
+    has foo => (
+        is => 'rw',
+    );
+
+    has bar => (
+        is => 'rw',
+        init_arg => undef,
+    );
+
+    __PACKAGE__->meta->make_immutable(strict_constructor => 1);
+}
+
+lives_ok {
+    MyClass->new(foo => 1);
+};
+
+throws_ok {
+    MyClass->new(foo => 1, hoge => 42);
+} qr/\b hoge \b/xms;
+
+throws_ok {
+    MyClass->new(foo => 1, bar => 42);
+} qr/\b bar \b/xms, "init_arg => undef";
+
+
+throws_ok {
+    MyClass->new(aaa => 1, bbb => 2, ccc => 3);
+} qr/\b aaa \b/xms;
+
+throws_ok {
+    MyClass->new(aaa => 1, bbb => 2, ccc => 3);
+} qr/\b bbb \b/xms;
+
+throws_ok {
+    MyClass->new(aaa => 1, bbb => 2, ccc => 3);
+} qr/\b ccc \b/xms;
+
+done_testing;