diff options
author | Michael G. Schwern <schwern@pobox.com> | 2010-09-13 19:14:54 -0700 |
---|---|---|
committer | Florian Ragwitz <rafl@debian.org> | 2010-09-15 18:59:41 +0200 |
commit | ad4e703e577a4db278c9a482f9057a9c9109c720 (patch) | |
tree | 21cf32804497fc7d9553407634f09d0f774e5da1 /t | |
parent | 92c9394b5f9cfe3b6e8bbe5ce3e20f92f1edefc1 (diff) | |
download | perl-ad4e703e577a4db278c9a482f9057a9c9109c720.tar.gz |
Add new_ok() to create and test objects. From Test::More.
Diffstat (limited to 't')
-rw-r--r-- | t/test.pl | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -788,6 +788,33 @@ sub can_ok ($@) { _ok( !@nok, _where(), $name ); } + +# Call $class->new( @$args ); and run the result through isa_ok. +# See Test::More::new_ok +sub new_ok { + my($class, $args, $obj_name) = @_; + $args ||= []; + $object_name = "The object" unless defined $obj_name; + + local $Level = $Level + 1; + + my $obj; + my $ok = eval { $obj = $class->new(@$args); 1 }; + my $error = $@; + + if($ok) { + isa_ok($obj, $class, $object_name); + } + else { + ok( 0, "new() died" ); + diag("Error was: $@"); + } + + return $obj; + +} + + sub isa_ok ($$;$) { my($object, $class, $obj_name) = @_; |