.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 >0, 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 .\" ======================================================================== .\" .IX Title "HTML::Mason::Tests 3pm" .TH HTML::Mason::Tests 3pm 2024-03-05 "perl v5.38.2" "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 HTML::Mason::Tests \- Test harness for testing Mason .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use HTML::Mason::Tests; \& \& my $group = HTML::Mason::Tests\->new( name => \*(Aqname of group\*(Aq, description => \*(Aqtests something\*(Aq ); \& $group\->add_test( name => \*(Aqfoo\*(Aq, \& description => \*(Aqtests foo\*(Aq, \& component => <<\*(AqEOF\*(Aq \& <%args> \& $foo => 1 \& \& <% $foo %> \& EOF \& expect => <<\*(AqEOF\*(Aq, \& 1 \& EOF \& ); \& \& $group\->run; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" 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. .PP It also makes sure that any given group of tests provides all the information needed to run them (test names, components and results, etc.). .PP Now you have no excuse for writing new tests (and that goes double for me!). .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" Takes the following parameters: .IP \(bu 4 name (required) .Sp The name of the entire group of tests. .IP \(bu 4 description (required) .Sp What this group tests. .IP \(bu 4 pre_test_cleanup (optional, default=1) .Sp If this is true (the default), the component root and data directory will be deleted both before and after running tests. .SS add_support .IX Subsection "add_support" Takes the following parameters: .IP \(bu 4 path (required) .Sp 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'. .IP \(bu 4 component .Sp Text of the support component. This parameter must have a value unless the skip_component parameter is true. .IP \(bu 4 skip_component .Sp If true, then the test harness will not write a component to disk for this test. .SS add_test .IX Subsection "add_test" Takes the following parameters: .IP \(bu 4 name (required) .Sp The name of this test. .IP \(bu 4 description (required) .Sp What this test is testing. .IP \(bu 4 component (required) .Sp Text of the component. .IP \(bu 4 path (optional) .Sp 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. .IP \(bu 4 call_path (optional) .Sp The path that should be used to call the component. If none is given, it will be //. If a value is given, it is still prepended by //. .IP \(bu 4 call_args (optional) .Sp The arguments that should be passed to the component, in list or hash reference form. If none is given, no arguments are passed. .IP \(bu 4 compiler_params .Sp This is a hash reference of parameters to be passed to the Compiler\->new method. .IP \(bu 4 interp_params .Sp This is a hash reference of parameters to be passed to the Interp\->new method. .IP \(bu 4 interp .Sp Provide an HTML::Mason::Interp object to be used for the test. .IP \(bu 4 todo .Sp 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. .PP One of the following three options is required: .IP \(bu 4 expect .Sp The text expected as a result of calling the component. This parameter is _not_ required when running in Create mode. .IP \(bu 4 expect_error .Sp A regex that will be matched against the error returned from the component execution. .IP \(bu 4 no_warnings .Sp If true, this means that the test expects to run without generating any warnings. If warnings are generated, the test fails. .IP \(bu 4 expect_warnings .Sp A regex that will be matched against any warnings output when running the component. .IP \(bu 4 skip_expect .Sp 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. .SS run .IX Subsection "run" Run the tests in the group. .SS "Class methods" .IX Subsection "Class methods" These methods are provided since some tests may need to know these values. .SS base_path .IX Subsection "base_path" The base path under which the component root and data directory for the tests are created. .SS comp_root .IX Subsection "comp_root" Returns the component root directory. .SS data_dir .IX Subsection "data_dir" Return the data directory .ie n .SS "check_output ( actual => $actual_output, expect => $expected_output )" .el .SS "check_output ( actual => \f(CW$actual_output\fP, expect => \f(CW$expected_output\fP )" .IX Subsection "check_output ( actual => $actual_output, expect => $expected_output )" 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. .SH "ADDITIONAL RUN MODES" .IX Header "ADDITIONAL RUN MODES" The following additional modes are available for running tests. .SS "Verbose mode" .IX Subsection "Verbose mode" 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 \f(CW\*(C`run\*(C'\fR method will output information about tests as they are run. If a test fails, then it will also show the cause of the failure. .SS "Debug mode" .IX Subsection "Debug mode" To turn this on, set the MASON_DEBUG environment variable to a true value. In this mode, the \f(CW\*(C`run\*(C'\fR method will print detailed information of its actions. This mode includes the output printed in VERBOSE mode. .SS "No cleanup mode" .IX Subsection "No cleanup 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. .SS "Create mode" .IX Subsection "Create mode" 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!). .SS "Running and/or skipping selected tests" .IX Subsection "Running and/or skipping selected tests" 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. .PP The value of either flag is a comma-separated list of one or more of .PP .Vb 1 \& [test_file_name:](test_number|test_name|*) .Ve .PP e.g. .PP .Vb 3 \& 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 .Ve .SS "Subclassing this module" .IX Subsection "Subclassing this module" 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. .PP .Vb 2 \& perl ./01\-syntax.t \-\-tests\-class=HTML::Mason::Tests::MyTests \& MASON_TESTS_CLASS=HTML::Mason::Tests::MyTests make test .Ve .PP 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: .PP .Vb 3 \& sub _make_interp \& { \& my ($self, %interp_params) = @_; \& \& return HTML::Mason::Interp\->new \& ( lexer_class => HTML::Mason::MyLexer, \& %interp_params ); \& } .Ve