Skip to content

Commit

Permalink
Merge pull request #570 from dumarchie/master
Browse files Browse the repository at this point in the history
Spectest for rakudo/rakudo#3137
  • Loading branch information
vrurg committed Sep 7, 2019
2 parents 618eefb + 04370f7 commit 3a4a84d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions S17-promise/single-assignment.t
@@ -0,0 +1,51 @@
use v6;
use Test;
plan 12;

my $exception = ::('X::Promise::Resolved');

{
my $promise = Promise.new;
my $vow = $promise.vow;

$vow.keep(1);
is $promise.status, Kept, 'Keeping a vow keeps the promise';
is $promise.result, 1, 'Keeping a vow assigns a result to the promise';

throws-like { $vow.keep(2) }, $exception, promise => $promise,
message => 'Cannot keep/break a Promise more than once (status: Kept)',
'Keeping a vow throws if the promise was Kept already';

is $promise.result, 1,
'Keeping a vow does not change the result of an already Kept promise';

throws-like { $vow.break(3) }, $exception, promise => $promise,
message => 'Cannot keep/break a Promise more than once (status: Kept)',
'Breaking a vow throws if the promise was Kept already';

is $promise.status, Kept,
'Breaking a vow does not change the status of an already Kept promise';
}

{
my $promise = Promise.new;
my $vow = $promise.vow;

$vow.break(1);
is $promise.status, Broken, 'Breaking a vow breaks the promise';
is $promise.cause, 1, 'Breaking a vow assigns a cause to the promise';

throws-like { $vow.break(2) }, $exception, promise => $promise,
message => 'Cannot keep/break a Promise more than once (status: Broken)',
'Breaking a vow throws if the promise was Broken already';

is $promise.cause, 1,
'Breaking a vow does not change the cause of an already Broken promise';

throws-like { $vow.keep(3) }, $exception, promise => $promise,
message => 'Cannot keep/break a Promise more than once (status: Broken)',
'Keeping a vow throws if the promise was Broken already';

is $promise.status, Broken,
'Keeping a vow does not change the status of an already Broken promise';
}
1 change: 1 addition & 0 deletions spectest.data
Expand Up @@ -876,6 +876,7 @@ S17-promise/in.t # slow
S17-promise/lock-async.t
S17-promise/lock-async-stress.t # moar stress slow
S17-promise/lock-async-stress2.t # moar stress slow
S17-promise/single-assignment.t
S17-promise/start.t # slow
S17-promise/stress.t # stress
S17-promise/then.t
Expand Down

0 comments on commit 3a4a84d

Please sign in to comment.