1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Future;
use Future::AsyncAwait;
my $orig_cxstack_ix = Future::AsyncAwait::__cxstack_ix;
async sub identity
{
await $_[0];
}
# invoking async/await entirely from within a string eval
{
ok eval q{
my $f1 = Future->new;
my $f2 = identity( $f1 );
$f1->done( 1 );
$f2->get;
}, 'async/await from within string eval';
}
# await at string-eval level should be forbidden (RT126035)
{
my $ok;
my $e;
(async sub {
$ok = !eval q{await $_[0]};
$e = $@;
})->();
ok( $ok, 'await in string eval fails to compile' );
$ok and like( $e, qr/^await is not allowed inside string eval /, '' );
}
is( Future::AsyncAwait::__cxstack_ix, $orig_cxstack_ix,
'cxstack_ix did not grow during the test' );
done_testing;
|