™.. Apache::Test - Online Linux Manual PageSection : 3
Updated : 2007-12-31
Source : perl v5.10.1
Note : User Contributed Perl Documentation
NAMEApache::Test − Test.pm wrapper with helpers for testing Apache
SYNOPSIS use Apache::Test;
DESCRIPTIONApache::Test is a wrapper around the standard \*(C`Test.pm\*(C'\fR with helpers for testing an Apache server.
FUNCTIONSplan This function is a wrapper around \*(C`Test::plan\*(C'\fR: plan tests => 3;
just like using Test.pm, plan 3 tests. If the first argument is an object, such as an \*(C`Apache::RequestRec\*(C'\fR object, \*(C`STDOUT\*(C'\fR will be tied to it. The \f(CW\*(C`Test.pm\*(C'\fR global state will also be refreshed by calling \*(C`Apache::Test::test_pm_refresh\*(C'\fR. For example: plan $r, tests => 7;
ties STDOUT to the request object $r. If there is a last argument that doesn't belong to \*(C`Test::plan\*(C'\fR (which expects a balanced hash), it's used to decide whether to continue with the test or to skip it all-together. This last argument can be: • a \*(C`SCALAR\*(C'\fR the test is skipped if the scalar has a false value. For example: plan tests => 5, 0;
But this won't hint the reason for skipping therefore it's better to use need(): plan tests => 5,
need 'LWP',
{ "not Win32" => sub { $^O eq 'MSWin32'} };
see \*(C`need()\*(C'\fR for more info. • an \*(C`ARRAY\*(C'\fR reference need_module() is called for each value in this array. The test is skipped if() returns false (which happens when at least one C or Perl module from the list cannot be found). Watch out for case insensitive file systems or duplicate modules with the same name. I.E. If you mean mod_env.c
need_module('mod_env.c') Not
need_module('env') • a \*(C`CODE\*(C'\fR reference the tests will be skipped if the function returns a false value. For example: plan tests => 5, need_lwp;
the test will be skipped if LWP is not available All other arguments are passed through to Test::plan as is. ok Same as Test::ok, see Test.pm documentation. sok Allows to skip a sub-test, controlled from the command line. The argument to sok() is a CODE reference or a BLOCK whose return value will be passed to ok(). By default behaves like ok(). If all sub-tests of the same test are written using sok(), and a test is executed as: % ./t/TEST −v skip_subtest 1 3
only sub-tests 1 and 3 will be run, the rest will be skipped. skip Same as Test::skip, see Test.pm documentation. test_pm_refresh Normally called by Apache::Test::plan, this function will refresh the global state maintained by Test.pm, allowing \*(C`plan\*(C'\fR and friends to be called more than once per-process. This function is not exported. Functions that can be used as a last argument to the extended plan(). Note that for each \*(C`need_*\*(C'\fR function there is a \f(CW\*(C`have_*\*(C'\fR equivalent that performs the exact same function except that it is designed to be used outside of \*(C`plan()\*(C'\fR. \f(CW\*(C`need_*\*(C'\fR functions have the side effect of generating skip messages, if the test is skipped. \*(C`have_*\*(C'\fR functions don't have this side effect. In other words, use \*(C`need_apache()\*(C'\fR with \*(C`plan()\*(C'\fR to decide whether a test will run, but \f(CW\*(C`have_apache()\*(C'\fR within test logic to adjust expectations based on older or newer server versions. need_http11 plan tests => 5, need_http11;
Require HTTP/1.1 support. need_ssl plan tests => 5, need_ssl;
Require SSL support. Not exported by default. need_lwp plan tests => 5, need_lwp;
Require LWP support. need_cgi plan tests => 5, need_cgi;
Requires mod_cgi or mod_cgid to be installed. need_php plan tests => 5, need_php;
Requires a PHP module to be installed (version 4 or 5). need_php4 plan tests => 5, need_php4;
Requires a PHP version 4 module to be installed. need_imagemap plan tests => 5, need_imagemap;
Requires a mod_imagemap or mod_imap be installed need_apache plan tests => 5, need_apache 2;
Requires Apache 2nd generation httpd−2.x.xx plan tests => 5, need_apache 1;
Requires Apache 1st generation (apache−1.3.xx) See also \*(C`need_min_apache_version()\*(C'\fR. need_min_apache_version Used to require a minimum version of Apache. For example: plan tests => 5, need_min_apache_version("2.0.40");
requires Apache 2.0.40 or higher. need_apache_version Used to require a specific version of Apache. For example: plan tests => 5, need_apache_version("2.0.40");
requires Apache 2.0.40. need_apache_mpm Used to require a specific Apache Multi-Processing Module. For example: plan tests => 5, need_apache_mpm('prefork');
requires the prefork MPM. need_perl plan tests => 5, need_perl 'iolayers';
plan tests => 5, need_perl 'ithreads';
Requires a perl extension to be present, or perl compiled with certain capabilities. The first example tests whether \*(C`PerlIO\*(C'\fR is available, the second whether: $Config{useithread} eq 'define';
need_min_perl_version Used to require a minimum version of Perl. For example: plan tests => 5, need_min_perl_version("5.008001");
requires Perl 5.8.1 or higher. need_module plan tests => 5, need_module 'CGI';
plan tests => 5, need_module qw(CGI Find::File);
plan tests => 5, need_module ['CGI', 'Find::File', 'cgid'];
Requires Apache C and Perl modules. The function accept a list of arguments or a reference to a list. In case of C modules, depending on how the module name was passed it may pass through the following completions: 1 need_module 'proxy_http.c' If there is the .c extension, the module name will be looked up as is, i.e. 'proxy_http.c'. 2 need_module 'mod_cgi' The .c extension will be appended before the lookup, turning it into 'mod_cgi.c'. 3 need_module 'cgi' The .c extension and mod_ prefix will be added before the lookup, turning it into 'mod_cgi.c'. need_min_module_version Used to require a minimum version of a module For example: plan tests => 5, need_min_module_version(CGI => 2.81);
requires \*(C`CGI.pm\*(C'\fR version 2.81 or higher. Currently works only for perl modules. need plan tests => 5,
need 'LWP',
{ "perl >= 5.8.0 and w/ithreads is required" =>
($Config{useperlio} && $] >= 5.008) },
{ "not Win32" => sub { $^O eq 'MSWin32' },
"foo is disabled" => \&is_foo_enabled,
},
'cgid';
need() is more generic function which can impose multiple requirements at once. All requirements must be satisfied. need()'s argument is a list of things to test. The list can include scalars, which are passed to need_module(), and hash references. If hash references are used, the keys, are strings, containing a reason for a failure to satisfy this particular entry, the values are the condition, which are satisfaction if they return true. If the value is 0 or 1, it used to decide whether the requirements very satisfied, so you can mix special \*(C`need_*()\*(C'\fR functions that return 0 or 1. For example: plan tests => 1, need 'Compress::Zlib', 'deflate',
need_min_apache_version("2.0.49");
If the scalar value is a string, different from 0 or 1, it's passed to need_module(). If the value is a code reference, it gets executed at the time of check and its return value is used to check the condition. If the condition check fails, the provided (in a key) reason is used to tell user why the test was skipped. In the presented example, we require the presence of the \*(C`LWP\*(C'\fR Perl module, \*(C`mod_cgid\*(C'\fR, that we run under perl >= 5.7.3 on Win32. It's possible to put more than one requirement into a single hash reference, but be careful that the keys will be different. It's also important to mention to avoid using: plan tests => 1, requirement1 && requirement2;
technique. While test-wise that technique is equivalent to: plan tests => 1, need requirement1, requirement2;
since the test will be skipped, unless all the rules are satisfied, it's not equivalent for the end users. The second technique, deploying \*(C`need()\*(C'\fR and a list of requirements, always runs all the requirement checks and reports all the missing requirements. In the case of the first technique, if the first requirement fails, the second is not run, and the missing requirement is not reported. So let's say all the requirements are missing Apache modules, and a user wants to satisfy all of these and run the test suite again. If all the unsatisfied requirements are reported at once, she will need to rebuild Apache once. If only one requirement is reported at a time, she will have to rebuild Apache as many times as there are elements in the \*(C`&&\*(C'\fR statement. Also see(). under_construction plan tests => 5, under_construction;
skip all tests, noting that the tests are under construction skip_reason plan tests => 5, skip_reason('my custom reason');
skip all tests. the reason you specify will be given at runtime. if no reason is given a default reason will be used.
Additional Configuration Variablesbasic_config my $basic_cfg = Apache::Test::basic_config();
$basic_cfg−>write_perlscript($file, $content);
\*(C`basic_config()\*(C'\fR is similar to \f(CW\*(C`config()\*(C'\fR, but doesn't contain any httpd-specific information and should be used for operations that don't require any httpd-specific knowledge. config my $cfg = Apache::Test::config();
my $server_rev = $cfg−>{server}−>{rev};
...
\*(C`config()\*(C'\fR gives an access to the configuration object. vars my $serverroot = Apache::Test::vars−>{serverroot};
my $serverroot = Apache::Test::vars('serverroot');
my($top_dir, $t_dir) = Apache::Test::vars(qw(top_dir t_dir));
\*(C`vars()\*(C'\fR gives an access to the configuration variables, otherwise accessible as: $vars = Apache::Test::config()−>{vars};
If no arguments are passed, the reference to the variables hash is returned. If one or more arguments are passed the corresponding values are returned.
Test::More IntegrationThere are a few caveats if you want to use Apache::Test with Test::More instead of the default Test backend. The first is that Test::More requires you to use its own \*(C`plan()\*(C'\fR function and not the one that ships with Apache::Test. Test::More also defines \*(C`ok()\*(C'\fR and \f(CW\*(C`skip()\*(C'\fR functions that are different, and simply \*(C`use\*(C'\fRing both modules in your test script will lead to redefined warnings for these subroutines. To assist Test::More users we have created a special Apache::Test import tag, \*(C`:withtestmore\*(C'\fR, which will export all of the standard Apache::Test symbols into your namespace except the ones that collide with Test::More. use Apache::Test qw(:withtestmore);
use Test::More;
plan tests => 1; # Test::More::plan()
ok ('yes', 'testing ok'); # Test::More::ok()
Now, while this works fine for standard client-side tests (such as \*(C`t/basic.t\*(C'\fR), the more advanced features of \fIApache::Test\fR require using Test::More as the sole driver behind the scenes. Should you choose to use Test::More as the backend for server-based tests (such as \*(C`t/response/TestMe/basic.pm\*(C'\fR) you will need to use the \*(C`\-withtestmore\*(C'\fR action tag: use Apache::Test qw(−withtestmore);
sub handler {
my $r = shift;
plan $r, tests => 1; # Test::More::plan() with
# Apache::Test features
ok ('yes', 'testing ok'); # Test::More::ok()
}
\*(C`\-withtestmore\*(C'\fR tells \fIApache::Test\fR to use \fITest::More\fR instead of Test.pm behind the scenes. Note that you are not required to \*(C`use Test::More\*(C'\fR yourself with the \f(CW\*(C`\-withtestmore\*(C'\fR option and that the \*(C`use Test::More tests => 1\*(C'\fR syntax may have unexpected results. Note that Test::More version 0.49, available within the Test::Simple 0.49 distribution on CPAN, or greater is required to use this feature. Because Apache:Test was initially developed using Test as the framework driver, complete Test::More integration is considered experimental at this time − it is supported as best as possible but is not guaranteed to be as stable as the default Test interface at this time.
Apache::TestToString ClassThe Apache::TestToString class is used to capture Test.pm output into a string. Example: Apache::TestToString−>start;
plan tests => 4;
ok $data eq 'foo';
...
# $tests will contain the Test.pm output: 1..4\nok 1\n...
my $tests = Apache::TestToString−>finish;
SEE ALSOThe Apache-Test tutorial: <http://perl.apache.org/docs/general/testing/testing.html>. Apache::TestRequest subclasses LWP::UserAgent and exports a number of useful functions for sending request to the Apache test server. You can then test the results of those requests. Use Apache::TestMM in your Makefile.PL to set up your distribution for testing.
AUTHORDoug MacEachern with contributions from Geoffrey Young, Philippe M. Chiasson, Stas Bekman and others. Questions can be asked at the test-dev <at> httpd.apache.org list For more information see: http://httpd.apache.org/test/.
POD ERRORSHey! The above document had some coding errors, which are explained below: Around line 939: '=item' outside of any '=over' Around line 971: You forgot a '=back' before '=head1' 0
Johanes Gumabo
Data Size : 51,793 byte
man-Apache::Test.3pmBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 2 / 174,382
Visitor ID : :
Visitor IP : 18.117.254.177 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|Apache::Test.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|Apache::Test.3pm|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|Apache::Test.3pm|41|br══─}─══|'br══─}─══
) (htmlprn|149|Apache::Test.3pm|41|'br══─}─══ |'br══─}─══
) (rof_nr_x|149|Apache::Test.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (rof_unit_scale_px|41|Apache::Test.3pm|51/52|F|.ie \nF ══─{─══. de IX
) (rof_if|19|Apache::Test.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (htmlprn|149|Apache::Test.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX
) (rof_escape_sequence|91|Apache::Test.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2"
) (parse_manual_page_|249|Apache::Test.3pm|57|══─}─══|.══─}─══
) (htmlprn|149|Apache::Test.3pm|57|.══─}─══ |.══─}─══
) (rof_escape_sequence|91|Apache::Test.3pm|141|\*(C`Test.pm\*(C'\fR with |\&\fBApache::Test\fR is a wrapper around the standard \f(CW\*(C`Test.pm\*(C'\fR with
) (rof_escape_sequence|91|Apache::Test.3pm|147|\*(C`Test::plan\*(C'\fR: |This function is a wrapper around \f(CW\*(C`Test::plan\*(C'\fR:
) (rof_escape_sequence|91|Apache::Test.3pm|155|\*(C`Apache::RequestRec\*(C'\fR |If the first argument is an object, such as an \f(CW\*(C`Apache::RequestRec\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|156|\*(C`STDOUT\*(C'\fR will be tied to it. The \f(CW\*(C`Test.pm\*(C'\fR global state will |object, \f(CW\*(C`STDOUT\*(C'\fR will be tied to it. The \f(CW\*(C`Test.pm\*(C'\fR global state will
) (rof_escape_sequence|91|Apache::Test.3pm|157|\*(C`Apache::Test::test_pm_refresh\*(C'\fR. For |also be refreshed by calling \f(CW\*(C`Apache::Test::test_pm_refresh\*(C'\fR. For
) (rof_escape_sequence|91|Apache::Test.3pm|166|\*(C`Test::plan\*(C'\fR |If there is a last argument that doesn't belong to \f(CW\*(C`Test::plan\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|172|\*(C`SCALAR\*(C'\fR |a \f(CW\*(C`SCALAR\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|189|\*(C`need()\*(C'\fR for more info. |see \f(CW\*(C`need()\*(C'\fR for more info.
) (rof_escape_sequence|91|Apache::Test.3pm|191|\*(C`ARRAY\*(C'\fR reference |an \f(CW\*(C`ARRAY\*(C'\fR reference
) (rof_escape_sequence|91|Apache::Test.3pm|203|\*(C`CODE\*(C'\fR reference |a \f(CW\*(C`CODE\*(C'\fR reference
) (rof_escape_sequence|91|Apache::Test.3pm|239|\*(C`plan\*(C'\fR and |the global state maintained by \fITest.pm\fR, allowing \f(CW\*(C`plan\*(C'\fR and
) (rof_escape_sequence|91|Apache::Test.3pm|244|\*(C`need_*\*(C'\fR function there is a \f(CW\*(C`have_*\*(C'\fR equivalent |Note that for each \f(CW\*(C`need_*\*(C'\fR function there is a \f(CW\*(C`have_*\*(C'\fR equivalent
) (rof_escape_sequence|91|Apache::Test.3pm|246|\*(C`plan()\*(C'\fR. \f(CW\*(C`need_*\*(C'\fR functions have the side effect |be used outside of \f(CW\*(C`plan()\*(C'\fR. \f(CW\*(C`need_*\*(C'\fR functions have the side effect
) (rof_escape_sequence|91|Apache::Test.3pm|247|\*(C`have_*\*(C'\fR functions |of generating skip messages, if the test is skipped. \f(CW\*(C`have_*\*(C'\fR functions
) (rof_escape_sequence|91|Apache::Test.3pm|248|\*(C`need_apache()\*(C'\fR |don't have this side effect. In other words, use \f(CW\*(C`need_apache()\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|249|\*(C`plan()\*(C'\fR to decide whether a test will run, but \f(CW\*(C`have_apache()\*(C'\fR |with \f(CW\*(C`plan()\*(C'\fR to decide whether a test will run, but \f(CW\*(C`have_apache()\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|317|\*(C`need_min_apache_version()\*(C'\fR. |See also \f(CW\*(C`need_min_apache_version()\*(C'\fR.
) (rof_escape_sequence|91|Apache::Test.3pm|361|\*(C`PerlIO\*(C'\fR is available, the second |The first example tests whether \f(CW\*(C`PerlIO\*(C'\fR is available, the second
) (rof_escape_sequence|91|Apache::Test.3pm|417|\*(C`CGI.pm\*(C'\fR version 2.81 or higher. |requires \f(CW\*(C`CGI.pm\*(C'\fR version 2.81 or higher.
) (rof_escape_sequence|91|Apache::Test.3pm|442|\*(C`need_*()\*(C'\fR functions that return 0 or 1. For |you can mix special \f(CW\*(C`need_*()\*(C'\fR functions that return 0 or 1. For
) (rof_escape_sequence|91|Apache::Test.3pm|456|\*(C`LWP\*(C'\fR Perl |In the presented example, we require the presence of the \f(CW\*(C`LWP\*(C'\fR Perl
) (rof_escape_sequence|91|Apache::Test.3pm|457|\*(C`mod_cgid\*(C'\fR, that we run under perl >= 5.7.3 on Win32. |module, \f(CW\*(C`mod_cgid\*(C'\fR, that we run under perl >= 5.7.3 on Win32.
) (rof_escape_sequence|91|Apache::Test.3pm|476|\*(C`need()\*(C'\fR and a list of requirements, always runs all the requirement |\&\f(CW\*(C`need()\*(C'\fR and a list of requirements, always runs all the requirement
) (rof_escape_sequence|91|Apache::Test.3pm|484|\*(C`&&\*(C'\fR |rebuild Apache as many times as there are elements in the \f(CW\*(C`&&\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|512|\*(C`basic_config()\*(C'\fR is similar to \f(CW\*(C`config()\*(C'\fR, but doesn't contain any |\&\f(CW\*(C`basic_config()\*(C'\fR is similar to \f(CW\*(C`config()\*(C'\fR, but doesn't contain any
) (rof_escape_sequence|91|Apache::Test.3pm|523|\*(C`config()\*(C'\fR gives an access to the configuration object. |\&\f(CW\*(C`config()\*(C'\fR gives an access to the configuration object.
) (rof_escape_sequence|91|Apache::Test.3pm|532|\*(C`vars()\*(C'\fR gives an access to the configuration variables, otherwise |\&\f(CW\*(C`vars()\*(C'\fR gives an access to the configuration variables, otherwise
) (rof_escape_sequence|91|Apache::Test.3pm|546|\*(C`plan()\*(C'\fR function |that \fITest::More\fR requires you to use its own \f(CW\*(C`plan()\*(C'\fR function
) (rof_escape_sequence|91|Apache::Test.3pm|548|\*(C`ok()\*(C'\fR and \f(CW\*(C`skip()\*(C'\fR functions that are different, and |defines \f(CW\*(C`ok()\*(C'\fR and \f(CW\*(C`skip()\*(C'\fR functions that are different, and
) (rof_escape_sequence|91|Apache::Test.3pm|549|\*(C`use\*(C'\fRing both modules in your test script will lead to redefined |simply \f(CW\*(C`use\*(C'\fRing both modules in your test script will lead to redefined
) (rof_escape_sequence|91|Apache::Test.3pm|553|\*(C`:withtestmore\*(C'\fR, which will export all of the standard |import tag, \f(CW\*(C`:withtestmore\*(C'\fR, which will export all of the standard
) (rof_escape_sequence|91|Apache::Test.3pm|567|\*(C`t/basic.t\*(C'\fR), the more advanced features of \fIApache::Test\fR |(such as \f(CW\*(C`t/basic.t\*(C'\fR), the more advanced features of \fIApache::Test\fR
) (rof_escape_sequence|91|Apache::Test.3pm|571|\*(C`t/response/TestMe/basic.pm\*(C'\fR) you will |server-based tests (such as \f(CW\*(C`t/response/TestMe/basic.pm\*(C'\fR) you will
) (rof_escape_sequence|91|Apache::Test.3pm|572|\*(C`\-withtestmore\*(C'\fR action tag: |need to use the \f(CW\*(C`\-withtestmore\*(C'\fR action tag:
) (rof_escape_sequence|91|Apache::Test.3pm|588|\*(C`\-withtestmore\*(C'\fR tells \fIApache::Test\fR to use \fITest::More\fR |\&\f(CW\*(C`\-withtestmore\*(C'\fR tells \fIApache::Test\fR to use \fITest::More\fR
) (rof_escape_sequence|91|Apache::Test.3pm|590|\*(C`use Test::More\*(C'\fR yourself with the \f(CW\*(C`\-withtestmore\*(C'\fR |required to \f(CW\*(C`use Test::More\*(C'\fR yourself with the \f(CW\*(C`\-withtestmore\*(C'\fR
) (rof_escape_sequence|91|Apache::Test.3pm|591|\*(C`use Test::More tests => 1\*(C'\fR syntax |option and that the \f(CW\*(C`use Test::More tests => 1\*(C'\fR syntax
)