1BEGIN { 2 require Config; 3 if (($Config::Config{'extensions'} !~ m!\bList/Util\b!) ){ 4 print "1..0 # Skip -- Perl configured without List::Util module\n"; 5 exit 0; 6 } 7 8 # `make test` in the CPAN version of this module runs us with -w, but 9 # Dumpvalue.pm relies on all sorts of things that can cause warnings. I 10 # don't think that's worth fixing, so we just turn off all warnings 11 # during testing. 12 $^W = 0; 13} 14 15use lib ("./t/lib"); 16use TieOut; 17use Test::More tests => 17; 18 19use_ok( 'Dumpvalue' ); 20 21my $d; 22ok( $d = Dumpvalue->new(), 'create a new Dumpvalue object' ); 23 24my $out = tie *OUT, 'TieOut'; 25select(OUT); 26 27my (@foobar, $x, $y); 28 29@foobar = ('foo', 'bar'); 30$d->dumpValue([@foobar]); 31$x = $out->read; 32is( $x, "0 'foo'\n1 'bar'\n", 'dumpValue worked on array ref' ); 33$d->dumpValues(@foobar); 34$y = $out->read; 35is( $y, "0 'foo'\n1 'bar'\n", 'dumpValues worked on array' ); 36is( $y, $x, 37 "dumpValues called on array returns same as dumpValue on array ref"); 38 39@foobar = (undef, 'bar'); 40$d->dumpValue([@foobar]); 41$x = $out->read; 42is( $x, "0 empty slot\n1 'bar'\n", 43 'dumpValue worked on array ref, first element undefined' ); 44$d->dumpValues(@foobar); 45$y = $out->read; 46is( $y, "0 empty slot\n1 'bar'\n", 47 'dumpValues worked on array, first element undefined' ); 48is( $y, $x, 49 "dumpValues called on array returns same as dumpValue on array ref, first element undefined"); 50 51@foobar = ('bar', undef); 52$d->dumpValue([@foobar]); 53$x = $out->read; 54is( $x, "0 'bar'\n1 empty slot\n", 55 'dumpValue worked on array ref, last element undefined' ); 56$d->dumpValues(@foobar); 57$y = $out->read; 58is( $y, "0 'bar'\n1 empty slot\n", 59 'dumpValues worked on array, last element undefined' ); 60is( $y, $x, 61 "dumpValues called on array returns same as dumpValue on array ref, last element undefined"); 62 63@foobar = ('', 'bar'); 64$d->dumpValue([@foobar]); 65$x = $out->read; 66is( $x, "0 ''\n1 'bar'\n", 67 'dumpValue worked on array ref, first element empty string' ); 68$d->dumpValues(@foobar); 69$y = $out->read; 70is( $y, "0 ''\n1 'bar'\n", 71 'dumpValues worked on array, first element empty string' ); 72is( $y, $x, 73 "dumpValues called on array returns same as dumpValue on array ref, first element empty string"); 74 75@foobar = ('bar', ''); 76$d->dumpValue([@foobar]); 77$x = $out->read; 78is( $x, "0 'bar'\n1 ''\n", 79 'dumpValue worked on array ref, last element empty string' ); 80$d->dumpValues(@foobar); 81$y = $out->read; 82is( $y, "0 'bar'\n1 ''\n", 83 'dumpValues worked on array, last element empty string' ); 84is( $y, $x, 85 "dumpValues called on array returns same as dumpValue on array ref, last element empty string"); 86 87