Skip to content

Instantly share code, notes, and snippets.

@jberger
Created December 19, 2019 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/2a4387dcebdb8c155677797367cb4b96 to your computer and use it in GitHub Desktop.
Save jberger/2a4387dcebdb8c155677797367cb4b96 to your computer and use it in GitHub Desktop.
$ git diff
diff --git a/t/mojo/promise_async_await.t b/t/mojo/promise_async_await.t
index 049253e47..084ad8de3 100644
--- a/t/mojo/promise_async_await.t
+++ b/t/mojo/promise_async_await.t
@@ -79,6 +79,13 @@ async sub test_two {
return $text;
}
+async sub returns_promise {
+ return Mojo::Promise->new(sub{
+ my ($resolve, $reject) = @_;
+ Mojo::IOLoop->next_tick(sub{ $resolve->('value') });
+ });
+}
+
# Basic async/await
my $promise = test_one();
isa_ok $promise, 'Mojo::Promise', 'right class';
@@ -106,4 +113,9 @@ $tx = $ua->get('/five');
is $tx->res->code, 500, 'right code';
like $tx->res->body, qr/runaway too/, 'right content';
+# Async function body returning a promise
+$text = undef;
+returns_promise()->then(sub { $text = shift })->catch(sub { warn @_ })->wait;
+is $text, 'value', 'right content';
+
done_testing();
$ TEST_ALL=1 prove -lr t/mojo/promise_async_await.t
t/mojo/promise_async_await.t .. 1/? Can't locate object method "AWAIT_NEW_DONE" via package "Mojo::Promise" at t/mojo/promise_async_await.t line 82.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 just after 8.
t/mojo/promise_async_await.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 8 subtests passed
Test Summary Report
-------------------
t/mojo/promise_async_await.t (Wstat: 65280 Tests: 8 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
Files=1, Tests=8, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.29 cusr 0.03 csys = 0.35 CPU)
Result: FAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment