I'm trying to start using the test harness (test::more) for the first time and I'm having what appears to me to be a strange test failure. The test fails on a for loop (if I take out the for loop it no longer fails). This happens even if I don't have the for loop do anything. The original function looks like:
sub parse { my ($self, $file_name) = @_; $self->{'_xbrl_file'} = $file_name; if ( -e $self->{'_xbrl_file'}) { my $parser = XML::LibXML->new(); my $dom = $parser->load_xml( location => $self->{'_xbrl_file'} +); #Deal with the contexts my @context_nodes = $dom->findnodes('/xbrli:xbrl/xbrli:context +'); foreach my $node (@context_nodes) { &add_context($self, $node); } } else { croak "$file_name doesn't exist"; } }
The test looks like:
ok($xbrl->parse($incoming_file));
In order to trouble shoot, I added some print statements (to a file) which results in the following code:
Changing the code so it writes out to file (and the file does in fact exist with the appropriate entries) causes the test to pass. I'm completely stumped and the usual sources (man Test::Tutorial) don't seem to cover this. Any help would be greatly appreciated. Thanks!sub parse { my ($self, $file_name) = @_; $self->{'_xbrl_file'} = $file_name; if ( -e $self->{'_xbrl_file'}) { my $parser = XML::LibXML->new(); my $dom = $parser->load_xml( location => $self->{'_xbrl_file'} +); #Deal with the contexts my @context_nodes = $dom->findnodes('/xbrli:xbrl/xbrli:context +'); open(FH, ">junk.txt") or croak "can't open junk.txt"; foreach my $node (@context_nodes) { print FH $node->toString(); # &add_context($self, $node); } close FH; } else { croak "$file_name doesn't exist"; } }
In reply to Test::More fails on foreach loop by Notdeadyet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |