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',
76 switches => [ '-Ilib', '-d:switchd_empty' ],
78 'sub foo { print qq _1\n_ }',
80 '*foo = sub { print qq _2\n_ };',
85 'Subroutine redefinition works in the debugger [perl #48332]',
88 # [rt.cpan.org #69862]
91 switches => [ '-Ilib', '-d:switchd_empty' ],
93 'sub DB::sub { goto &$DB::sub }',
94 'sub foo { print qq _1\n_ }',
95 'sub bar { print qq _2\n_ }',
96 'delete $::{foo}; eval { foo() };',
97 'my $bar = *bar; undef *bar; eval { &$bar };',
101 'Subroutines no longer found under their names can be called',
104 # [rt.cpan.org #69862]
107 switches => [ '-Ilib', '-d:switchd_empty' ],
109 'sub DB::sub { goto &$DB::sub }',
110 'sub foo { goto &bar::baz; }',
111 'sub bar::baz { print qq _ok\n_ }',
112 'delete $::{bar::::};',
117 'No crash when calling orphaned subroutine via goto &',
120 # test when DB::DB is seen but not defined [perl #114990]
123 switches => [ '-Ilib', '-d:nodb' ],
127 qr/^No DB::DB routine defined/,
128 "No crash when *DB::DB exists but not &DB::DB",
132 switches => [ '-Ilib' ],
133 prog => 'sub DB::DB; BEGIN { $^P = 0x22; } for(0..9){ warn }',
136 qr/^No DB::DB routine defined/,
137 "No crash when &DB::DB exists but isn't actually defined",
140 # [perl #115742] Recursive DB::DB clobbering its own pad
143 switches => [ '-Ilib' ],
144 progs => [ split "\n", <<'='
152 $^D |= 1 << 30; # allow recursive calls
154 print $x//q-u-, qq-\n-;
164 "Recursive DB::DB does not clobber its own pad",
170 switches => [ '-Ilib', '-d:switchd_empty' ],
171 prog => 'print @{q|_<-e|}',
173 qr "use Devel::switchd_empty;(?:BEGIN|\r?\nprint)",
174 # miniperl tacks a BEGIN block on to the same line
175 'Copy on write does not mangle ${"_<-e"}[0] [perl #118627]',