Skip to content

Commit

Permalink
Followup to change 34979. Tests are good, m'kay. Particularly when they
Browse files Browse the repository at this point in the history
show you that something you thought worked doesn't.
Sadly it's not possible to trivially make it work, so for now they're
todo_skip().

p4raw-id: //depot/perl@34981
  • Loading branch information
nwc10 committed Dec 2, 2008
1 parent 925cfbb commit 83fca67
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
4 changes: 4 additions & 0 deletions perl.h
Expand Up @@ -5347,7 +5347,9 @@ typedef struct am_table_short AMTS;
#define PERLDBf_NAMEANON 0x200 /* Informative names for anon subs */
#define PERLDBf_SAVESRC 0x400 /* Save source lines into @{"_<$filename"} */
#define PERLDBf_SAVESRC_NOSUBS 0x800 /* Including evals that generate no subrouties */
#if 0 /* Not yet working. */
#define PERLDBf_SAVESRC_INVALID 0x1000 /* Save source that did not compile */
#endif

#define PERLDB_SUB (PL_perldb && (PL_perldb & PERLDBf_SUB))
#define PERLDB_LINE (PL_perldb && (PL_perldb & PERLDBf_LINE))
Expand All @@ -5361,7 +5363,9 @@ typedef struct am_table_short AMTS;
#define PERLDB_NAMEANON (PL_perldb && (PL_perldb & PERLDBf_NAMEANON))
#define PERLDB_SAVESRC (PL_perldb && (PL_perldb & PERLDBf_SAVESRC))
#define PERLDB_SAVESRC_NOSUBS (PL_perldb && (PL_perldb & PERLDBf_SAVESRC_NOSUBS))
#if 0 /* Not yet working. */
#define PERLDB_SAVESRC_INVALID (PL_perldb && (PL_perldb & PERLDBf_SAVESRC_INVALID))
#endif

#ifdef USE_LOCALE_NUMERIC

Expand Down
11 changes: 10 additions & 1 deletion pp_ctl.c
Expand Up @@ -3733,7 +3733,16 @@ PP(pp_entereval)
if (ok ? (was != PL_breakable_sub_gen /* Some subs defined here. */
? (PERLDB_LINE || PERLDB_SAVESRC)
: PERLDB_SAVESRC_NOSUBS)
: PERLDB_SAVESRC_INVALID) {
: 0 /* PERLDB_SAVESRC_INVALID */
/* Much that I'd like to think that it was this trivial to add this
feature, it's not, due to
lex_end();
LEAVE;
in S_doeval() for the failure case. So really we want a more
sophisticated way of (optionally) clearing the source code.
Particularly as the current way is buggy, as a syntactically
invalid eval string can still define a subroutine that is retained,
and the user may wish to breakpoint. */) {
/* Just need to change the string in our writable scratch buffer that
will be used at scope exit to delete this eval's "file" name, to
something safe. The key names are of the form "_<(eval 1)" upwards,
Expand Down
62 changes: 46 additions & 16 deletions t/comp/retainedlines.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {

use strict;

plan (tests => 21);
plan (tests => 55);

$^P = 0xA;

Expand All @@ -19,17 +19,9 @@ my @before = grep { /eval/ } keys %::;
is (@before, 0, "No evals");

my %seen;
my $name = 'foo';

for my $sep (' ', "\0") {

my $prog = "sub $name {
'Perl${sep}Rules'
};
1;
";

eval $prog or die;
sub check_retained_lines {
my ($prog, $name) = @_;
# Is there a more efficient way to write this?
my @expect_lines = (undef, map ({"$_\n"} split "\n", $prog), "\n", ';');

Expand All @@ -39,19 +31,57 @@ for my $sep (' ', "\0") {

my @got_lines = @{$::{$keys[0]}};

is (@got_lines, @expect_lines, "Right number of lines for " . ord $sep);
is (@got_lines, @expect_lines, "Right number of lines for $name");

for (0..$#expect_lines) {
is ($got_lines[$_], $expect_lines[$_], "Line $_ is correct");
}
$seen{$keys[0]}++;
}

my $name = 'foo';

for my $sep (' ', "\0") {

my $prog = "sub $name {
'Perl${sep}Rules'
};
1;
";

eval $prog or die;
check_retained_lines($prog, ord $sep);
$name++;
}

is (eval '1 + 1', 2, 'String eval works');
foreach my $flags (0x0, 0x800, 0x1000, 0x1800) {
local $^P = $^P | $flags;
# This is easier if we accept that the guts eval will add a trailing \n
# for us
my $prog = "1 + 1 + 1\n";
my $fail = "1 + \n";

is (eval $prog, 3, 'String eval works');
if ($flags & 0x800) {
check_retained_lines($prog, sprintf "%#X", $^P);
} else {
my @after = grep { /eval/ } keys %::;

is (@after, 0 + keys %seen,
"evals that don't define subroutines are correctly cleaned up");
}

my @after = grep { /eval/ } keys %::;
is (eval $fail, undef, 'Failed string eval fails');

is (@after, 0 + keys %seen,
"evals that don't define subroutines are correctly cleaned up");
if ($flags & 0x1000) {
TODO: {
todo_skip "Can't yet retain lines for evals with syntax errors", 6;
check_retained_lines($fail, sprintf "%#X", $^P);
}
} else {
my @after = grep { /eval/ } keys %::;

is (@after, 0 + keys %seen,
"evals that fail are correctly cleaned up");
}
}

0 comments on commit 83fca67

Please sign in to comment.