Domanda

I have a working Coro program which I'm writing test scripts for

This is a cut down version of how I'm trying to test

use Test::More ;#tests => 9;

BEGIN{
  use_ok( 'EV' ) || print "Bail out!\n";
  use_ok( 'Coro' ) || print "Bail out!\n";
  use_ok( 'AnyEvent' ) || print "Bail out!\n";
  use_ok( 'Coro::AnyEvent' ) || print "Bail out!\n";
}

my @coro;
push @coro, async sub{ok(Coro::AnyEvent::sleep(2), 'sleep')};

push @coro, async sub{ok (1 == 1, 'one equals one')};
push @coro, async sub{isnt (1, 2, 'one does not equal two')};
#push @coro, async sub{is(EV::unloop, undef, 'unloop')};

#EV::run;

map {ok($_->join, 'join')} @coro;

which gives me

t/coro-test.t .. 
ok 1 - use EV;
ok 2 - use Coro;
ok 3 - use AnyEvent;
ok 4 - use Coro::AnyEvent;
ok 5 - one equals one
ok 6 - one does not equal two
Undefined subroutine &main:: called at /usr/lib/perl5/Coro/AnyEvent.pm line 218.
Dubious, test returned 9 (wstat 2304, 0x900)
All 6 subtests passed 

Test Summary Report
-------------------
t/coro-test.t (Wstat: 2304 Tests: 6 Failed: 0)
  Non-zero exit status: 9
  Parse errors: No plan found in TAP output
 Files=1, Tests=6,  0 wallclock secs ( 0.02 usr  0.01 sys +  0.18 cusr  0.03 csys =  0.24 CPU)
Result: FAIL

My (real) program sets coroutines off then they sleep whist they have nothing to do so its not a contrived example.

Any help gratefully received. (I think the unloop and EV::run aren't required)

È stato utile?

Soluzione

I can't imagine a reason why Test::More wouldn't work, and in fact, it works for me with current versions of Coro and AnyEvent (and either EV or Perl as event backends).

I think your problem might be that Coro::AnyEvent::sleep returns something that Test::More doesn't like on your system. Assuming Coro::AnyEvent::sleep returns anything specific is looking for trouble anyway - the return value(s), if any, are undocumented, so expecting it to be something specific makes your program rely on undocumented behaviour, and failure is an expected outcome.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top