.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
.    if \nF \{
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Template::Test 3"
.TH Template::Test 3 "2011-12-20" "perl v5.16.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Template::Test \- Module for automating TT2 test scripts
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&    use Template::Test;
\&   
\&    $Template::Test::DEBUG = 0;   # set this true to see each test running
\&    $Template::Test::EXTRA = 2;   # 2 extra tests follow test_expect()...
\&    
\&    # ok() can be called any number of times before test_expect
\&    ok( $true_or_false )
\&    
\&    # test_expect() splits $input into individual tests, processes each 
\&    # and compares generated output against expected output
\&    test_expect($input, $template, \e%replace );
\&    
\&    # $input is text or filehandle (e.g. DATA section after _\|_END_\|_)
\&    test_expect( $text );
\&    test_expect( \e*DATA );
\&    
\&    # $template is a Template object or configuration hash
\&    my $template_cfg = { ... };
\&    test_expect( $input, $template_cfg );
\&    my $template_obj = Template\->new($template_cfg);
\&    test_expect( $input, $template_obj );
\&    
\&    # $replace is a hash reference of template variables
\&    my $replace = {
\&        a => \*(Aqalpha\*(Aq,
\&        b => \*(Aqbravo\*(Aq
\&    };
\&    test_expect( $input, $template, $replace );
\&    
\&    # ok() called after test_expect should be declared in $EXTRA (2)
\&    ok( $true_or_false )   
\&    ok( $true_or_false )
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \f(CW\*(C`Template::Test\*(C'\fR module defines the \fItest_expect()\fR and other related
subroutines which can be used to automate test scripts for the
Template Toolkit.  See the numerous tests in the \fIt\fR sub-directory of
the distribution for examples of use.
.SH "PACKAGE SUBROUTINES"
.IX Header "PACKAGE SUBROUTINES"
.SS "\fItext_expect()\fP"
.IX Subsection "text_expect()"
The \f(CW\*(C`test_expect()\*(C'\fR subroutine splits an input document into a number
of separate tests, processes each one using the Template Toolkit and
then compares the generated output against an expected output, also
specified in the input document.  It generates the familiar 
\&\f(CW\*(C`ok\*(C'\fR/\f(CW\*(C`not ok\*(C'\fR output compatible with \f(CW\*(C`Test::Harness\*(C'\fR.
.PP
The test input should be specified as a text string or a reference to
a filehandle (e.g. \f(CW\*(C`GLOB\*(C'\fR or \f(CW\*(C`IO::Handle\*(C'\fR) from which it can be read.  In 
particular, this allows the test input to be placed after the \f(CW\*(C`_\|_END_\|_\*(C'\fR
marker and read via the \f(CW\*(C`DATA\*(C'\fR filehandle.
.PP
.Vb 1
\&    use Template::Test;
\&    
\&    test_expect(\e*DATA);
\&    
\&    _\|_END_\|_
\&    # this is the first test (this is a comment)
\&    \-\- test \-\-
\&    blah blah blah [% foo %]
\&    \-\- expect \-\-
\&    blah blah blah value_of_foo
\&    
\&    # here\*(Aqs the second test (no surprise, so is this)
\&    \-\- test \-\-
\&    more blah blah [% bar %]
\&    \-\- expect \-\-
\&    more blah blah value_of_bar
.Ve
.PP
Blank lines between test sections are generally ignored.  Any line starting
with \f(CW\*(C`#\*(C'\fR is treated as a comment and is ignored.
.PP
The second and third parameters to \f(CW\*(C`test_expect()\*(C'\fR are optional.  The second
may be either a reference to a Template object which should be used to 
process the template fragments, or a reference to a hash array containing
configuration values which should be used to instantiate a new Template
object.
.PP
.Vb 6
\&    # pass reference to config hash
\&    my $config = {
\&        INCLUDE_PATH => \*(Aq/here/there:/every/where\*(Aq,
\&        POST_CHOMP   => 1,
\&    };
\&    test_expect(\e*DATA, $config);
\&    
\&    # or create Template object explicitly
\&    my $template = Template\->new($config);
\&    test_expect(\e*DATA, $template);
.Ve
.PP
The third parameter may be used to reference a hash array of template
variable which should be defined when processing the tests.  This is
passed to the Template \fIprocess()\fR method.
.PP
.Vb 4
\&    my $replace = {
\&        a => \*(Aqalpha\*(Aq,
\&        b => \*(Aqbravo\*(Aq,
\&    };
\&    
\&    test_expect(\e*DATA, $config, $replace);
.Ve
.PP
The second parameter may be left undefined to specify a default Template
configuration.
.PP
.Vb 1
\&    test_expect(\e*DATA, undef, $replace);
.Ve
.PP
For testing the output of different Template configurations, a
reference to a list of named Template objects also may be passed as
the second parameter.
.PP
.Vb 3
\&    my $tt1 = Template\->new({ ... });
\&    my $tt2 = Template\->new({ ... });
\&    my @tts = [ one => $tt1, two => $tt1 ];
.Ve
.PP
The first object in the list is used by default.  Other objects may be 
switched in with a '\f(CW\*(C`\-\- use $name \-\-\*(C'\fR' marker.  This should immediately 
follow a '\f(CW\*(C`\-\- test \-\-\*(C'\fR' line.  That object will then be used for the rest 
of the test, or until a different object is selected.
.PP
.Vb 5
\&    \-\- test \-\-
\&    \-\- use one \-\-
\&    [% blah %]
\&    \-\- expect \-\-
\&    blah, blah
\&    
\&    \-\- test \-\-
\&    still using one...
\&    \-\- expect \-\-
\&    ...
\&    
\&    \-\- test \-\-
\&    \-\- use two \-\-
\&    [% blah %]
\&    \-\- expect \-\-
\&    blah, blah, more blah
.Ve
.PP
The \f(CW\*(C`test_expect()\*(C'\fR sub counts the number of tests, and then calls \fIntests()\fR 
to generate the familiar "\f(CW\*(C`1..$ntests\en\*(C'\fR" test harness line.  Each 
test defined generates two test numbers.  The first indicates 
that the input was processed without error, and the second that the 
output matches that expected.
.PP
Additional test may be run before \f(CW\*(C`test_expect()\*(C'\fR by calling \fIok()\fR. These
test results are cached until \fIntests()\fR is called and the final number of
tests can be calculated. Then, the "\f(CW\*(C`1..$ntests\*(C'\fR\*(L" line is output, along with
\&\*(R"\f(CW\*(C`ok $n\*(C'\fR\*(L" / \*(R"\f(CW\*(C`not ok $n\*(C'\fR" lines for each of the cached test result.
Subsequent calls to \fIok()\fR then generate an output line immediately.
.PP
.Vb 2
\&    my $something = SomeObject\->new();
\&    ok( $something );
\&    
\&    my $other = AnotherThing\->new();
\&    ok( $other );
\&    
\&    test_expect(\e*DATA);
.Ve
.PP
If any tests are to follow after \f(CW\*(C`test_expect()\*(C'\fR is called then these 
should be pre-declared by setting the \f(CW$EXTRA\fR package variable.  This
value (default: \f(CW0\fR) is added to the grand total calculated by \fIntests()\fR.
The results of the additional tests are also registered by calling \fIok()\fR.
.PP
.Vb 1
\&    $Template::Test::EXTRA = 2;
\&    
\&    # can call ok() any number of times before test_expect()
\&    ok( $did_that_work );             
\&    ok( $make_sure );
\&    ok( $dead_certain ); 
\&    
\&    # <some> number of tests...
\&    test_expect(\e*DATA, $config, $replace);
\&    
\&    # here\*(Aqs those $EXTRA tests
\&    ok( defined $some_result && ref $some_result eq \*(AqARRAY\*(Aq );
\&    ok( $some_result\->[0] eq \*(Aqsome expected value\*(Aq );
.Ve
.PP
If you don't want to call \f(CW\*(C`test_expect()\*(C'\fR at all then you can call
\&\f(CW\*(C`ntests($n)\*(C'\fR to declare the number of tests and generate the test 
header line.  After that, simply call \fIok()\fR for each test passing 
a true or false values to indicate that the test passed or failed.
.PP
.Vb 3
\&    ntests(2);
\&    ok(1);
\&    ok(0);
.Ve
.PP
If you're really lazy, you can just call \fIok()\fR and not bother declaring
the number of tests at all.  All tests results will be cached until the
end of the script and then printed in one go before the program exits.
.PP
.Vb 2
\&    ok( $x );
\&    ok( $y );
.Ve
.PP
You can identify only a specific part of the input file for testing
using the '\f(CW\*(C`\-\- start \-\-\*(C'\fR' and '\f(CW\*(C`\-\- stop \-\-\*(C'\fR' markers.  Anything before the 
first '\f(CW\*(C`\-\- start \-\-\*(C'\fR' is ignored, along with anything after the next 
\&'\f(CW\*(C`\-\- stop \-\-\*(C'\fR' marker.
.PP
.Vb 4
\&    \-\- test \-\-
\&    this is test 1 (not performed)
\&    \-\- expect \-\-
\&    this is test 1 (not performed)
\&    
\&    \-\- start \-\-
\&    
\&    \-\- test \-\-
\&    this is test 2
\&    \-\- expect \-\-
\&    this is test 2
\&        
\&    \-\- stop \-\-
\&    
\&    ...
.Ve
.SS "\fIntests()\fP"
.IX Subsection "ntests()"
Subroutine used to specify how many tests you're expecting to run.
.SS "ok($test)"
.IX Subsection "ok($test)"
Generates an "\f(CW\*(C`ok $n\*(C'\fR\*(L" or \*(R"\f(CW\*(C`not ok $n\*(C'\fR" message if \f(CW$test\fR is true or false.
.SS "not_ok($test)"
.IX Subsection "not_ok($test)"
The logical inverse of \fIok()\fR. Prints an "\f(CW\*(C`ok $n\*(C'\fR" message is \f(CW$test\fR is
\&\fIfalse\fR and vice-versa.
.SS "\fIcallsign()\fP"
.IX Subsection "callsign()"
For historical reasons and general utility, the module also defines a
\&\f(CW\*(C`callsign()\*(C'\fR subroutine which returns a hash mapping the letters \f(CW\*(C`a\*(C'\fR
to \f(CW\*(C`z\*(C'\fR to their phonetic alphabet equivalent (e.g. radio callsigns). 
This is used by many of the test scripts as a known source of variable values.
.PP
.Vb 1
\&    test_expect(\e*DATA, $config, callsign());
.Ve
.SS "\fIbanner()\fP"
.IX Subsection "banner()"
This subroutine prints a simple banner including any text passed as parameters.
The \f(CW$DEBUG\fR variable must be set for it to generate any output.
.PP
.Vb 1
\&    banner(\*(AqTesting something\-or\-other\*(Aq);
.Ve
.PP
example output:
.PP
.Vb 3
\&    #\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
\&    # Testing something\-or\-other (27 tests completed)
\&    #\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
.Ve
.SH "PACKAGE VARIABLES"
.IX Header "PACKAGE VARIABLES"
.ie n .SS "$DEBUG"
.el .SS "\f(CW$DEBUG\fP"
.IX Subsection "$DEBUG"
The \f(CW$DEBUG\fR package variable can be set to enable debugging mode.
.ie n .SS "$PRESERVE"
.el .SS "\f(CW$PRESERVE\fP"
.IX Subsection "$PRESERVE"
The \f(CW$PRESERVE\fR package variable can be set to stop the \fItest_expect()\fR
from converting newlines in the output and expected output into
the literal strings '\en'.
.SH "HISTORY"
.IX Header "HISTORY"
This module started its butt-ugly life as the \f(CW\*(C`t/texpect.pl\*(C'\fR script.  It
was cleaned up to became the \f(CW\*(C`Template::Test\*(C'\fR module some time around
version 0.29.  It underwent further cosmetic surgery for version 2.00
but still retains some remarkable rear-end resemblances.
.PP
Since then the \f(CW\*(C`Test::More\*(C'\fR and related modules have appeared on \s-1CPAN\s0
making this module mostly, but not entirely, redundant.
.ie n .SH "BUGS / KNOWN ""FEATURES"""
.el .SH "BUGS / KNOWN ``FEATURES''"
.IX Header "BUGS / KNOWN FEATURES"
Imports all methods by default.  This is generally a Bad Thing, but
this module is only used in test scripts (i.e. at build time) so a) we
don't really care and b) it saves typing.
.PP
The line splitter may be a bit dumb, especially if it sees lines like
\&\f(CW\*(C`\-\- this \-\-\*(C'\fR that aren't supposed to be special markers.  So don't do that.
.SH "AUTHOR"
.IX Header "AUTHOR"
Andy Wardley <abw@wardley.org> <http://wardley.org/>
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (C) 1996\-2007 Andy Wardley.  All Rights Reserved.
.PP
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Template
