add heap allocated async function frame test

This commit is contained in:
Andrew Kelley 2019-08-02 16:32:24 -04:00
parent b3b6a98451
commit 5bd330e76c
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -333,3 +333,27 @@ async fn testBreakFromSuspend(my_result: *i32) void {
suspend;
my_result.* += 1;
}
test "heap allocated async function frame" {
const S = struct {
var x: i32 = 42;
fn doTheTest() !void {
const frame = try std.heap.direct_allocator.create(@Frame(someFunc));
defer std.heap.direct_allocator.destroy(frame);
expect(x == 42);
frame.* = async someFunc();
expect(x == 43);
resume frame;
expect(x == 44);
}
fn someFunc() void {
x += 1;
suspend;
x += 1;
}
};
try S.doTheTest();
}