Revert "convert all uses of Test::Exception to Test::Fatal."
[gitmo/Class-MOP.git] / t / 021_attribute_errors_and_edge_cases.t
index aad2a34..d00d4c3 100644 (file)
@@ -1,13 +1,11 @@
-#!/usr/bin/perl
-
 use strict;
 use warnings;
 
-use Test::More tests => 27;
+use Test::More;
 use Test::Exception;
 
-BEGIN {use Class::MOP;use Class::MOP::Attribute;
-}
+use Class::MOP;
+use Class::MOP::Attribute;
 
 # most values are static
 
@@ -83,6 +81,34 @@ BEGIN {use Class::MOP;use Class::MOP::Attribute;
         ));
     } '... no default AND builder';
 
+    my $undef_attr;
+    lives_ok {
+        $undef_attr = Class::MOP::Attribute->new('$test' => (
+            default   => undef,
+            predicate => 'has_test',
+        ));
+    } '... undef as a default is okay';
+    ok($undef_attr->has_default, '... and it counts as an actual default');
+    ok(!Class::MOP::Attribute->new('$test')->has_default,
+       '... but attributes with no default have no default');
+
+    Class::MOP::Class->create(
+        'Foo',
+        attributes => [$undef_attr],
+    );
+    {
+        my $obj = Foo->meta->new_object;
+        ok($obj->has_test, '... and the default is populated');
+        is($obj->meta->get_attribute('$test')->get_value($obj), undef, '... with the right value');
+    }
+    lives_ok { Foo->meta->make_immutable }
+             '... and it can be inlined';
+    {
+        my $obj = Foo->new;
+        ok($obj->has_test, '... and the default is populated');
+        is($obj->meta->get_attribute('$test')->get_value($obj), undef, '... with the right value');
+    }
+
 }
 
 
@@ -91,11 +117,12 @@ BEGIN {use Class::MOP;use Class::MOP::Attribute;
         Class::MOP::Attribute->new();
     } '... no name argument';
 
-    dies_ok {
+    # These are no longer errors
+    lives_ok {
         Class::MOP::Attribute->new('');
     } '... bad name argument';
 
-    dies_ok {
+    lives_ok {
         Class::MOP::Attribute->new(0);
     } '... bad name argument';
 }
@@ -131,7 +158,7 @@ BEGIN {use Class::MOP;use Class::MOP::Attribute;
     my $attr = Class::MOP::Attribute->new('$test');
 
     dies_ok {
-        $attr->process_accessors('fail', 'my_failing_sub');
+        $attr->_process_accessors('fail', 'my_failing_sub');
     } '... cannot find "fail" type generator';
 }
 
@@ -202,3 +229,5 @@ BEGIN {use Class::MOP;use Class::MOP::Attribute;
         ));
     } '... can create accessors with reader/writers';
 }
+
+done_testing;