From: gfx Date: Sat, 20 Feb 2010 05:41:20 +0000 (+0900) Subject: Add tests for strict constructors X-Git-Tag: 0.50_02~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=29cb82b7c53a275a299076477c09d5cbe4f2d160;hp=fc89f89b46e85a9c7d7930c57dcde75786234881 Add tests for strict constructors --- 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;