authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-02 16:32:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-02 16:32:24-04:00
log5bd330e76c4b9bfc341dcba1732a8ac9277e133d
treea2b86dd5ec3cbc68b0ea66ac96a75cce06701318
parentb3b6a98451a9703dc15a1ee5f48acde23de3c491
signature Commit is signed but in an unrecognized format.

add heap allocated async function frame test


1 files changed, 24 insertions(+), 0 deletions(-)

test/stage1/behavior/coroutines.zig+24
...@@ -333,3 +333,27 @@ async fn testBreakFromSuspend(my_result: *i32) void {...@@ -333,3 +333,27 @@ async fn testBreakFromSuspend(my_result: *i32) void {
333 suspend;333 suspend;
334 my_result.* += 1;334 my_result.* += 1;
335}335}
336
337test "heap allocated async function frame" {
338 const S = struct {
339 var x: i32 = 42;
340
341 fn doTheTest() !void {
342 const frame = try std.heap.direct_allocator.create(@Frame(someFunc));
343 defer std.heap.direct_allocator.destroy(frame);
344
345 expect(x == 42);
346 frame.* = async someFunc();
347 expect(x == 43);
348 resume frame;
349 expect(x == 44);
350 }
351
352 fn someFunc() void {
353 x += 1;
354 suspend;
355 x += 1;
356 }
357 };
358 try S.doTheTest();
359}