This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The in-memory files require PerlIO::scalar.
[perl5.git] / lib / perl5db / dumpvar.t
1 #!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     unless (find PerlIO::Layer 'perlio') { # PerlIO::scalar
7         print "1..0 # Skip: not perlio\n";
8         exit 0;
9     }
10 }
11
12 use strict;
13
14 $|=1;
15 undef $/;
16 my @prgs = split "########\n", <DATA>;
17 close DATA;
18 print "1..", scalar @prgs, "\n";
19 require "dumpvar.pl";
20
21 my $i = 0;
22 for (@prgs){
23     my($prog,$expected) = split(/\nEXPECT\n?/, $_);
24     open my $select, ">", \my $got or die;
25     select $select;
26     eval $prog;
27     my $not = "";
28     my $why = "";
29     if ($@) {
30         $not = "not ";
31         $why = " # prog[$prog]\$\@[$@]";
32     } elsif ($got ne $expected) {
33         $not = "not ";
34         $why = " # prog[$prog]got[$got]expected[$expected]";
35     }
36     close $select;
37     select STDOUT;
38     print $not, "ok ", ++$i, $why, "\n";
39 }
40
41 __END__
42 "";
43 EXPECT
44 ########
45 dumpValue(1);
46 EXPECT
47 1
48 ########
49 dumpValue("1\n2\n3");
50 EXPECT
51 '1
52 2
53 3'
54 ########
55 dumpValue([1..3],1);
56 EXPECT
57 0  1
58 1  2
59 2  3
60 ########
61 dumpValue({1..4},1);
62 EXPECT
63 1 => 2
64 3 => 4
65 ########