Skip to content

Commit

Permalink
Test dynamic vars work in Promise.then
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Jun 4, 2017
1 parent 65a0dc5 commit e5d144e
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions S17-promise/then.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 14;
plan 15;

{
my $run_then = 0;
Expand All @@ -15,7 +15,7 @@ plan 14;
});
isa-ok $p2, Promise, "then returns a Promise";
is $run_then, 0, "Not run then yet";

$p1.keep(42);
is $p2.result, 101, "Got correct result from then Promise";
ok $run_then, "Certainly ran the then";
Expand All @@ -29,7 +29,7 @@ plan 14;
is $res.cause.message, "we fail it", "Got correct cause";
"oh noes"
});

$p1.break("we fail it");
is $p2.result, "oh noes", "Got correct result from then Promise";
}
Expand All @@ -46,3 +46,29 @@ plan 14;
is $p2.status, Broken, "then Promise is broken";
is $p2.cause.message, "then died", "then Promise has correct cause";
}

# RT #131509
subtest 'dynamics accessible from .then' => {
plan 4;

my @code;
my $*FOO; my @*FOO; my %*FOO;
my &*FOO = { @code.push: $_ };

await start {
$*FOO ~= 'prom';
@*FOO.push: 'prom';
%*FOO<prom> = 42;
&*FOO('prom');
}.then: {
$*FOO ~= 'then';
@*FOO.push: 'then';
%*FOO<then> = 72;
&*FOO('then');
}

is-deeply $*FOO, 'promthen', '$*FOO';
is-deeply @*FOO, [<prom then>], '@*FOO';
is-deeply %*FOO, {:42prom, :72then}, '%*FOO';
is-deeply @code, [<prom then>], '&*FOO';
}

0 comments on commit e5d144e

Please sign in to comment.