Redid conversion to Test::Fatal
[gitmo/Moose.git] / t / 070_native_traits / 060_trait_number.t
index ddb8f4e..acf4551 100644 (file)
@@ -3,9 +3,12 @@
 use strict;
 use warnings;
 
+use lib 't/lib';
+
 use Moose ();
 use Moose::Util::TypeConstraints;
-use Test::Exception;
+use NoInlineAttribute;
+use Test::Fatal;
 use Test::More;
 use Test::Moose;
 
@@ -34,9 +37,13 @@ use Test::Moose;
             superclasses => ['Moose::Object'],
         );
 
+        my @traits = 'Number';
+        push @traits, 'NoInlineAttribute'
+            if delete $attr{no_inline};
+
         $class->add_attribute(
             integer => (
-                traits  => ['Number'],
+                traits  => \@traits,
                 is      => 'ro',
                 isa     => 'Int',
                 default => 5,
@@ -53,6 +60,8 @@ use Test::Moose;
 {
     run_tests(build_class);
     run_tests( build_class( lazy => 1 ) );
+    run_tests( build_class( trigger => sub { } ) );
+    run_tests( build_class( no_inline => 1 ) );
 
     # Will force the inlining code to check the entire hashref when it is modified.
     subtype 'MyInt', as 'Int', where { 1 };
@@ -74,53 +83,41 @@ sub run_tests {
 
         is( $obj->integer, 5, 'Default to five' );
 
-        $obj->add(10);
+        is( $obj->add(10), 15, 'add returns new value' );
 
         is( $obj->integer, 15, 'Add ten for fithteen' );
 
-        throws_ok { $obj->add( 10, 2 ) }
-        qr/Cannot call add with more than 1 argument/,
-            'add throws an error when 2 arguments are passed';
+        like( exception { $obj->add( 10, 2 ) }, qr/Cannot call add with more than 1 argument/, 'add throws an error when 2 arguments are passed' );
 
-        $obj->sub(3);
+        is( $obj->sub(3), 12, 'sub returns new value' );
 
         is( $obj->integer, 12, 'Subtract three for 12' );
 
-        throws_ok { $obj->sub( 10, 2 ) }
-        qr/Cannot call sub with more than 1 argument/,
-            'sub throws an error when 2 arguments are passed';
+        like( exception { $obj->sub( 10, 2 ) }, qr/Cannot call sub with more than 1 argument/, 'sub throws an error when 2 arguments are passed' );
 
-        $obj->set(10);
+        is( $obj->set(10), 10, 'set returns new value' );
 
         is( $obj->integer, 10, 'Set to ten' );
 
-        throws_ok { $obj->set( 10, 2 ) }
-        qr/Cannot call set with more than 1 argument/,
-            'set throws an error when 2 arguments are passed';
+        like( exception { $obj->set( 10, 2 ) }, qr/Cannot call set with more than 1 argument/, 'set throws an error when 2 arguments are passed' );
 
-        $obj->div(2);
+        is( $obj->div(2), 5, 'div returns new value' );
 
         is( $obj->integer, 5, 'divide by 2' );
 
-        throws_ok { $obj->div( 10, 2 ) }
-        qr/Cannot call div with more than 1 argument/,
-            'div throws an error when 2 arguments are passed';
+        like( exception { $obj->div( 10, 2 ) }, qr/Cannot call div with more than 1 argument/, 'div throws an error when 2 arguments are passed' );
 
-        $obj->mul(2);
+        is( $obj->mul(2), 10, 'mul returns new value' );
 
         is( $obj->integer, 10, 'multiplied by 2' );
 
-        throws_ok { $obj->mul( 10, 2 ) }
-        qr/Cannot call mul with more than 1 argument/,
-            'mul throws an error when 2 arguments are passed';
+        like( exception { $obj->mul( 10, 2 ) }, qr/Cannot call mul with more than 1 argument/, 'mul throws an error when 2 arguments are passed' );
 
-        $obj->mod(2);
+        is( $obj->mod(2), 0, 'mod returns new value' );
 
         is( $obj->integer, 0, 'Mod by 2' );
 
-        throws_ok { $obj->mod( 10, 2 ) }
-        qr/Cannot call mod with more than 1 argument/,
-            'mod throws an error when 2 arguments are passed';
+        like( exception { $obj->mod( 10, 2 ) }, qr/Cannot call mod with more than 1 argument/, 'mod throws an error when 2 arguments are passed' );
 
         $obj->set(7);
 
@@ -130,11 +127,9 @@ sub run_tests {
 
         $obj->set(-1);
 
-        $obj->abs;
+        is( $obj->abs, 1, 'abs returns new value' );
 
-        throws_ok { $obj->abs(10) }
-        qr/Cannot call abs with any arguments/,
-            'abs throws an error when an argument is passed';
+        like( exception { $obj->abs(10) }, qr/Cannot call abs with any arguments/, 'abs throws an error when an argument is passed' );
 
         is( $obj->integer, 1, 'abs 1' );