This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move Config test.
[perl5.git] / lib / perl5db / dumpvar.t
CommitLineData
fafebdf5
A
1#!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
e8c07a23
JH
6 unless (find PerlIO::Layer 'perlio') { # PerlIO::scalar
7 print "1..0 # Skip: not perlio\n";
8 exit 0;
9 }
fafebdf5
A
10}
11
12use strict;
13
14$|=1;
96b31d9e
JH
15
16my @prgs;
17{
18 local $/;
19 @prgs = split "########\n", <DATA>;
20 close DATA;
21}
22
23use Test::More;
24
25plan tests => scalar @prgs;
26
fafebdf5
A
27require "dumpvar.pl";
28
f97a9a4b
JH
29sub unctrl { print dumpvar::unctrl($_[0]), "\n" }
30sub uniescape { print dumpvar::uniescape($_[0]), "\n" }
31sub stringify { print dumpvar::stringify($_[0]), "\n" }
32
33package Foo;
34
35sub new { my $class = shift; bless [ @_ ], $class }
36
37package Bar;
38
39sub new { my $class = shift; bless [ @_ ], $class }
40
41use overload '""' => sub { "Bar<@{$_[0]}>" };
42
43package main;
44
45my $foo = Foo->new(1..5);
46my $bar = Bar->new(1..5);
47
96b31d9e
JH
48for (@prgs) {
49 my($prog, $expected) = split(/\nEXPECT\n?/, $_);
f97a9a4b
JH
50 # TODO: dumpvar::stringify() is controlled by a pile of package
51 # dumpvar variables: $printUndef, $unctrl, $quoteHighBit, $bareStringify,
52 # and so forth. We need to test with various settings of those.
fafebdf5
A
53 open my $select, ">", \my $got or die;
54 select $select;
55 eval $prog;
96b31d9e 56 my $ERR = $@;
fafebdf5
A
57 close $select;
58 select STDOUT;
96b31d9e
JH
59 if ($ERR) {
60 ok(0, "$prog - $ERR");
61 } else {
f97a9a4b
JH
62 if ($expected =~ m:^/:) {
63 like($got, $expected, $prog);
64 } else {
65 is($got, $expected, $prog);
66 }
96b31d9e 67 }
fafebdf5
A
68}
69
70__END__
f97a9a4b
JH
71unctrl("A");
72EXPECT
73A
74########
75unctrl("\cA");
76EXPECT
77^A
78########
79uniescape("A");
80EXPECT
81A
82########
83uniescape("\x{100}");
84EXPECT
85\x{0100}
86########
87stringify(undef);
88EXPECT
89undef
90########
91stringify("foo");
92EXPECT
93'foo'
94########
95stringify("\cA");
96EXPECT
97"\cA"
98########
99stringify(*a);
100EXPECT
101*main::a
102########
103stringify(\undef);
104EXPECT
105/^'SCALAR\(0x[0-9a-f]+\)'$/i
106########
107stringify([]);
108EXPECT
109/^'ARRAY\(0x[0-9a-f]+\)'$/i
110########
111stringify({});
112EXPECT
113/^'HASH\(0x[0-9a-f]+\)'$/i
114########
115stringify(sub{});
116EXPECT
117/^'CODE\(0x[0-9a-f]+\)'$/i
118########
119stringify(\*a);
120EXPECT
121/^'GLOB\(0x[0-9a-f]+\)'$/i
122########
123stringify($foo);
124EXPECT
125/^'Foo=ARRAY\(0x[0-9a-f]+\)'$/i
126########
127stringify($bar);
128EXPECT
129/^'Bar=ARRAY\(0x[0-9a-f]+\)'$/i
130########
131dumpValue(undef);
132EXPECT
133undef
134########
fafebdf5
A
135dumpValue(1);
136EXPECT
1371
138########
f97a9a4b
JH
139dumpValue("\cA");
140EXPECT
141"\cA"
142########
143dumpValue("\x{100}");
144EXPECT
145'\x{0100}'
146########
fafebdf5
A
147dumpValue("1\n2\n3");
148EXPECT
149'1
1502
1513'
152########
153dumpValue([1..3],1);
154EXPECT
1550 1
1561 2
1572 3
158########
159dumpValue({1..4},1);
160EXPECT
1611 => 2
1623 => 4
163########
f97a9a4b
JH
164dumpValue($foo,1);
165EXPECT
1660 1
1671 2
1682 3
1693 4
1704 5
171########
172dumpValue($bar,1);
173EXPECT
1740 1
1751 2
1762 3
1773 4
1784 5
179########