Add explicit check for odd number of args to new and give a useful warning
[gitmo/Moose.git] / t / 010_basics / 022_buildargs_warning.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Moose qw( with_immutable );
8
9 use Test::Requires {
10     'Test::Output' => '0.01',
11 };
12
13 {
14     package Baz;
15     use Moose;
16 }
17
18 with_immutable {
19     stderr_like { Baz->new( x => 42, 'y' ) }
20     qr{\QThe new() method for Baz expects a hash reference or a key/value list. You passed an odd number of arguments at t/010_basics/022_buildargs_warning.t line \E\d+},
21         'warning when passing an odd number of args to new()';
22
23     stderr_unlike { Baz->new( x => 42, 'y' ) }
24     qr{\QOdd number of elements in anonymous hash},
25         'we suppress the standard warning from Perl for an odd number of elements in a hash';
26 }
27 'Baz';
28
29 done_testing;