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

cvs@template-toolkit.org cvs@template-toolkit.org
Fri, 26 Mar 2004 10:54:16 +0000


cvs         04/03/26 10:54:16

  Added:       t        compilers.t
  Log:
  * added tests for Template::Compilers
  
  Revision  Changes    Path
  1.1                  TT3/t/compilers.t
  
  Index: compilers.t
  ===================================================================
  #============================================================= -*-perl-*-
  #
  # t/compilers.t
  #
  # Test the Template::Compilers.pm module.
  #
  # Written by Andy Wardley <abw@wardley.org>
  #
  # This is free software; you can redistribute it and/or modify it
  # under the same terms as Perl itself.
  #
  # $Id: compilers.t,v 1.1 2004/03/26 10:54:16 abw Exp $
  #
  #========================================================================
  
  use strict;
  use warnings;
  
  use lib qw( ./lib ../lib );
  use Template::Compilers;
  use Test::More tests => 9;
  
  my $DEBUG = 
  $Template::Compilers::DEBUG = 
  grep(/^--?d(ebug)?/, @ARGV);
  
  
  #------------------------------------------------------------------------
  # package method
  #------------------------------------------------------------------------
  
  my $tt2 = Template::Compilers->get('tt2');
  ok( $tt2, 'got tt2 compiler from class' );
  ok( UNIVERSAL::isa($tt2, 'Template::TT2::Compiler'), 
      'class: ' . ref $tt2 );
  
  # TT3 compiler is broken - oh the shame!
  #my $tt3 = Template::Compilers->get('tt3');
  #ok( $tt3, 'got tt3 compiler from class' );
  #ok( UNIVERSAL::isa($tt3, 'Template::TT3::Compiler'), 
  #    'class: ' . ref $tt3 );
  
  
  #------------------------------------------------------------------------
  # object method
  #------------------------------------------------------------------------
  
  my $compilers = Template::Compilers->new();
  $tt2 = $compilers->get('tt2');
  ok( $tt2, 'got tt2 compiler from object' );
  ok( UNIVERSAL::isa($tt2, 'Template::TT2::Compiler'), 
      'obj: ' . ref $tt2 );
  
  
  #------------------------------------------------------------------------
  # object method with extra compilers
  #------------------------------------------------------------------------
  
  $compilers = Template::Compilers->new({
      tt4 => 'Template::Exception', 
      tt5 => $tt2,
  });
  
  # this is actually an exception object, not a compiler, but it
  # doesn't really make any difference - it proves that we've 
  # specified a custom module and that argument are being passed 
  # to the new() constructor method
  
  my $tt4 = $compilers->get(tt4 => 'wibble', 'wobble');
  ok( UNIVERSAL::isa($tt4, 'Template::Exception'), 
      'got exception' );
  is( $tt4->type(), 'wibble', 'type wibble' );
  is( $tt4->info(), 'wobble', 'info wobble' );
  
  # now test that an existing object gets returned intact
  my $tt5 = $compilers->get('tt5');
  is( $tt2, $tt5, 'got compiler object' );
  
  
  #------------------------------------------------------------------------
  # test Template::Compilers as a compiler provider in a component 
  # framework
  #------------------------------------------------------------------------
  
  use Template::Component;
  
  $Template::Component::DEBUG = $DEBUG;
  
  my $component = Template::Component->new({
      name      => 'outer',
      compilers => Template::Compilers->new(),
  }) || die Template::Component->error();
  
  $tt2 = $component->compiler('tt2') || die $component->error();
  ok( $tt2, 'got tt2 compiler');
  
  __END__
  
  # Local Variables:
  # mode: perl
  # perl-indent-level: 4
  # indent-tabs-mode: nil
  # End:
  #
  # vim: expandtab shiftwidth=4: