Subject: | on_done() and on_fail() do not return the invocant in some cases |
I tested the behavior of on_done() and on_fail() methods with the
attached test script, and found out they do not return the invocant
Future object in the following cases.
- on_done() is called on already failed Future
- on_done() is called on already cancelled Future
- on_fail() is called on already done (succeeded) Future
- on_fail() is called on already cancelled Future
on_done() and on_fail() should always return the invocant.
By the way, the last test in the attached test script fails because of
the bug I reported in https://rt.cpan.org/Ticket/Display.html?id=84312
Subject: | test_return_invocant.t |
use strict;
use warnings;
use Future 0.11;
use Test::More;
use Test::Builder;
sub create_callback { sub {} }
sub create_future { Future->new }
sub test_invocant {
my ($f, $method, $arg, $label) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $die_test_message = "$method($arg) should not throw exception: $label";
eval {
is($f->$method($arg), $f, "$method($arg) should return the invocant: $label");
pass($die_test_message);
};
if($@) {
fail($die_test_message);
diag("Exception: $@");
}
}
foreach my $method (qw(on_done on_fail on_ready)) {
foreach my $arg_creator (\&create_callback, \&create_future) {
test_invocant(Future->new, $method, $arg_creator->(), "not ready");
test_invocant(Future->new->done, $method, $arg_creator->(), "done");
test_invocant(Future->new->fail("failure"), $method, $arg_creator->(), "failed");
test_invocant(Future->new->cancel(), $method, $arg_creator->(), "cancelled");
}
}
done_testing();