4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
16 require Test::Simple::Catch;
17 my($out, $err) = Test::Simple::Catch::caught();
18 Test::Builder->new->no_header(1);
19 Test::Builder->new->no_ending(1);
21 # Can't use Test.pm, that's a 5.005 thing.
27 # Utility testing functions.
29 my($this, $that, $name) = @_;
30 my $test = $$this eq $that;
32 $ok .= "not " unless $test;
33 $ok .= "ok $test_num";
34 $ok .= " - $name" if defined $name;
39 print "# got \n$$this";
40 print "# expected \n$that";
50 my($this, $regex, $name) = @_;
52 my $test = $$this =~ /$regex/;
55 $ok .= "not " unless $test;
56 $ok .= "ok $test_num";
57 $ok .= " - $name" if defined $name;
62 print "# got \n$$this";
63 print "# expected \n$regex";
75 Test::More->import(tests => 11, import => ['is_deeply']);
77 my $Filename = quotemeta $0;
80 is_deeply('foo', 'bar', 'plain strings');
81 is( $out, "not ok 1 - plain strings\n", 'plain strings' );
82 is( $err, <<ERR, ' right diagnostic' );
83 # Failed test ($0 at line 68)
90 is_deeply({}, [], 'different types');
91 is( $out, "not ok 2 - different types\n", 'different types' );
92 like( $err, <<ERR, ' right diagnostic' );
93 # Failed test \\($Filename at line 78\\)
94 # Structures begin differing at:
95 # \\\$got = 'HASH\\(0x[0-9a-f]+\\)'
96 # \\\$expected = 'ARRAY\\(0x[0-9a-f]+\\)'
100 is_deeply({ this => 42 }, { this => 43 }, 'hashes with different values');
101 is( $out, "not ok 3 - hashes with different values\n",
102 'hashes with different values' );
103 is( $err, <<ERR, ' right diagnostic' );
104 # Failed test ($0 at line 88)
105 # Structures begin differing at:
106 # \$got->{this} = '42'
107 # \$expected->{this} = '43'
111 is_deeply({ that => 42 }, { this => 42 }, 'hashes with different keys');
112 is( $out, "not ok 4 - hashes with different keys\n",
113 'hashes with different keys' );
114 is( $err, <<ERR, ' right diagnostic' );
115 # Failed test ($0 at line 99)
116 # Structures begin differing at:
117 # \$got->{this} = Does not exist
118 # \$expected->{this} = '42'
122 is_deeply([1..9], [1..10], 'arrays of different length');
123 is( $out, "not ok 5 - arrays of different length\n",
124 'arrays of different length' );
125 is( $err, <<ERR, ' right diagnostic' );
126 # Failed test ($0 at line 110)
127 # Structures begin differing at:
128 # \$got->[9] = Does not exist
129 # \$expected->[9] = '10'
133 is_deeply([undef, undef], [undef], 'arrays of undefs' );
134 is( $out, "not ok 6 - arrays of undefs\n", 'arrays of undefs' );
135 is( $err, <<ERR, ' right diagnostic' );
136 # Failed test ($0 at line 121)
137 # Structures begin differing at:
139 # \$expected->[1] = Does not exist
143 is_deeply({ foo => undef }, {}, 'hashes of undefs', 'hashes of undefs' );
144 is( $out, "not ok 7 - hashes of undefs\n", 'hashes of undefs' );
145 is( $err, <<ERR, ' right diagnostic' );
146 # Failed test ($0 at line 131)
147 # Structures begin differing at:
148 # \$got->{foo} = undef
149 # \$expected->{foo} = Does not exist
153 is_deeply(\42, \23, 'scalar refs');
154 is( $out, "not ok 8 - scalar refs\n", 'scalar refs' );
155 is( $err, <<ERR, ' right diagnostic' );
156 # Failed test ($0 at line 141)
157 # Structures begin differing at:
159 # \${\$expected} = '23'
163 is_deeply([], \23, 'mixed scalar and array refs');
164 is( $out, "not ok 9 - mixed scalar and array refs\n",
165 'mixed scalar and array refs' );
166 like( $err, <<ERR, ' right diagnostic' );
167 # Failed test \\($Filename at line 151\\)
168 # Structures begin differing at:
169 # \\\$got = 'ARRAY\\(0x[0-9a-f]+\\)'
170 # \\\$expected = 'SCALAR\\(0x[0-9a-f]+\\)'
175 $a1 = \$a2; $a2 = \$a3;
179 $b1 = \$b2; $b2 = \$b3;
183 is_deeply($a1, $b1, 'deep scalar refs');
184 is( $out, "not ok 10 - deep scalar refs\n", 'deep scalar refs' );
185 is( $err, <<ERR, ' right diagnostic' );
186 # Failed test ($0 at line 173)
187 # Structures begin differing at:
188 # \${\${ \$got}} = '42'
189 # \${\${\$expected}} = '23'
192 # I don't know how to properly display this structure.
193 # $a2 = { foo => \$a3 };
194 # $b2 = { foo => \$b3 };
195 # is_deeply([$a1], [$b1], 'deep mixed scalar refs');
199 that => { up => "down", left => "right" },
204 that => { up => "down", left => "right", foo => 42 },
208 is_deeply( $foo, $bar, 'deep structures' );
209 is( $out, "not ok 11 - deep structures\n", 'deep structures' );
210 is( $err, <<ERR, ' right diagnostic' );
211 # Failed test ($0 at line 198)
212 # Structures begin differing at:
213 # \$got->{that}{foo} = Does not exist
214 # \$expected->{that}{foo} = '42'