[Templates-cvs] cvs commit: TT3/t base.t

cvs@template-toolkit.org cvs@template-toolkit.org
Fri, 03 Dec 2004 10:05:42 +0000


cvs         04/12/03 10:05:42

  Modified:    t        base.t
  Log:
  * added tests for error_msg()
  
  Revision  Changes    Path
  1.13      +52 -2     TT3/t/base.t
  
  Index: base.t
  ===================================================================
  RCS file: /template-toolkit/TT3/t/base.t,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- base.t	2004/11/26 12:33:30	1.12
  +++ base.t	2004/12/03 10:05:42	1.13
  @@ -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.12 2004/11/26 12:33:30 abw Exp $
  +# $Id: base.t,v 1.13 2004/12/03 10:05:42 abw Exp $
   #
   #========================================================================
   
  @@ -18,7 +18,7 @@
   
   use lib qw( ./lib ../lib );
   use Template::Base;
  -use Template::Test tests => 106, import => qw( like );
  +use Template::Test tests => 116, import => qw( like );
   
   
   # run with -d flag to enable debugging, e.g. perl base.t -d
  @@ -422,6 +422,56 @@
   eval { $base->throw( propulsion => $ee ) };
   is( "$@", 'propulsion error - engine error - warp drive offline', 
       'propulsion system is NFG' );
  +
  +
  +
  +#------------------------------------------------------------------------
  +# error_msg()
  +#------------------------------------------------------------------------
  +
  +package My::Base;
  +use base qw( Template::Base );
  +
  +our $ERRORS = {
  +    no_pony  => 'Missing pony! (got "%s")',
  +    no_buffy => 'Missing Buffy! (got %s and %s)',
  +};
  +
  +package main;
  +
  +$base = My::Base->new();
  +
  +ok( ! defined $base->error_msg( no_pony => 'donkey' ), 'pony error' );
  +is( $base->error(), 'Missing pony! (got "donkey")', 'no pony!' );
  +
  +ok( ! defined $base->error_msg( no_buffy => 'Angel', 'Willow' ), 'Buffy error' );
  +is( $base->error(), 'Missing Buffy! (got Angel and Willow)', 'no Buffy!' );
  +
  +
  +#------------------------------------------------------------------------
  +# error_msg() with subclass
  +#------------------------------------------------------------------------
  +
  +package My::Sub;
  +use base qw( My::Base );
  +
  +our $ERRORS = {
  +    no_buffy => 'Buffy still missing! (%s is here)',
  +    no_angel => 'Angel is slain! (by %s)',
  +};
  +
  +package main;
  +
  +my $sub = My::Sub->new();
  +
  +ok( ! defined $sub->error_msg( no_pony => 'ass' ), 'ass error' );
  +is( $sub->error(), 'Missing pony! (got "ass")', 'still no pony!' );
  +
  +ok( ! defined $sub->error_msg( no_buffy => 'Giles' ), 'Giles error' );
  +is( $sub->error(), 'Buffy still missing! (Giles is here)', 'still no Buffy!' );
  +
  +ok( ! defined $sub->error_msg( no_angel => 'Buffy' ), 'Angel error' );
  +is( $sub->error(), 'Angel is slain! (by Buffy)', 'Angle is slain!' );
   
   
   #------------------------------------------------------------------------