use strictures 1;
use Test::More;
-use Test::Exception;
-
-use Moo::HandleMoose;
+use Test::Fatal;
{
package FrewWithIsa;
package Bar;
use Moose;
with 'FrewWithIsa';
+
+ package OffByOne;
+ use Moo::Role;
+
+ has off_by_one => (is => 'rw', coerce => sub { $_[0] + 1 });
+
+ package Baz;
+ use Moo;
+
+ with 'OffByOne';
+
+ package Quux;
+ use Moose;
+
+ with 'OffByOne';
+
+ __PACKAGE__->meta->make_immutable;
}
-lives_ok {
+is(exception {
Bar->new(frooh => 1, frew => 1);
-} 'creation of valid Bar';
+}, undef, 'creation of valid Bar');
-dies_ok {
+ok exception {
Bar->new(frooh => 'silly', frew => 1);
-} 'creation of invalid Bar validated by coderef';
+}, 'creation of invalid Bar validated by coderef';
-dies_ok {
+ok exception {
Bar->new(frooh => 1, frew => 'goose');
-} 'creation of invalid Bar validated by quoted sub';
+}, 'creation of invalid Bar validated by quoted sub';
+
+sub test_off_by_one {
+ my ($class, $type) = @_;
+
+ my $obo = $class->new(off_by_one => 1);
+
+ is($obo->off_by_one, 2, "Off by one (new) ($type)");
+
+ $obo->off_by_one(41);
+
+ is($obo->off_by_one, 42, "Off by one (set) ($type)");
+}
+
+test_off_by_one('Baz', 'Moo');
+test_off_by_one('Quux', 'Moose');
done_testing;