X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fconstructor.t;h=810f3f91f4e5768dc5260c9a43aff5ac435505cb;hb=e56ed5d5e92a228e5364ffe1478f9f8adbc2b557;hp=62e8d696f3b52a952bd68eb853a9ac0b89808301;hpb=4635347295081d0588159329d164b78260c6838d;p=gitmo%2FMooseX-UndefTolerant.git diff --git a/t/constructor.t b/t/constructor.t index 62e8d69..810f3f9 100644 --- a/t/constructor.t +++ b/t/constructor.t @@ -1,88 +1,15 @@ -use Test::More tests => 14; -use Test::Fatal; +use strict; +use warnings; -{ - package Foo; - use Moose; +use Test::More; +use Test::Moose; - has 'attr1' => ( - traits => [ qw(MooseX::UndefTolerant::Attribute)], - is => 'ro', - isa => 'Num', - predicate => 'has_attr1', - ); +use lib 't/lib'; +use ConstructorTests; - has 'attr2' => ( - is => 'ro', - isa => 'Num', - predicate => 'has_attr2', - ); -} +with_immutable { ConstructorTests::do_tests() } qw(Foo Bar); -{ - package Bar; - use Moose; - use MooseX::UndefTolerant; - - has 'attr1' => ( - is => 'ro', - isa => 'Num', - predicate => 'has_attr1', - ); - has 'attr2' => ( - is => 'ro', - isa => 'Num', - predicate => 'has_attr2', - ); -} - -package main; - -note 'Constructor behaviour'; -note ''; - -note 'Testing class with a single UndefTolerant attribute'; -{ - my $obj = Foo->new; - ok(!$obj->has_attr1, 'attr1 has no value before it is assigned'); - ok(!$obj->has_attr2, 'attr2 has no value before it is assigned'); -} - -{ - my $obj = Foo->new(attr1 => undef); - ok(!$obj->has_attr1, 'UT attr1 has no value when assigned undef in constructor'); - ok (exception { $obj = Foo->new(attr2 => undef) }, - 'But assigning undef to attr2 generates a type constraint error'); -} - -{ - my $obj = Foo->new(attr1 => 1234, attr2 => 5678); - is($obj->attr1, 1234, 'assigning a defined value during construction works as normal'); - ok($obj->has_attr1, '...and the predicate returns true as normal'); - is($obj->attr2, 5678, 'assigning a defined value during construction works as normal'); - ok($obj->has_attr2, '...and the predicate returns true as normal'); -} - - -note ''; -note 'Testing class with the entire class being UndefTolerant'; -{ - my $obj = Bar->new; - ok(!$obj->has_attr1, 'attr1 has no value before it is assigned'); -} - -{ - my $obj = Bar->new(attr1 => undef); - ok(!$obj->has_attr1, 'attr1 has no value when assigned undef in constructor'); - ok (!exception { $obj = Bar->new(attr2 => undef) }, - 'assigning undef to attr2 does not produce an error'); - ok(!$obj->has_attr2, 'attr2 has no value when assigned undef in constructor'); -} - -{ - my $obj = Bar->new(attr1 => 1234); - is($obj->attr1, 1234, 'assigning a defined value during construction works as normal'); - ok($obj->has_attr1, '...and the predicate returns true as normal'); -} +note 'Ran ', Test::More->builder->current_test, ' tests - should have run 56'; +done_testing;