Test-More / Test2-Harness

Alternative to Test::Harness
Other
23 stars 26 forks source link

Tests fail if Linux::Inotify2 is not available #247

Closed ppisar closed 2 years ago

ppisar commented 2 years ago

Test2-Harness-1.000113 refactored preloading and introduced this bug: If Linux::Inotify2 is not installed, tests fail:

$ perl -Ilib t/integration/coverage.t
# Seeded srand with seed '20220324' from local date.
not ok 1 - yath test -It/integration/coverage/lib t/integration/coverage --ext=tx --cover-wr[...]UA6Bt.json -v {
    not ok 1 - Exit Value Check
    # Failed test 'Exit Value Check'
    # at t/integration/coverage.t line 16.
    # +-----+----+-------+
    # | GOT | OP | CHECK |
    # +-----+----+-------+
    # | 256 | eq | 0     |
    # +-----+----+-------+
    # Command = /usr/bin/perl /home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/scripts/yath -Dt/integration/coverage/lib -D/home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/lib test -I/home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/lib -It/integration/coverage/lib t/integration/coverage --ext=tx --cover-write=/tmp/v68HOUA6Bt.json -v
    # Exit = 256
    # ==== Output ====
    # (INTERNAL)     Can't call method "blocking" on unblessed reference at /home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/lib/Test2/Harness/Runner/Reloader.pm line 69.
    # (INTERNAL)     Can't call method "blocking" on unblessed reference at /home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/lib/Test2/Harness/Runner/Reloader.pm line 69.
    # (INTERNAL)     BEGIN failed--compilation aborted at /home/test/fedora/perl-Test2-Harness/Test2-Harness-1.000113/scripts/yath line 260.
    # 
    # No tests were seen!

The reason is in lib/Test2/Harness/Runner/Reloader.pm:

BEGIN {
    local $@;
    my $inotify = eval { require Linux::Inotify2; 1 };
    if ($inotify) {
    [...]
    }
    else {
        *USE_INOTIFY = sub() { 0 };
        *INOTIFY_MASK = sub() { 0 };
    }
}
[...]
sub reset {
    my $self = shift;
    delete $self->{+PID};
    $self->{+MONITORED} = {};
    $self->{+MONITOR_LOOKUP} = {};
    $self->{+WATCHER} = USE_INOTIFY ? Linux::Inotify2->new : {};
    $self->{+WATCHER}->blocking(0);
    delete $self->{+STAT_LAST_CHECKED};
}

If Linux::Inotify2 is cannot be loaded, USE_INOTIFY become 0, $self->{+WATCHER} initialized to an empty hashref {}, and then used to invoce a method blocking(0). That raises an exception.

ppisar commented 2 years ago

Fixed in 1.000114.