BioPerl-DB

 view release on metacpan or  search on metacpan

t/lib/Test/Harness/Straps.pm  view on Meta::CPAN

Initialize a new strap.

=cut

sub new {
    my $class = shift;
    my $self  = bless {}, $class;

    $self->_init;

    return $self;
}

=for private $strap->_init

  $strap->_init;

Initialize the internal state of a strap to make it ready for parsing.

=cut

sub _init {
    my($self) = shift;

    $self->{_is_vms}   = ( $^O eq 'VMS' );
    $self->{_is_win32} = ( $^O =~ /^(MS)?Win32$/ );
    $self->{_is_macos} = ( $^O eq 'MacOS' );
}

=head1 ANALYSIS

=head2 $strap->analyze( $name, \@output_lines )

    my $results = $strap->analyze($name, \@test_output);

Analyzes the output of a single test, assigning it the given C<$name>
for use in the total report.  Returns the C<$results> of the test.
See L<Results>.

C<@test_output> should be the raw output from the test, including
newlines.

=cut

sub analyze {
    my($self, $name, $test_output) = @_;

    my $it = Test::Harness::Iterator->new($test_output);
    return $self->_analyze_iterator($name, $it);
}


sub _analyze_iterator {
    my($self, $name, $it) = @_;

    $self->_reset_file_state;
    $self->{file} = $name;

    my $results = Test::Harness::Results->new;

    # Set them up here so callbacks can have them.
    $self->{totals}{$name} = $results;
    while( defined(my $line = $it->next) ) {
        $self->_analyze_line($line, $results);
        last if $self->{saw_bailout};
    }

    $results->set_skip_all( $self->{skip_all} ) if defined $self->{skip_all};

    my $passed =
        (($results->max == 0) && defined $results->skip_all) ||
        ($results->max &&
         $results->seen &&
         $results->max == $results->seen &&
         $results->max == $results->ok);

    $results->set_passing( $passed ? 1 : 0 );

    return $results;
}


sub _analyze_line {
    my $self = shift;
    my $line = shift;
    my $results = shift;

    $self->{line}++;

    my $linetype;
    my $point = Test::Harness::Point->from_test_line( $line );
    if ( $point ) {
        $linetype = 'test';

        $results->inc_seen;
        $point->set_number( $self->{'next'} ) unless $point->number;

        # sometimes the 'not ' and the 'ok' are on different lines,
        # happens often on VMS if you do:
        #   print "not " unless $test;
        #   print "ok $num\n";
        if ( $self->{lone_not_line} && ($self->{lone_not_line} == $self->{line} - 1) ) {
            $point->set_ok( 0 );
        }

        if ( $self->{todo}{$point->number} ) {
            $point->set_directive_type( 'todo' );
        }

        if ( $point->is_todo ) {
            $results->inc_todo;
            $results->inc_bonus if $point->ok;
        }
        elsif ( $point->is_skip ) {
            $results->inc_skip;
        }

        $results->inc_ok if $point->pass;

        if ( ($point->number > 100_000) && ($point->number > ($self->{max}||100_000)) ) {
            if ( !$self->{too_many_tests}++ ) {



( run in 1.126 second using v1.01-cache-2.11-cpan-0d23b851a93 )