I am training to create a new module using Module :: Starter. I wrote some test cases for the package, and they sometimes work fine.
However, I noticed that there are two problems:
When test cases fail, I want to put some print statements in the function we are testing. I started make test, and he only informs me that my test cases failed, he does not display my print output, despite the fact that I am really sure that the print statements have been reached.
Let's say I have three test cases to test one function, I put a print statement inside the function, when the test cases start, it reports that only 1 out of three test cases was executed. If I delete the print statement, all three test cases will run. Why is this?
Here is my code:
sub get_in {
my ( $hash, @path ) = @_;
my $ref = $hash;
print 'lol';
foreach (@path) {
if ( ref($ref) eq 'HASH' && exists $ref->{$_} ) {
$ref = $ref->{$_};
} else {
return undef;
}
}
return $ref;
}
These are test cases:
use Test::More tests => 3;
use strict;
use warnings;
use diagnostics;
require_ok('Foo::Doc');
ok( Foo::Doc::get_in( { 'a' => { 'b' => { 'c' => 101 } } }, 'a', 'b', 'c' ) == 101 );
ok( @{ Foo::Doc::get_in( { 'a' => { 'b' => { 'c' => [ 1, 2, 3 ] } } }, 'a', 'b', 'c' ) } == @{ [ 1, 2, 3 ] } );
user972946
source
share