<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML::Mason::Tests - Test harness for testing Mason</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">


<!-- INDEX BEGIN -->
<div name="index">
<p><A NAME="__index__"></a></p>

<ul>

	<li><A HREF="#name">NAME</a></li>
	<li><A HREF="#synopsis">SYNOPSIS</a></li>
	<li><A HREF="#description">DESCRIPTION</a></li>
	<li><A HREF="#methods">METHODS</a></li>
	<ul>

		<li><A HREF="#new">new</a></li>
		<li><A HREF="#add_support">add_support</a></li>
		<li><A HREF="#add_test">add_test</a></li>
		<li><A HREF="#run">run</a></li>
		<li><A HREF="#class_methods">Class methods</a></li>
		<li><A HREF="#base_path">base_path</a></li>
		<li><A HREF="#comp_root">comp_root</a></li>
		<li><A HREF="#data_dir">data_dir</a></li>
		<li><A HREF="#check_output___actual_____actual">check_output ( actual =&gt; $actual_output, expect =&gt; $expected_output )</a></li>
	</ul>

	<li><A HREF="#additional_run_modes">ADDITIONAL RUN MODES</a></li>
	<ul>

		<li><A HREF="#verbose_mode">Verbose mode</a></li>
		<li><A HREF="#debug_mode">Debug mode</a></li>
		<li><A HREF="#no_cleanup_mode">No cleanup mode</a></li>
		<li><A HREF="#create_mode">Create mode</a></li>
		<li><A HREF="#running_and_or_skipping_selected">Running and/or skipping selected tests</a></li>
		<li><A HREF="#subclassing_this_module">Subclassing this module</a></li>
	</ul>

	<li><A HREF="#see_also">SEE ALSO</a></li>
</ul>

<hr name="index" />
</div>
<!-- INDEX END -->

<p>
</p>
<h1><A NAME="name">NAME</a></h1>
<p>HTML::Mason::Tests - Test harness for testing Mason</p>
<p>
</p>
<hr />
<h1><A NAME="synopsis">SYNOPSIS</a></h1>
<pre>
 use HTML::Mason::Tests;</pre>
<pre>
 my $group = HTML::Mason::Tests-&gt;new( name =&gt; 'name of group', description =&gt; 'tests something' );
 $group-&gt;add_test( name =&gt; 'foo',
                   description =&gt; 'tests foo',
                   component =&gt; &lt;&lt;'EOF'
 &lt;%args&gt;
 $foo =&gt; 1
 &lt;/%args&gt;
 &lt;% $foo %&gt;
 EOF
                   expect =&gt; &lt;&lt;'EOF',
 1
 EOF
                 );</pre>
<pre>
 $group-&gt;run;</pre>
<p>
</p>
<hr />
<h1><A NAME="description">DESCRIPTION</a></h1>
<p>This module is designed to automate as much as possible of the Mason
test suite.  It does tasks like write component files to disk, call
them, compare the actual results to the expected results, and more.
In addition, it also is capable of printing out useful information
about test failures when run in verbose mode.  See the ADDITIONAL RUN
MODES section for more information.</p>
<p>It also makes sure that any given group of tests provides all the
information needed to run them (test names, components and results,
etc.).</p>
<p>Now you have no excuse for writing new tests (and that goes double for
me!).</p>
<p>
</p>
<hr />
<h1><A NAME="methods">METHODS</a></h1>
<p>
</p>
<h2><A NAME="new">new</a></h2>
<p>Takes the following parameters:</p>
<ul>
<li><strong><A NAME="name" class="item">name (required)</a></strong>

<p>The name of the entire group of tests.</p>
</li>
<li><strong><A NAME="description" class="item">description (required)</a></strong>

<p>What this group tests.</p>
</li>
<li><strong><A NAME="pre_test_cleanup" class="item">pre_test_cleanup (optional, default=1)</a></strong>

<p>If this is true (the default), the component root and data directory
will be deleted both before and after running tests.</p>
</li>
</ul>
<p>
</p>
<h2><A NAME="add_support">add_support</a></h2>
<p>Takes the following parameters:</p>
<ul>
<li><strong><A NAME="path" class="item">path (required)</a></strong>

<p>The path that other components will expect this component to be
reachable at.  All paths are prepended with the group name.  So '/bar'
as a support component in the 'foo' group's ultimate path would be
'/foo/bar'.</p>
</li>
<li><strong><A NAME="component" class="item">component</a></strong>

<p>Text of the support component.  This parameter must have a value
unless the skip_component parameter is true.</p>
</li>
<li><strong><A NAME="skip_component" class="item">skip_component</a></strong>

<p>If true, then the test harness will not write a component to disk for
this test.</p>
</li>
</ul>
<p>
</p>
<h2><A NAME="add_test">add_test</a></h2>
<p>Takes the following parameters:</p>
<ul>
<li><strong>name (required)</strong>

<p>The name of this test.</p>
</li>
<li><strong>description (required)</strong>

<p>What this test is testing.</p>
</li>
<li><strong>component (required)</strong>

<p>Text of the component.</p>
</li>
<li><strong>path (optional)</strong>

<p>The path that this component should written to.  As with support
components, this path is prepended with the group's name.  If no path
is given, it uses call_path, if given, otherwise it uses the name
parameter.</p>
</li>
<li><strong><A NAME="call_path" class="item">call_path (optional)</a></strong>

<p>The path that should be used to call the component.  If none is given,
it will be /&lt;group name&gt;/&lt;test name&gt;.  If a value is given, it is
still prepended by /&lt;group name&gt;/.</p>
</li>
<li><strong><A NAME="call_args" class="item">call_args (optional)</a></strong>

<p>The arguments that should be passed to the component, in list or hash
reference form. If none is given, no arguments are passed.</p>
</li>
<li><strong><A NAME="compiler_params" class="item">compiler_params</a></strong>

<p>This is a hash reference of parameters to be passed to the Compiler-&gt;new
method.</p>
</li>
<li><strong><A NAME="interp_params" class="item">interp_params</a></strong>

<p>This is a hash reference of parameters to be passed to the Interp-&gt;new
method.</p>
</li>
<li><strong><A NAME="interp" class="item">interp</a></strong>

<p>Provide an HTML::Mason::Interp object to be used for the test.</p>
</li>
<li><strong><A NAME="todo" class="item">todo</a></strong>

<p>If this is given, the test will be treated as a todo test, so it will
be expected to fail.  This should be a string.</p>
</li>
</ul>
<p>One of the following three options is required:</p>
<ul>
<li><strong><A NAME="expect" class="item">expect</a></strong>

<p>The text expected as a result of calling the component.  This
parameter is _not_ required when running in <A HREF="#additional_run_modes">Create mode</a>.</p>
</li>
<li><strong><A NAME="expect_error" class="item">expect_error</a></strong>

<p>A regex that will be matched against the error returned from the
component execution.</p>
</li>
<li><strong><A NAME="no_warnings" class="item">no_warnings</a></strong>

<p>If true, this means that the test expects to run without generating
any warnings.  If warnings are generated, the test fails.</p>
</li>
<li><strong><A NAME="expect_warnings" class="item">expect_warnings</a></strong>

<p>A regex that will be matched against any warnings output when running
the component.</p>
</li>
<li><strong><A NAME="skip_expect" class="item">skip_expect</a></strong>

<p>This causes the component to be run but its output is ignored.
However, if the component execution causes an error this will cause
the test to fail.  This is used in a few situations where it is
necessary to just run a component as part the preparation for another
test.</p>
</li>
</ul>
<p>
</p>
<h2><A NAME="run">run</a></h2>
<p>Run the tests in the group.</p>
<p>
</p>
<h2><A NAME="class_methods">Class methods</a></h2>
<p>These methods are provided since some tests may need to know these
values.</p>
<p>
</p>
<h2><A NAME="base_path">base_path</a></h2>
<p>The base path under which the component root and data directory for
the tests are created.</p>
<p>
</p>
<h2><A NAME="comp_root">comp_root</a></h2>
<p>Returns the component root directory.</p>
<p>
</p>
<h2><A NAME="data_dir">data_dir</a></h2>
<p>Return the data directory</p>
<p>
</p>
<h2><A NAME="check_output___actual_____actual">check_output ( actual =&gt; $actual_output, expect =&gt; $expected_output )</a></h2>
<p>Given the parameters shown above, this method will check to see if the
two are equal.  If they're not equal, it will print out an error
message attempting to highlight the difference.</p>
<p>
</p>
<hr />
<h1><A NAME="additional_run_modes">ADDITIONAL RUN MODES</a></h1>
<p>The following additional modes are available for running tests.</p>
<p>
</p>
<h2><A NAME="verbose_mode">Verbose mode</a></h2>
<p>To turn this on, set the environment variables MASON_VERBOSE or
MASON_DEBUG as true or run the tests as 'make test TEST_VERBOSE=1'.
In this mode, the <code>run</code> method will output information about tests as
they are run.  If a test fails, then it will also show the cause of
the failure.</p>
<p>
</p>
<h2><A NAME="debug_mode">Debug mode</a></h2>
<p>To turn this on, set the MASON_DEBUG environment variable to a true
value.  In this mode, the <code>run</code> method will print detailed
information of its actions.  This mode includes the output printed in
VERBOSE mode.</p>
<p>
</p>
<h2><A NAME="no_cleanup_mode">No cleanup mode</a></h2>
<p>Setting the MASON_NO_CLEANUP environment variable will tell the module
to not clean up generated data from running the tests.  This includes
the components written to disk and the data directory used during
testing.  This can be useful when debugging.</p>
<p>
</p>
<h2><A NAME="create_mode">Create mode</a></h2>
<p>If the individual tests are run from the command line with the
'--create' flag, then instead of checking the output of a component,
the test harness will simply output its results.  This allows you to
cut and paste these results back into the test file (assuming they are
correct!).</p>
<p>
</p>
<h2><A NAME="running_and_or_skipping_selected">Running and/or skipping selected tests</a></h2>
<p>You can run just some of a test file with the '--tests-to-run' flag or
the MASON_TESTS_TO_RUN environment variable. Similarly you can skip
specific tests with the '--tests-to-skip' flag or the
MASON_TESTS_TO_SKIP environment variable.</p>
<p>The value of either flag is a comma-separated list of one or more of</p>
<pre>
   [test_file_name:](test_number|test_name|*)</pre>
<p>e.g.</p>
<pre>
    perl ./01-syntax.t --tests-to-run=3,5
    MASON_TESTS_TO_SKIP=fake_percent,empty_percents perl ./01-syntax.t
    MASON_TESTS_TO_RUN=&quot;misc:autohandler, request:*, interp:private1&quot; make test</pre>
<p>
</p>
<h2><A NAME="subclassing_this_module">Subclassing this module</a></h2>
<p>You can run tests with your own Tests.pm subclass using the
'--tests-class' flag or the MASON_TESTS_CLASS environment variable.
The value is a fully qualified package name that will be loaded before
each test file is run.  e.g.</p>
<pre>
    perl ./01-syntax.t --tests-class=HTML::Mason::Tests::MyTests
    MASON_TESTS_CLASS=HTML::Mason::Tests::MyTests make test</pre>
<p>For example, if you have created your own lexer subclass and want
to make sure that tests still pass with it, create a Tests subclass
that overrides the _make_interp method to use your subclass:</p>
<pre>
    sub _make_interp
    {
        my ($self, %interp_params) = @_;</pre>
<pre>
        return HTML::Mason::Interp-&gt;new
            ( lexer_class =&gt; HTML::Mason::MyLexer,
              %interp_params );
    }</pre>
<p>
</p>
<hr />
<h1><A NAME="see_also">SEE ALSO</a></h1>
<p><a HREF="Mason.html">HTML::Mason</a></p>

</body>

</html>