Skip to content

Test output blocks until test class is finished #100

@Ovid

Description

@Ovid

Consider the following code:

#!/usr/bin/env perl

package TestExample {
    use Test::Class::Moose;

    sub test_method {
        ok 'first';
        ok 'second';
        sleep 10;
        ok 'third';
    }
}
use Test::Class::Moose::Runner;
Test::Class::Moose::Runner->new->runtests;

That prints out:

1..1
ok 1 - TestExample {
    1..1
    ok 1 - test_method {
        ok 1
        ok 2
        ok 3
        1..3
    }
}
ok
All tests successful.
Files=1, Tests=1, 11 wallclock secs ( 0.02 usr  0.00 sys +  0.33 cusr  0.03 csys =  0.38 CPU)
Result: PASS

But I see none of that output until after the test class is completed (note the sleep 10). We have some extremely long running tests and sometimes it's nice to run them in verbose mode, but this means our tests hang and then we get a huge dump of output instead of seeing things as they go along.

Compare to this Test::More code:

#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;

subtest 'TestExample' => sub {
    subtest "test_method" => sub {
        ok 'first';
        ok 'second';
        sleep 10;
        ok 'third';
    };
};
done_testing;

That prints out:

# Subtest: TestExample
    # Subtest: test_method
        ok 1
        ok 2
        ok 3
        1..3
    ok 1 - test_method
    1..1
ok 1 - TestExample
1..1
ok
All tests successful.
Files=1, Tests=1, 10 wallclock secs ( 0.02 usr  0.00 sys +  0.07 cusr  0.01 csys =  0.10 CPU)
Result: PASS

But the first output shows up before the sleep. Why is Test::Class::Moose output blocking until the end of the test class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions