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:

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"; } }
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!

In reply to Test::More fails on foreach loop by Notdeadyet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.