[Templates-cvs] cvs commit: Template2/t stash-xs.t

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/01/30 13:33:47

  Modified:    t        stash-xs.t
  Log:
  * added tests for Dave Howorth's fix to make stash stricter about what
    it considers to be a missing object method.
  
  Revision  Changes    Path
  2.9       +55 -2     Template2/t/stash-xs.t
  
  Index: stash-xs.t
  ===================================================================
  RCS file: /template-toolkit/Template2/t/stash-xs.t,v
  retrieving revision 2.8
  retrieving revision 2.9
  diff -u -r2.8 -r2.9
  --- stash-xs.t	2006/01/29 11:38:55	2.8
  +++ stash-xs.t	2006/01/30 13:33:47	2.9
  @@ -13,7 +13,7 @@
   # This is free software; you can redistribute it and/or modify it
   # under the same terms as Perl itself.
   #
  -# $Id: stash-xs.t,v 2.8 2006/01/29 11:38:55 abw Exp $
  +# $Id: stash-xs.t,v 2.9 2006/01/30 13:33:47 abw Exp $
   #
   #========================================================================
   
  @@ -32,11 +32,37 @@
       skip_all('cannot load Template::Stash::XS');
   }
   
  +#------------------------------------------------------------------------
  +# define some simple objects for testing
  +#------------------------------------------------------------------------
  +
   package Buggy;
   sub new { bless {}, shift }
   sub croak { my $self = shift; die @_ }
  +
  +package ListObject;
  +
  +package HashObject;
  +
  +sub hello {
  +    my $self = shift;
  +    return "Hello $self->{ planet }";
  +}
  +
  +sub goodbye {
  +    my $self = shift;
  +    return $self->no_such_method();
  +}
  +
  +sub now_is_the_time_to_test_a_very_long_method_to_see_what_happens {
  +    my $self = shift;
  +    return $self->this_method_does_not_exist();
  +}
  +
  +
   package main;
   
  +
   my $count = 20;
   my $data = {
       foo => 10,
  @@ -52,7 +78,13 @@
       obj => bless({
           name => 'an object',
       }, 'AnObject'),
  -    listobj => bless([10, 20, 30], 'AListObject'),
  +    listobj => bless([10, 20, 30], 'ListObject'),
  +    hashobj => bless({ planet => 'World' }, 'HashObject'),
  +    clean   => sub {
  +        my $error = shift;
  +        $error =~ s/\s+at.*$//;
  +        return $error;
  +    },
       correct => sub { die @_ },
       buggy => Buggy->new(),
   };
  @@ -289,4 +321,25 @@
   -- expect --
   message: Hello World
   
  +# test Dave Howorth's patch (v2.15) which makes the stash more strict
  +# about what it considers to be a missing method error
  +
  +-- test --
  +[% hashobj.hello %]
  +-- expect --
  +Hello World
   
  +-- test --
  +[% TRY; hashobj.goodbye; CATCH; "ERROR: "; clean(error); END %]
  +-- expect --
  +ERROR: undef error - Can't locate object method "no_such_method" via package "HashObject"
  +
  +-- test --
  +[% TRY; 
  +    hashobj.now_is_the_time_to_test_a_very_long_method_to_see_what_happens;
  +   CATCH; 
  +     "ERROR: "; clean(error); 
  +   END 
  +%]
  +-- expect --
  +ERROR: undef error - Can't locate object method "this_method_does_not_exist" via package "HashObject"