summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2010-09-13 19:14:54 -0700
committerFlorian Ragwitz <rafl@debian.org>2010-09-15 18:59:41 +0200
commitad4e703e577a4db278c9a482f9057a9c9109c720 (patch)
tree21cf32804497fc7d9553407634f09d0f774e5da1 /t
parent92c9394b5f9cfe3b6e8bbe5ce3e20f92f1edefc1 (diff)
downloadperl-ad4e703e577a4db278c9a482f9057a9c9109c720.tar.gz
Add new_ok() to create and test objects. From Test::More.
Diffstat (limited to 't')
-rw-r--r--t/test.pl27
1 files changed, 27 insertions, 0 deletions
diff --git a/t/test.pl b/t/test.pl
index 1d4a8cdb17..f26627d3c8 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -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) = @_;