3 # Check that lines from eval are correctly retained by the debugger
17 my @before = grep { /eval/ } keys %::;
19 is (@before, 0, "No evals");
23 sub check_retained_lines {
24 my ($prog, $name) = @_;
25 # Is there a more efficient way to write this?
26 my @expect_lines = (undef, map ({"$_\n"} split "\n", $prog), "\n", ';');
28 my @keys = grep {!$seen{$_}} grep { /eval/ } keys %::;
30 is (@keys, 1, "1 new eval");
32 my @got_lines = @{$::{$keys[0]}};
34 is (@got_lines, @expect_lines, "Right number of lines for $name");
36 for (0..$#expect_lines) {
37 is ($got_lines[$_], $expect_lines[$_], "Line $_ is correct");
44 for my $sep (' ', "\0") {
46 my $prog = "sub $name {
53 check_retained_lines($prog, ord $sep);
58 # This contains a syntax error
59 my $prog = "sub $name {
67 is (eval "$name()", "This is $name", "Subroutine was compiled, despite error")
70 check_retained_lines($prog,
71 'eval that defines subroutine but has syntax error');
75 foreach my $flags (0x0, 0x800, 0x1000, 0x1800) {
76 local $^P = $^P | $flags;
77 # This is easier if we accept that the guts eval will add a trailing \n
79 my $prog = "1 + 1 + 1\n";
82 is (eval $prog, 3, 'String eval works');
84 check_retained_lines($prog, sprintf "%#X", $^P);
86 my @after = grep { /eval/ } keys %::;
88 is (@after, 0 + keys %seen,
89 "evals that don't define subroutines are correctly cleaned up");
92 is (eval $fail, undef, 'Failed string eval fails');
94 if ($flags & 0x1000) {
95 check_retained_lines($fail, sprintf "%#X", $^P);
97 my @after = grep { /eval/ } keys %::;
99 is (@after, 0 + keys %seen,
100 "evals that fail are correctly cleaned up");