Skip to content

Commit

Permalink
Unroll a conditional in current_test().
Browse files Browse the repository at this point in the history
Simpler to return early for the getter case.
  • Loading branch information
schwern committed May 1, 2012
1 parent 0ebc23e commit 221d0d3
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions lib/Test/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1737,36 +1737,35 @@ sub current_test {

my $history = $self->history;

if( defined $num ) {
# If the test counter is being pushed forward fill in the details.
my $results = $history->results;

if( $num > @$results ) {
my $last_test_number = @$results ? @$results : 0;
$history->counter($last_test_number);

for my $test_number ( $last_test_number + 1 .. $num ) {
my $result = TB2::Result->new_result(
$self->_file_and_line,
pass => 1,
directives => [qw(unknown)],
reason => 'incrementing test number',
test_number => $test_number
);
$history->accept_event( $result );
}
}
# If backward, wipe history. Its their funeral.
elsif( $num < @$results ) {
$#{$results} = $num - 1;
# Being used as a getter.
return $history->counter unless defined $num;

# If the test counter is being pushed forward fill in the details.
my $results = $history->results;

if ( $num > @$results ) {
my $last_test_number = @$results ? @$results : 0;
$history->counter($last_test_number);

for my $test_number ( $last_test_number + 1 .. $num ) {
my $result = TB2::Result->new_result(
$self->_file_and_line,
pass => 1,
directives => [qw(unknown)],
reason => 'incrementing test number',
test_number => $test_number
);
$history->accept_event( $result );
}

$history->counter($num);
return;
}
else {
return $history->counter;
# If backward, wipe history. Its their funeral.
elsif ( $num < @$results ) {
$#{$results} = $num - 1;
}

$history->counter($num);

return;
}

=item B<is_passing>
Expand Down

0 comments on commit 221d0d3

Please sign in to comment.