1#============================================================= -*-perl-*- 2# 3# t/template.t 4# 5# Test the Template.pm module. Does nothing of any great importance 6# at the moment, but all of its options are tested in the various other 7# test scripts. 8# 9# Written by Andy Wardley <abw@kfs.org> 10# 11# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved. 12# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd. 13# 14# This is free software; you can redistribute it and/or modify it 15# under the same terms as Perl itself. 16# 17# $Id$ 18# 19#======================================================================== 20 21use strict; 22use lib qw( ./lib ../lib ); 23use Template; 24use Template::Test; 25 26my $out; 27my $dir = -d 't' ? 't/test' : 'test'; 28my $tt = Template->new({ 29 INCLUDE_PATH => "$dir/src:$dir/lib", 30 OUTPUT => \$out, 31}); 32 33ok( $tt ); 34ok( $tt->process('header') ); 35ok( $out ); 36 37$out = ''; 38ok( ! $tt->process('this_file_does_not_exist') ); 39my $error = $tt->error(); 40ok( $error->type() eq 'file' ); 41ok( $error->info() eq 'this_file_does_not_exist: not found' ); 42 43my @output; 44$tt->process('header', undef, \@output); 45ok(length($output[-1])); 46 47sub myout { 48 my $output = shift; 49 ok($output) 50} 51 52ok($tt->process('header', undef, \&myout)); 53 54$out = Myout->new(); 55 56ok($tt->process('header', undef, $out)); 57 58package Myout; 59use Template::Test; 60 61sub new { 62 my $proto = shift; 63 my $class = ref($proto) || $proto; 64 my $self = {}; 65 bless($self, $class); 66 return $self; 67} 68sub print { 69 my $output = shift; 70 ok($output); 71} 72