HTML::Mason::Tests - Test harness for testing Mason
use HTML::Mason::Tests; my $group = HTML::Mason::Tests->new( name => 'name of group', description => 'tests something' ); $group->add_test( name => 'foo', description => 'tests foo', component => <<'EOF' <%args> $foo => 1 </%args> <% $foo %> EOF expect => <<'EOF', 1 EOF ); $group->run;
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.
It also makes sure that any given group of tests provides all the information needed to run them (test names, components and results, etc.).
Now you have no excuse for writing new tests (and that goes double for me!).
Takes the following parameters:
Takes the following parameters:
Takes the following parameters:
One of the following three options is required:
Run the tests in the group.
These methods are provided since some tests may need to know these values.
The base path under which the component root and data directory for the tests are created.
Returns the component root directory.
Return the data directory
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.
The following additional modes are available for running tests.
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 run
method will output information about tests as
they are run. If a test fails, then it will also show the cause of
the failure.
To turn this on, set the MASON_DEBUG environment variable to a true
value. In this mode, the run
method will print detailed
information of its actions. This mode includes the output printed in
VERBOSE mode.
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.
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!).
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.
The value of either flag is a comma-separated list of one or more of
[test_file_name:](test_number|test_name|*)
e.g.
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="misc:autohandler, request:*, interp:private1" make test
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.
perl ./01-syntax.t --tests-class=HTML::Mason::Tests::MyTests MASON_TESTS_CLASS=HTML::Mason::Tests::MyTests make test
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:
sub _make_interp { my ($self, %interp_params) = @_; return HTML::Mason::Interp->new ( lexer_class => HTML::Mason::MyLexer, %interp_params ); }