develooper Front page | perl.perl5.porters | Postings from January 2012

[RESEND] RFC: Refactoring the lib/perl5db.t test script (for the"perl -d" front-end).

Thread Next
From:
Shlomi Fish
Date:
January 8, 2012 08:42
Subject:
[RESEND] RFC: Refactoring the lib/perl5db.t test script (for the"perl -d" front-end).
Message ID:
20120108184249.2261da1b@lap.shlomifish.org
[ I originally sent this message between Christmas and New Year's Eve, and got
not reply, possibly due to the Winter's holidays. Resending again because it
seems most people returned. Hope you had enjoyable holidays/vacations! ]  

Hi all,

I've been adding tests to the Perl debugger in some of my github branches, such
as:

https://github.com/shlomif/perl/tree/perl-d-add-tests-5-while-cherry-picking-commits

I hope the remaining commits gets applied soon, but as I was adding the code
I noticed that I've been writing very similar code times and again:

[CODE]
{
    rc(<<'EOF');
&parse_options("NonStop=0 TTY=db.out LineInfo=db.out");

sub afterinit {
    push (@DB::typeahead,
    'n uncalled_subroutine()',
    'c',
    'q',
    );

}
EOF

    my $output = runperl(switches => [ '-d', ], stderr => 1, progfile =>
    '../lib/perl5db/t/uncalled-subroutine');

    like ($output, 
        qr/<1,2,3,4,5>\n/,
        'uncalled_subroutine was called after n EXPR()',
        );

}
[/CODE]

And:

[CODE]
# Tests for "T" (stack trace).
{
    rc(<<'EOF');
&parse_options("NonStop=0 TTY=db.out LineInfo=db.out");

sub afterinit {
    push (@DB::typeahead,
    'c baz',
    'T',
    'q',
    );

}
EOF

    my $prog_fn = '../lib/perl5db/t/rt-104168';
    my $output = runperl(switches => [ '-d', ], stderr => 1, progfile => 
$prog_fn,);

    my $re_text = join('',
        map {
        sprintf(
            "%s = %s\\(\\) called from file " .
            "'" . quotemeta($prog_fn) . "' line %s\\n",
            (map { quotemeta($_) } @$_)
            )
        } 
        (
            ['.', 'main::baz', 14,],
            ['.', 'main::bar', 9,],
            ['.', 'main::foo', 6]
        )
    );
    like(_out_contents(), 
        # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
        qr/^$re_text/ms,
        "T command test."
    );
}
[/CODE]

I've been thinking that it would be a good idea to refactor it into a class
where:

1. The @DB::typeahead commands will be given as a list of Perl strings, which
would be encoded and quoted in the call to rc().

2. There will be two fields for $output and _out_contents() with methods that
can be used to match them with regular expressions (ultimately calling like).

3. The final "q" command will be added by default with a flag to suppress it.

The topic of whether duplication in automated tests is a good idea is
controversial (see for example
http://tech.groups.yahoo.com/group/extremeprogramming/message/146255 ),
but I feel that a good API for testing the debugger will be a good idea here
and will facilitate writing subsequent tests.

What are your thoughts?

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Chuck Norris/etc. Facts - http://www.shlomifish.org/humour/bits/facts/

You can never truly appreciate The Gilmore Girls until you’ve watched it in
the original Klingon.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About