Front page | perl.perl5.porters |
Postings from December 2011
RFC: Refactoring the lib/perl5db.t test script (for the "perl -d"front-end).
From:
Shlomi Fish
Date:
December 29, 2011 08:20
Subject:
RFC: Refactoring the lib/perl5db.t test script (for the "perl -d"front-end).
Message ID:
20111229182033.0f6e2285@lap.shlomifish.org
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 .
-
RFC: Refactoring the lib/perl5db.t test script (for the "perl -d"front-end).
by Shlomi Fish