X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F001_mouse%2F068-strict-constructor.t;fp=t%2F001_mouse%2F068-strict-constructor.t;h=801118c07fc63e655d73d99262d909c238c8e480;hp=0000000000000000000000000000000000000000;hb=29cb82b7c53a275a299076477c09d5cbe4f2d160;hpb=fc89f89b46e85a9c7d7930c57dcde75786234881 diff --git a/t/001_mouse/068-strict-constructor.t b/t/001_mouse/068-strict-constructor.t new file mode 100644 index 0000000..801118c --- /dev/null +++ b/t/001_mouse/068-strict-constructor.t @@ -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;