Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 504
perlyking Avatar asked Nov 04 '22 07:11

perlyking


1 Answers

I found a quick workaround:

$|=0;     # no auto-flush

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

like image 51
kubanczyk Avatar answered Nov 10 '22 03:11

kubanczyk