8 BEGIN { require "./test.pl"; }
10 # This test depends on t/lib/Devel/switchd*.pm.
16 my $filename = tempfile();
18 open my $f, ">$filename"
19 or skip( "Can't write temp file $filename: $!" );
20 print $f <<'__SWDTEST__';
22 sub bar { $_[0] * $_[0] }
26 $s += Bar::bar($_) for 1..$_[0];
32 $| = 1; # Unbufferize.
34 switches => [ '-Ilib', '-f', '-d:switchd' ],
35 progfile => $filename,
39 qr/^sub<Devel::switchd::import>;import<Devel::switchd>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
40 'Got debugging output: 1');
42 switches => [ '-Ilib', '-f', '-d:switchd=a,42' ],
43 progfile => $filename,
47 qr/^sub<Devel::switchd::import>;import<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
48 'Got debugging output: 2');
50 switches => [ '-Ilib', '-f', '-d:-switchd=a,42' ],
51 progfile => $filename,
55 qr/^sub<Devel::switchd::unimport>;unimport<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/,
56 'Got debugging output: 3');
61 runperl( # less is useful for something :-)
62 switches => [ '"-Mless ++INC->{q-Devel/_.pm-}"' ],
65 'sub DB::DB{} print scalar @{q/_</.__FILE__}',
70 'The debugger can see the lines of the main program under #!perl -d',
75 switches => [ '"-Mless ++INC->{q-Devel/_.pm-}"' ],
78 'sub DB::DB{} print line=>__LINE__',
82 '#!perl -d:whatever does not throw line numbers off';
87 switches => [ '-Ilib', '-d:switchd_empty' ],
89 'sub foo { print qq _1\n_ }',
91 '*foo = sub { print qq _2\n_ };',
96 'Subroutine redefinition works in the debugger [perl #48332]',
99 # [rt.cpan.org #69862]
102 switches => [ '-Ilib', '-d:switchd_empty' ],
104 'sub DB::sub { goto &$DB::sub }',
105 'sub foo { print qq _1\n_ }',
106 'sub bar { print qq _2\n_ }',
107 'delete $::{foo}; eval { foo() };',
108 'my $bar = *bar; undef *bar; eval { &$bar };',
112 'Subroutines no longer found under their names can be called',
115 # [rt.cpan.org #69862]
118 switches => [ '-Ilib', '-d:switchd_empty' ],
120 'sub DB::sub { goto &$DB::sub }',
121 'sub foo { goto &bar::baz; }',
122 'sub bar::baz { print qq _ok\n_ }',
123 'delete $::{bar::::};',
128 'No crash when calling orphaned subroutine via goto &',
131 # test when DB::DB is seen but not defined [perl #114990]
134 switches => [ '-Ilib', '-d:nodb' ],
138 qr/^No DB::DB routine defined/,
139 "No crash when *DB::DB exists but not &DB::DB",
143 switches => [ '-Ilib' ],
144 prog => 'sub DB::DB; BEGIN { $^P = 0x22; } for(0..9){ warn }',
147 qr/^No DB::DB routine defined/,
148 "No crash when &DB::DB exists but isn't actually defined",
150 # or seen and defined later
153 switches => [ '-Ilib', '-d:nodb' ], # nodb.pm contains *DB::DB...if 0
154 prog => 'warn; sub DB::DB { print qq-ok\n-; exit }',
158 "DB::DB works after '*DB::DB if 0'",
161 # [perl #115742] Recursive DB::DB clobbering its own pad
164 switches => [ '-Ilib' ],
165 progs => [ split "\n", <<'='
173 $^D |= 1 << 30; # allow recursive calls
175 print $x//q-u-, qq-\n-;
185 "Recursive DB::DB does not clobber its own pad",
191 switches => [ '-Ilib', '-d:switchd_empty' ],
192 prog => 'print @{q|_<-e|}',
194 qr "use Devel::switchd_empty;(?:BEGIN|\r?\nprint)",
195 # miniperl tacks a BEGIN block on to the same line
196 'Copy on write does not mangle ${"_<-e"}[0] [perl #118627]',
199 # PERL5DB with embedded newlines
201 local $ENV{PERL5DB} = "sub DB::DB{}\nwarn";
204 switches => [ '-Ilib', '-ld' ],
208 "Warning: something's wrong.\n"
209 ."Warning: something's wrong at -e line 1.\n",
210 'PERL5DB with embedded newlines',
214 # test that DB::goto works
217 switches => [ '-Ilib', '-d:switchd_goto' ],
218 prog => 'sub baz { print qq|hello;\n| } sub foo { goto &baz } foo()',
221 "goto<main::baz>;hello;\n",
225 # Test that %DB::lsub is not vivified
228 switches => [ '-Ilib', '-d:switchd_empty' ],
229 progs => ['sub DB::sub {} sub foo : lvalue {} foo();',
230 'print qq-ok\n- unless defined *DB::lsub{HASH}'],
233 "%DB::lsub is not vivified"
236 # Test setting of breakpoints without *DB::dbline aliased
239 switches => [ '-Ilib', '-d:nodb' ],
240 progs => [ split "\n",
242 $DB::single = 0, return if $DB::single; print qq[ok\n]; exit
244 ${q(_<).__FILE__}{6} = 1; # set a breakpoint
254 "setting breakpoints without *DB::dbline aliased"
258 # Check that utf8 caches are flushed when $DB::sub is set
261 switches => [ '-Ilib', '-d:switchd_empty' ],
262 progs => [ split "\n",
263 'sub DB::sub{length($DB::sub); goto &$DB::sub}
266 eval qq|sub oo\x{25f} { 42 }
267 sub ooooo\x{25f} { oo\x{25f}() }
276 'UTF8 length caches on $DB::sub are flushed'
279 # [perl #122771] -d conflicting with sort optimisations
282 switches => [ '-Ilib', '-d:switchd_empty' ],
283 prog => 'BEGIN { $^P &= ~0x4 } sort { $$b <=> $$a } (); print qq-42\n-',
286 '-d does not conflict with sort optimisations'
291 switches => [ '-Ilib', '-d:switchd_empty' ],
292 progs => [ split "\n",
295 print qq/debugged\n/;
301 "\$DB::single set to overload"