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);
20 local $ENV{HARNESS_ACTIVE} = 0;
23 # Can't use Test.pm, that's a 5.005 thing.
27 my $TB = Test::Builder->create;
28 $TB->plan(tests => 73);
30 # Utility testing functions.
36 my($this, $that, $name) = @_;
38 my $ok = $TB->is_eq($$this, $that, $name);
46 my($this, $regex, $name) = @_;
47 $regex = "/$regex/" if !ref $regex and $regex !~ m{^/.*/$}s;
49 my $ok = $TB->like($$this, $regex, $name);
58 Test::More->import(tests => 11, import => ['is_deeply']);
60 my $Filename = quotemeta $0;
63 ok !is_deeply('foo', 'bar', 'plain strings');
64 is( $out, "not ok 1 - plain strings\n", 'plain strings' );
65 is( $err, <<ERR, ' right diagnostic' );
66 # Failed test 'plain strings'
74 ok !is_deeply({}, [], 'different types');
75 is( $out, "not ok 2 - different types\n", 'different types' );
76 like( $err, <<ERR, ' right diagnostic' );
77 # Failed test 'different types'
78 # at $Filename line 78.
79 # Structures begin differing at:
80 # \\\$got = HASH\\(0x[0-9a-f]+\\)
81 # \\\$expected = ARRAY\\(0x[0-9a-f]+\\)
85 ok !is_deeply({ this => 42 }, { this => 43 }, 'hashes with different values');
86 is( $out, "not ok 3 - hashes with different values\n",
87 'hashes with different values' );
88 is( $err, <<ERR, ' right diagnostic' );
89 # Failed test 'hashes with different values'
91 # Structures begin differing at:
92 # \$got->{this} = '42'
93 # \$expected->{this} = '43'
97 ok !is_deeply({ that => 42 }, { this => 42 }, 'hashes with different keys');
98 is( $out, "not ok 4 - hashes with different keys\n",
99 'hashes with different keys' );
100 is( $err, <<ERR, ' right diagnostic' );
101 # Failed test 'hashes with different keys'
103 # Structures begin differing at:
104 # \$got->{this} = Does not exist
105 # \$expected->{this} = '42'
109 ok !is_deeply([1..9], [1..10], 'arrays of different length');
110 is( $out, "not ok 5 - arrays of different length\n",
111 'arrays of different length' );
112 is( $err, <<ERR, ' right diagnostic' );
113 # Failed test 'arrays of different length'
115 # Structures begin differing at:
116 # \$got->[9] = Does not exist
117 # \$expected->[9] = '10'
121 ok !is_deeply([undef, undef], [undef], 'arrays of undefs' );
122 is( $out, "not ok 6 - arrays of undefs\n", 'arrays of undefs' );
123 is( $err, <<ERR, ' right diagnostic' );
124 # Failed test 'arrays of undefs'
126 # Structures begin differing at:
128 # \$expected->[1] = Does not exist
132 ok !is_deeply({ foo => undef }, {}, 'hashes of undefs' );
133 is( $out, "not ok 7 - hashes of undefs\n", 'hashes of undefs' );
134 is( $err, <<ERR, ' right diagnostic' );
135 # Failed test 'hashes of undefs'
137 # Structures begin differing at:
138 # \$got->{foo} = undef
139 # \$expected->{foo} = Does not exist
143 ok !is_deeply(\42, \23, 'scalar refs');
144 is( $out, "not ok 8 - scalar refs\n", 'scalar refs' );
145 is( $err, <<ERR, ' right diagnostic' );
146 # Failed test 'scalar refs'
148 # Structures begin differing at:
150 # \${\$expected} = '23'
154 ok !is_deeply([], \23, 'mixed scalar and array refs');
155 is( $out, "not ok 9 - mixed scalar and array refs\n",
156 'mixed scalar and array refs' );
157 like( $err, <<ERR, ' right diagnostic' );
158 # Failed test 'mixed scalar and array refs'
159 # at $Filename line 151.
160 # Structures begin differing at:
161 # \\\$got = ARRAY\\(0x[0-9a-f]+\\)
162 # \\\$expected = SCALAR\\(0x[0-9a-f]+\\)
167 $a1 = \$a2; $a2 = \$a3;
171 $b1 = \$b2; $b2 = \$b3;
175 ok !is_deeply($a1, $b1, 'deep scalar refs');
176 is( $out, "not ok 10 - deep scalar refs\n", 'deep scalar refs' );
177 is( $err, <<ERR, ' right diagnostic' );
178 # Failed test 'deep scalar refs'
180 # Structures begin differing at:
181 # \${\${ \$got}} = '42'
182 # \${\${\$expected}} = '23'
185 # I don't know how to properly display this structure.
186 # $a2 = { foo => \$a3 };
187 # $b2 = { foo => \$b3 };
188 # is_deeply([$a1], [$b1], 'deep mixed scalar refs');
192 that => { up => "down", left => "right" },
197 that => { up => "down", left => "right", foo => 42 },
201 ok !is_deeply( $foo, $bar, 'deep structures' );
202 ok( @Test::More::Data_Stack == 0, '@Data_Stack not holding onto things' );
203 is( $out, "not ok 11 - deep structures\n", 'deep structures' );
204 is( $err, <<ERR, ' right diagnostic' );
205 # Failed test 'deep structures'
207 # Structures begin differing at:
208 # \$got->{that}{foo} = Does not exist
209 # \$expected->{that}{foo} = '42'
216 [qw(42 23), qw(42 23)]
219 foreach my $test (@tests) {
220 my $num_args = @$test;
223 local $SIG{__WARN__} = sub { $warning .= join '', @_; };
224 ok !is_deeply(@$test);
227 "/^is_deeply\\(\\) takes two or three args, you gave $num_args\.\n/";
233 ok !is_deeply([{Foo => undef}],[{Foo => ""}]), 'undef != ""';
234 ok( @Test::More::Data_Stack == 0, '@Data_Stack not holding onto things' );
240 ok !is_deeply($a, $a.''), "don't compare refs like strings";
241 ok !is_deeply([$a], [$a.'']), " even deep inside";
246 ok !is_deeply( {}, {key => []} ), '[] could match non-existent values';
247 ok !is_deeply( [], [[]] );
252 ok !is_deeply( [\'a', 'b'], [\'a', 'c'] );
253 is( $out, "not ok 20\n", 'scalar refs in an array' );
254 is( $err, <<ERR, ' right diagnostic' );
255 # Failed test at $0 line 274.
256 # Structures begin differing at:
258 # \$expected->[1] = 'c'
264 ok !is_deeply( 23, $ref );
265 is( $out, "not ok 21\n", 'scalar vs ref' );
266 is( $err, <<ERR, ' right diagnostic');
267 # Failed test at $0 line 286.
268 # Structures begin differing at:
274 ok !is_deeply( $ref, 23 );
275 is( $out, "not ok 22\n", 'ref vs scalar' );
276 is( $err, <<ERR, ' right diagnostic');
277 # Failed test at $0 line 296.
278 # Structures begin differing at:
284 ok !is_deeply( undef, [] );
285 is( $out, "not ok 23\n", 'is_deeply and undef [RT 9441]' );
286 like( $err, <<ERR, ' right diagnostic' );
287 # Failed test at $Filename line 306\\.
288 # Structures begin differing at:
290 # \\\$expected = ARRAY\\(0x[0-9a-f]+\\)
300 ok !is_deeply( $array, $hash );
301 is( $out, "not ok 24\n", 'is_deeply and different reference types' );
302 is( $err, <<ERR, ' right diagnostic' );
303 # Failed test at $0 line 321.
304 # Structures begin differing at:
310 ok !is_deeply( [$array], [$hash] );
311 is( $out, "not ok 25\n", 'nested different ref types' );
312 is( $err, <<ERR, ' right diagnostic' );
313 # Failed test at $0 line 332.
314 # Structures begin differing at:
315 # \$got->[0] = $array
316 # \$expected->[0] = $hash
320 # Overloaded object tests
322 my $foo = bless [], "Foo";
323 my $bar = bless {}, "Bar";
327 "overload"->import(q[""] => sub { "wibble" });
331 ok !is_deeply( [$foo], [$bar] );
332 is( $out, "not ok 26\n", 'string overloaded refs respected in diag' );
333 is( $err, <<ERR, ' right diagnostic' );
334 # Failed test at $0 line 353.
335 # Structures begin differing at:
337 # \$expected->[0] = 'wibble'
347 ok !is_deeply( sub {"foo"}, sub {"bar"} ), 'function refs';
348 is( $out, "not ok 27\n" );
349 like( $err, <<ERR, ' right diagnostic' );
350 # Failed test at $Filename line 349.
351 # Structures begin differing at:
352 # \\\$got = CODE\\(0x[0-9a-f]+\\)
353 # \\\$expected = CODE\\(0x[0-9a-f]+\\)
362 ok !is_deeply( $glob1, $glob2 ), 'typeglobs';
363 is( $out, "not ok 28\n" );
364 like( $err, <<ERR, ' right diagnostic' );
365 # Failed test at $Filename line 357.
366 # Structures begin differing at:
367 # \\\$got = GLOB\\(0x[0-9a-f]+\\)
368 # \\\$expected = GLOB\\(0x[0-9a-f]+\\)