[perl #46893] [TODO] [Perl] Complete test coverage of Parrot::Test

James Keenan via RT parrotbug-followup at parrotcode.org
Sat Dec 6 01:15:41 UTC 2008


Here's another bit of code in lib/Parrot::Test.pm that is currently
untested, is probably unreachable and is therefore non-DWIMming.

In internal sub _run_test_file(), there is the following block:

    # set up default description
    unless ($desc) {
        ( undef, my $file, my $line ) = caller();
        $desc = "($file line $line)";
    }

The intent of this block appears to be:  If one of our test authors
neglects to provide a description for a test, guarantee that a minimal
description is provided that looks like this:

  (lib/Parrot/Test.pm line 414)
  
Coverage analysis
(http://thenceforward.net/parrot/coverage/tperl/lib-Parrot-Test-pm.html)
indicates that the 'true' branch of the 'unless' is not (yet) tested. 
So, in the SVN testparrottest branch, I have added the following test to
the end of (a revised) t/perl/Parrot_Test.t:

$desc = '';
test_out("ok 1 - $desc");
pasm_output_is( <<'CODE', <<'OUTPUT', $desc );
    print "foo\n"
    endParrot::TestCODE
foo
OUTPUT
test_test($desc);

I would have expected that with an empty string assigned to $desc, the
value of $desc would have been altered to something like the default
description described above.  But all I got was:

ok 97 -

For debugging, I then threw some 'print STDERR' statements into the
testparrottest branch version of lib/Parrot/Test.pm:

    my ( $func, $code, $expected, $desc, %extra ) = @_;
my $incoming_desc_status;
if ($desc) {
    $incoming_desc_status++;
    print STDERR "desc:  $desc\n";
} else {
    print STDERR "desc is Perl-false\n";
}

# [snip]

    # set up default description
    unless ($desc) {
        ( undef, my $file, my $line ) = caller();
        $desc = "($file line $line)";
    }
unless ($incoming_desc_status) {
    if ($desc) {
        print STDERR "desc:  $desc\n";
    } else {
        print STDERR "desc is still Perl-false\n";
    }
}

I see that $desc is correctly assigned to, but that that doesn't change
the output of the test file:

desc:  (lib/Parrot/Test.pm line 416)
ok 97 -

I then re-examined sub _run_test_file and noted that nothing is done
with $desc inside that function after the 'unless' block shown above --
which means that the 'default description' block is currently useless.

Does my analysis seem correct?

If it is correct, then we have survived this far without the 'default
description' block.  In that case, is there any reason why I should not
delete it as I go about testing/refactoring Parrot::Test?

Thank you very much.
kid51



More information about the parrot-dev mailing list