📄 testrun.pm
字号:
map { "$_/Apache-Test/lib" } qw(. ..);}sub set_perl5lib { $ENV{PERL5LIB} = join $Config{path_sep}, shift->test_inc();}sub set_perldb_opts { my $config = shift->{test_config}; my $file = catfile $config->{vars}->{t_logs}, 'perldb.out'; $config->genfile($file); #mark for -clean $ENV{PERLDB_OPTS} = "NonStop frame=4 AutoTrace LineInfo=$file"; warning "perldb log is t/logs/perldb.out";}sub opt_debug { my $self = shift; my $server = $self->{server}; my $opts = $self->{opts}; my $debug_opts = {}; for (qw(debugger breakpoint)) { $debug_opts->{$_} = $opts->{$_}; } if (my $db = $opts->{debugger}) { if ($db =~ s/^perl=?//) { $opts->{'run-tests'} = 1; $self->start; #if not already running $self->set_perl5lib; $self->set_perldb_opts if $db eq 'nostop'; system $^X, '-MApache::TestPerlDB', '-d', @{ $self->{tests} }; $self->stop; return 1; } elsif ($db =~ s/^lwp[=:]?//) { $ENV{APACHE_TEST_DEBUG_LWP} = $db || 1; $opts->{verbose} = 1; return 0; } } $server->stop; $server->start_debugger($debug_opts); 1;}sub opt_help { my $self = shift; print <<EOM;usage: TEST [options ...] where options include:EOM for (sort keys %usage){ printf " -%-13s %s\n", $_, $usage{$_}; } print "\n configuration options:\n"; Apache::TestConfig->usage; 1;}# generate t/TEST script (or a different filename) which will drive# Apache::TestRunsub generate_script { my ($class, @opts) = @_; my %opts = (); # back-compat if (@opts == 1) { $opts{file} = $opts[0]; } else { %opts = @opts; $opts{file} ||= catfile 't', 'TEST'; } my $body = "BEGIN { eval { require blib && blib->import; } }\n"; my %args = @Apache::TestMM::Argv; while (my($k, $v) = each %args) { $v =~ s/\|/\\|/g; $body .= "\n\$Apache::TestConfig::Argv{'$k'} = q|$v|;\n"; } my $header = Apache::TestConfig->perlscript_header; $body .= join "\n", $header, "use $class ();"; if (my $report = $opts{bugreport}) { $body .= "\n\npackage $class;\n" . "sub bug_report { print '$report' }\n\n"; } $body .= "$class->new->run(\@ARGV);"; Apache::Test::basic_config()->write_perlscript($opts{file}, $body);}# in idiomatic perl functions return 1 on success and 0 on# failure. Shell expects the opposite behavior. So this function# reverses the status.sub exit_perl { exit_shell $_[0] ? 0 : 1;}# expects shell's exit status values (0==success)sub exit_shell {# require Carp;# Carp::cluck('exiting'); CORE::exit $_[0];}# successfully abort the test suite execution (to allow automatic# tools like CPAN.pm, to continue with installation).## if a true value is passed, quit right away# otherwise ask the user, if they may want to change their mind which# will return them back to where they leftsub skip_test_suite { my $no_doubt = shift; # we can't prompt when STDIN is not attached to tty, unless we # were told that's it OK via env var (in which case some program # will feed the interactive prompts unless (-t STDIN || $ENV{APACHE_TEST_INTERACTIVE_PROMPT_OK}) { $no_doubt = 1; } print qq[Running the test suite is important to make sure that the module thatyou are about to install works on your system. If you choose not torun the test suite and you have a problem using this module, make sureto return and run this test suite before reporting any problems to thedevelopers of this module.]; unless ($no_doubt) { my $default = 'No'; my $prompt = 'Skip the test suite?'; my $ans = ExtUtils::MakeMaker::prompt($prompt, $default); return if lc($ans) =~ /no/; } error "Skipping the test suite execution, while returning success status"; exit_perl 1;}1;__END__=head1 NAMEApache::TestRun - Run the test suite=head1 SYNOPSIS=head1 DESCRIPTIONThe C<Apache::TestRun> package controls the configuration and runningof the test suite.=head1 METHODSSeveral methods are sub-classable, if the default behavior should bechanged.=head2 C<bug_report>The C<bug_report()> method is executed when C<t/TEST> was executedwith the C<-bugreport> option, and C<make test> (or C<t/TEST>)fail. Normally this is callback which you can use to tell the user howto deal with the problem, e.g. suggesting to read some document oremail some details to someone who can take care of it. By defaultnothing is executed.The C<-bugreport> option is needed so this feature won't becomeannoying to developers themselves. It's automatically added to theC<run_tests> target in F<Makefile>. So if you repeateadly have to testyour code, just don't use C<make test> but run C<t/TEST>directly. Here is an example of a custom C<t/TEST> My::TestRun->new->run(@ARGV); package My::TestRun; use base 'Apache::TestRun'; sub bug_report { my $self = shift; print <<EOI; +--------------------------------------------------------+ | Please file a bug report: http://perl.apache.org/bugs/ | +--------------------------------------------------------+ EOI }=head2 C<pre_configure>The C<pre_configure()> method is executed before the configuration forC<Apache::Test> is generated. So if you need to adjust the setupbefore I<httpd.conf> and other files are autogenerated, this is theright place to do so.For example if you don't want to inherit a LoadModule directive forI<mod_apreq.so> but to make sure that the local version is used, youcan sub-class C<Apache::TestRun> and override this method inI<t/TEST.PL>: package My::TestRun; use base 'Apache::TestRun'; use Apache::TestConfig; __PACKAGE__->new->run(@ARGV); sub pre_configure { my $self = shift; # Don't load an installed mod_apreq Apache::TestConfig::autoconfig_skip_module_add('mod_apreq.c'); $self->SUPER::pre_configure(); }Notice that the extension is I<.c>, and not I<.so>.Don't forget to run the super class' c<pre_configure()> method.=head2 C<new_test_config>META: to be completed=head1 Persistent Custom ConfigurationWhen C<Apache::Test> is first installed or used, it will save thevalues of C<httpd>, C<apxs>, C<port>, C<user>, and C<group>, if set,to a configuration file C<Apache::TestConfigData>. This informationwill then be used in setting these options for subsequent uses ofC<Apache-Test> unless temprorarily overridden, either by setting theappropriate environment variable (C<APACHE_TEST_HTTPD>,C<APACHE_TEST_APXS>, C<APACHE_TEST_PORT>, C<APACHE_TEST_USER>, andC<APACHE_TEST_GROUP>) or by giving the relevant option (C<-httpd>,C<-apxs>, C<-port>, C<-user>, and C<-group>) when the C<TEST> scriptis run.To avoid either using previous persistent configurations or savingcurrent configurations, set the C<APACHE_TEST_NO_STICKY_PREFERENCES>environment variable to a true value.Finally it's possible to permanently override the previously savedoptions by passing C<L<-save|/Saving_Custom_Configuration_Options>>.Here is the algorithm of how and when options are saved for the firsttime and when they are used. We will use a few variables to simplifythe pseudo-code/pseudo-chart flow:C<$config_exists> - custom configuration has already been saved, toget this setting run C<custom_config_exists()>, which tests whethereither C<apxs> or C<httpd> values are set. It doesn't check for othervalues, since all we need is C<apxs> or C<httpd> to get the test suiterunning. custom_config_exists() checks in the following orderF<lib/Apache/TestConfigData.pm> (if during Apache-Test build) ,F<~/.apache-test/Apache/TestConfigData.pm> andF<Apache/TestConfigData.pm> in the perl's libraries.C<$config_overriden> - that means that we have either C<apxs> orC<httpd> values provided by user, via env vars or command line options.=over=item 1 Building Apache-Test or modperl-2.0 (or any other project thatbundles Apache-Test). 1) perl Apache-Test/Makefile.PL (for bundles top-level Makefile.PL will run this as well) if $config_exists do nothing else create lib/Apache/TestConfigData.pm w/ empty config: {} 2) make 3) make test if $config_exists if $config_overriden override saved options (for those that were overriden) else use saved options else if $config_overriden save them in lib/Apache/TestConfigData.pm (which will be installed on 'make install') else - run interactive prompt for C<httpd> and optionally for C<apxs> - save the custom config in lib/Apache/TestConfigData.pm - restart the currently run program modperl-2.0 is a special case in (3). it always overrides 'httpd' and 'apxs' settings. Other settings like 'port', can be used from the saved config. 4) make install if $config_exists only in lib/Apache/TestConfigData.pm it will be installed system-wide else nothing changes (since lib/Apache/TestConfigData.pm won't exist)=item 2 Testing 3rd party modules (after Apache-Test was installed)Notice that the following situation is quite possible: cd Apache-Test perl Makefile.PL && make installso that Apache-Test was installed but no custom configuration saved(since its C<make test> wasn't run). In which case the interactiveconfiguration should kick in (unless config options were passed) andin any case saved once configured.C<$custom_config_path> - perl's F<Apache/TestConfigData.pm> (at thesame location as F<Apache/TestConfig.pm>) if that area is writable bythat user (e.g. perl's lib is not owned by 'root'). If not, inF<~/.apache-test/Apache/TestConfigData.pm>. 1) perl Apache-Test/Makefile.PL 2) make 3) make test if $config_exists if $config_overriden override saved options (for those that were overriden) else use saved options else if $config_overriden save them in $custom_config_path else - run interactive prompt for C<httpd> and optionally for C<apxs> - save the custom config in $custom_config_path - restart the currently run program 4) make install=back=head2 Saving Custom Configuration OptionsIf you want to override the existing custom configurations options toC<Apache::TestConfigData>, use the C<-save> flag when running C<TEST>.If you are running C<Apache::Test> as a user who does not havepermission to alter the system C<Apache::TestConfigData>, you canplace your own private configuration file F<TestConfigData.pm> underC<$ENV{HOME}/.apache-test/Apache/>, which C<Apache::Test> will use, ifpresent. An example of such a configuration file is # file $ENV{HOME}/.apache-test/Apache/TestConfigData.pm package Apache::TestConfigData; use strict; use warnings; use vars qw($vars); $vars = { 'group' => 'me', 'user' => 'myself', 'port' => '8529', 'httpd' => '/usr/local/apache/bin/httpd', }; 1;=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -