perltestingperl-prove

Test fails under prove if it writes to stdout without newline


When I run a perl test using the prove utility, it fails if the method under test contains print statements that are not terminated by newlines.

use Test::More tests=>1;

ok(foo(), "calling foo");

sub foo{
    print "A";
    1;
}

This results in

Bad plan.  You planned 1 tests but ran 0.

If I append a newline: print "A\n"; the test passes.

(Note that if I simply execute the test perl mytest.t rather than using prove it passes either way).

Any ideas why this might be, and how to work around it?


Solution

  • I found a quick workaround:

    $|=0;     # no auto-flush
    

    ...but I have no idea (yet) why this works.