⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 harness.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
package TAP::Harness;use strict;use Carp;use File::Spec;use File::Path;use IO::Handle;use TAP::Base;use TAP::Parser;use TAP::Parser::Aggregator;use TAP::Parser::Multiplexer;use vars qw($VERSION @ISA);@ISA = qw(TAP::Base);=head1 NAMETAP::Harness - Run test scripts with statistics=head1 VERSIONVersion 3.07=cut$VERSION = '3.07';$ENV{HARNESS_ACTIVE}  = 1;$ENV{HARNESS_VERSION} = $VERSION;END {    # For VMS.    delete $ENV{HARNESS_ACTIVE};    delete $ENV{HARNESS_VERSION};}=head1 DESCRIPTIONThis is a simple test harness which allows tests to be run and resultsautomatically aggregated and output to STDOUT.=head1 SYNOPSIS use TAP::Harness; my $harness = TAP::Harness->new( \%args ); $harness->runtests(@tests);=cutmy %VALIDATION_FOR;my @FORMATTER_ARGS;sub _error {    my $self = shift;    return $self->{error} unless @_;    $self->{error} = shift;}BEGIN {    @FORMATTER_ARGS = qw(      directives verbosity timer failures errors stdout color    );    %VALIDATION_FOR = (        lib => sub {            my ( $self, $libs ) = @_;            $libs = [$libs] unless 'ARRAY' eq ref $libs;            return [ map {"-I$_"} @$libs ];        },        switches        => sub { shift; shift },        exec            => sub { shift; shift },        merge           => sub { shift; shift },        formatter_class => sub { shift; shift },        formatter       => sub { shift; shift },        jobs            => sub { shift; shift },        fork            => sub { shift; shift },        test_args       => sub { shift; shift },    );    for my $method ( sort keys %VALIDATION_FOR ) {        no strict 'refs';        if ( $method eq 'lib' || $method eq 'switches' ) {            *{$method} = sub {                my $self = shift;                unless (@_) {                    $self->{$method} ||= [];                    return wantarray                      ? @{ $self->{$method} }                      : $self->{$method};                }                $self->_croak("Too many arguments to method '$method'")                  if @_ > 1;                my $args = shift;                $args = [$args] unless ref $args;                $self->{$method} = $args;                return $self;            };        }        else {            *{$method} = sub {                my $self = shift;                return $self->{$method} unless @_;                $self->{$method} = shift;            };        }    }    for my $method (@FORMATTER_ARGS) {        no strict 'refs';        *{$method} = sub {            my $self = shift;            return $self->formatter->$method(@_);        };    }}##############################################################################=head1 METHODS=head2 Class Methods=head3 C<new> my %args = (    verbosity => 1,    lib     => [ 'lib', 'blib/lib' ], ) my $harness = TAP::Harness->new( \%args );The constructor returns a new C<TAP::Harness> object.  It accepts an optionalhashref whose allowed keys are:=over 4=item * C<verbosity>Set the verbosity level:     1   verbose        Print individual test results to STDOUT.     0   normal    -1   quiet          Suppress some test output (mostly failures                         while tests are running).    -2   really quiet   Suppress everything but the tests summary.=item * C<timer>Append run time for each test to output. Uses L<Time::HiRes> if available.=item * C<failures>Only show test failures (this is a no-op if C<verbose> is selected).=item * C<lib>Accepts a scalar value or array ref of scalar values indicating which paths toallowed libraries should be included if Perl tests are executed.  Naturally,this only makes sense in the context of tests written in Perl.=item * C<switches>Accepts a scalar value or array ref of scalar values indicating which switchesshould be included if Perl tests are executed.  Naturally, this only makessense in the context of tests written in Perl.=item * C<test_args>A reference to an C<@INC> style array of arguments to be passed to eachtest program.=item * C<color>Attempt to produce color output.=item * C<exec>Typically, Perl tests are run through this.  However, anything which spits outTAP is fine.  You can use this argument to specify the name of the program(and optional switches) to run your tests with:  exec => ['/usr/bin/ruby', '-w']  =item * C<merge>If C<merge> is true the harness will create parsers that merge STDOUTand STDERR together for any processes they start.=item * C<formatter_class>The name of the class to use to format output. The default isL<TAP::Formatter::Console>.=item * C<formatter>If set C<formatter> must be an object that is capable of formatting theTAP output. See L<TAP::Formatter::Console> for an example.=item * C<errors>If parse errors are found in the TAP output, a note of this will be madein the summary report.  To see all of the parse errors, set this argument totrue:  errors => 1=item * C<directives>If set to a true value, only test results with directives will be displayed.This overrides other settings such as C<verbose> or C<failures>.=item * C<stdout>A filehandle for catching standard output.=backAny keys for which the value is C<undef> will be ignored.=cut# new supplied by TAP::Base{    my @legal_callback = qw(      parser_args      made_parser      before_runtests      after_runtests      after_test    );    sub _initialize {        my ( $self, $arg_for ) = @_;        $arg_for ||= {};        $self->SUPER::_initialize( $arg_for, \@legal_callback );        my %arg_for = %$arg_for;    # force a shallow copy        for my $name ( sort keys %VALIDATION_FOR ) {            my $property = delete $arg_for{$name};            if ( defined $property ) {                my $validate = $VALIDATION_FOR{$name};                my $value = $self->$validate($property);                if ( $self->_error ) {                    $self->_croak;                }                $self->$name($value);            }        }        $self->jobs(1) unless defined $self->jobs;        unless ( $self->formatter ) {            $self->formatter_class( my $class = $self->formatter_class                  || 'TAP::Formatter::Console' );            croak "Bad module name $class"              unless $class =~ /^ \w+ (?: :: \w+ ) *$/x;            eval "require $class";            $self->_croak("Can't load $class") if $@;            # This is a little bodge to preserve legacy behaviour. It's            # pretty horrible that we know which args are destined for            # the formatter.            my %formatter_args = ( jobs => $self->jobs );            for my $name (@FORMATTER_ARGS) {                if ( defined( my $property = delete $arg_for{$name} ) ) {                    $formatter_args{$name} = $property;                }            }            $self->formatter( $class->new( \%formatter_args ) );        }        if ( my @props = sort keys %arg_for ) {            $self->_croak("Unknown arguments to TAP::Harness::new (@props)");        }        return $self;    }}##############################################################################=head2 Instance Methods=head3 C<runtests>    $harness->runtests(@tests);Accepts and array of C<@tests> to be run.  This should generally be the namesof test files, but this is not required.  Each element in C<@tests> will bepassed to C<TAP::Parser::new()> as a C<source>.  See L<TAP::Parser> for moreinformation.It is possible to provide aliases that will be displayed in place of thetest name by supplying the test as a reference to an array containingC<< [ $test, $alias ] >>:    $harness->runtests( [ 't/foo.t', 'Foo Once' ],                        [ 't/foo.t', 'Foo Twice' ] );Normally it is an error to attempt to run the same test twice. Aliasesallow you to overcome this limitation by giving each run of the test aunique name.Tests will be run in the order found.If the environment variable C<PERL_TEST_HARNESS_DUMP_TAP> is defined itshould name a directory into which a copy of the raw TAP for each testwill be written. TAP is written to files named for each test.Subdirectories will be created as needed.Returns a L<TAP::Parser::Aggregator> containing the test results.=cutsub runtests {    my ( $self, @tests ) = @_;    my $aggregate = TAP::Parser::Aggregator->new;    $self->_make_callback( 'before_runtests', $aggregate );    $aggregate->start;    $self->aggregate_tests( $aggregate, @tests );    $aggregate->stop;    $self->formatter->summary($aggregate);    $self->_make_callback( 'after_runtests', $aggregate );    return $aggregate;}sub _after_test {    my ( $self, $aggregate, $test, $parser ) = @_;    $self->_make_callback( 'after_test', $test, $parser );    $aggregate->add( $test->[1], $parser );}sub _aggregate_forked {    my ( $self, $aggregate, @tests ) = @_;    eval { require Parallel::Iterator };    croak "Parallel::Iterator required for --fork option ($@)"      if $@;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -