a3ad5a7706fe8a3b781e542c471c05cbbbd420e6
[p5sagit/p5-mst-13.2.git] / lib / perl5db / de0.t
1 #!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
2
3 BEGIN {
4     require Config; import Config;
5     unless ($Config{d_fork}) {
6         print "1..0\n";
7         exit 0;
8     }
9     chdir 't' if -d 't';
10     @INC = '../lib';
11     $ENV{PERL5LIB} = '../lib';    # so children will see it too
12 }
13
14 use strict;
15 use IPC::Open3 qw(open3);
16 use IO::Select;
17
18 $|=1;
19
20 my @prgs;
21
22 {
23     local $/;
24     @prgs = split "########\n", <DATA>;
25     close DATA;
26 }
27
28 use Test::More;
29
30 plan tests => scalar @prgs;
31
32 require "dumpvar.pl";
33
34 $ENV{PERLDB_OPTS} = "TTY=0";
35 my($ornament1,$ornament2,$wtrfh,$rdrfh);
36 open3 $wtrfh, $rdrfh, 0, $^X, "-de0";
37 my $ios = IO::Select->new();
38 $ios->add($rdrfh);
39 for (@prgs){
40     my($prog,$expected) = split(/\nEXPECT\n?/, $_);
41     print $wtrfh $prog, "\n";
42     my $got;
43     while (not defined $got) {
44         while ($ios->can_read(0.25)) {
45             sysread $rdrfh, $got, 1024, length($got);
46         }
47     }
48     $got =~ s/^\s*Loading.*\nEditor.*\n\nEnter.*\n\nmain::\(-e:1\):\s0\n//;
49     unless (defined $ornament1) {
50          $got =~ s/^\s*Loading.*\nEditor.*\n\nEnter.*\n\nmain::\(-e:1\):\s0\n//;
51          ($ornament1,$ornament2) = $got =~
52              /(.*?)0\s+'reserved example for calibrating the ornaments'\n(.*)/
53     }
54     $got =~ s/^\Q$ornament1\E//;
55     $got =~ s/\Q$ornament2\E\z//;
56     like($got, qr:$expected:i, $prog);
57 }
58
59 __END__
60 x "reserved example for calibrating the ornaments"
61 EXPECT
62 0  'reserved example for calibrating the ornaments'
63 ########
64 x "foo"
65 EXPECT
66 0  'foo'
67 ########
68 x "\x{100}"
69 EXPECT
70 0  '\\x\{0100\}'
71 ########
72 x *a
73 EXPECT
74 0  \*main::a
75 ########
76 x 1..3
77 EXPECT
78 0  1
79 1  2
80 2  3
81 ########
82 x +{1..4}
83 EXPECT
84 0\s+HASH\(0x[0-9a-f]+\)
85 \s+1 => 2
86 \s+3 => 4
87 ########