[Templates-cvs] cvs commit: TT3/t base.t
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 24 Mar 2004 14:16:40 +0000
cvs 04/03/24 14:16:40
Modified: t base.t
Log:
* more test to reflect Base.pm changes
Revision Changes Path
1.9 +81 -2 TT3/t/base.t
Index: base.t
===================================================================
RCS file: /template-toolkit/TT3/t/base.t,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- base.t 2004/03/23 10:46:46 1.8
+++ base.t 2004/03/24 14:16:40 1.9
@@ -9,7 +9,7 @@
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
-# $Id: base.t,v 1.8 2004/03/23 10:46:46 abw Exp $
+# $Id: base.t,v 1.9 2004/03/24 14:16:40 abw Exp $
#
#========================================================================
@@ -18,8 +18,9 @@
use lib qw( ./lib ../lib );
use Template::Base;
-use Test::More tests => 76;
+use Test::More tests => 97;
+# run with -d flag to enable debugging, e.g. perl base.t -d
$Template::Base::DEBUG = grep(/^--?d(ebug)?/, @ARGV);
my ($pkg, $obj);
@@ -315,6 +316,84 @@
ok( ! defined $dribble, 'no dribble object' );
like( $loader->error(), qr[^failed to load My/Dribble.pm: ],
'no dribble object error' );
+
+
+
+#------------------------------------------------------------------------
+# test the throw() method
+#------------------------------------------------------------------------
+
+$obj = Template::Base->new();
+eval { $obj->throw( wibble => 'wobble' ) };
+my $except = $@;
+ok( $except, 'thrown exception' );
+is( $except->type(), 'wibble', 'type is wibble' );
+is( $except->info(), 'wobble', 'info is wobble' );
+
+# test that throw() throws exceptions as they are
+eval { $obj->throw($except) };
+my $other = $@;
+ok( $other, 're-thrown exception' );
+is( $other->type(), 'wibble', 're-thrown type is wibble' );
+is( $other->info(), 'wobble', 're-thrown info is wobble' );
+is( $except, $other, 'one and the same' );
+
+
+#------------------------------------------------------------------------
+# test the throw option
+#------------------------------------------------------------------------
+
+$obj = Template::Base->new( throw => 'food' );
+eval { $obj->error('cheese ', 'roll') };
+$except = $@;
+ok( $except, 'thrown food exception' );
+is( $except->type(), 'food', 'type is food' );
+is( $except->info(), 'cheese roll', 'info is cheese roll' );
+
+
+#------------------------------------------------------------------------
+# test that the $THROW package variable has the same effect
+#------------------------------------------------------------------------
+
+package My::Thrower;
+use base qw( Template::Base );
+
+our $THROW = 'thrower';
+
+package My::Sub::Thrower;
+use base qw( My::Thrower );
+use vars qw( $THROW );
+
+*THROW = \$My::Thrower::THROW;
+
+package main;
+
+$obj = My::Thrower->new();
+eval { $obj->error('threw error') };
+$except = $@;
+ok( $except, 'thrown thrower exception' );
+is( $except->type(), 'thrower', 'type is thrower' );
+is( $except->info(), 'threw error', 'info is threw error' );
+
+$obj = My::Sub::Thrower->new();
+eval { $obj->error('threw sub-error') };
+$except = $@;
+ok( $except, 'thrown sub-thrower exception' );
+is( $except->type(), 'thrower', 'type is still thrower' );
+is( $except->info(), 'threw sub-error', 'info is threw sub-error' );
+
+$obj = My::Sub::Thrower->new( throw => undef );
+ok( ! defined $obj->error('sub error undef'), 'throw undef' );
+is( $obj->error(), 'sub error undef', 'got error() info' );
+
+$obj = My::Sub::Thrower->new( throw => 'frobless' );
+eval { $obj->error('threw frobless error') };
+$except = $@;
+ok( $except, 'thrown frobless exception' );
+is( $except->type(), 'frobless', 'type is frobless' );
+is( $except->info(), 'threw frobless error', 'info is threw frobless error' );
+
+
__END__