authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-03-07 15:26:51+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-03-07 15:30:59+02:00
log2d286100ef7ae87a71af1ace0002398d405e33d2
treedc7991099dec4f9b5bfcd8e3e8799ac08abd85f4
parent93f8110e5d9ca7e3ac81b33edd38709fac2c6acd
signature Commit is signed but in an unrecognized format.

stage1: add tests for nosuspend async/resume


1 files changed, 63 insertions(+), 1 deletions(-)

test/stage1/behavior/async_fn.zig+63-1
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
2const builtin = std.builtin;
33const expect = std.testing.expect;
44const expectEqual = std.testing.expectEqual;
55const expectEqualStrings = std.testing.expectEqualStrings;
......@@ -1545,6 +1545,68 @@ test "nosuspend on function calls" {
15451545 expectEqual(@as(i32, 42), (try nosuspend S1.d()).b);
15461546}
15471547
1548test "nosuspend on async function calls" {
1549 const S0 = struct {
1550 b: i32 = 42,
1551 };
1552 const S1 = struct {
1553 fn c() S0 {
1554 return S0{};
1555 }
1556 fn d() !S0 {
1557 return S0{};
1558 }
1559 };
1560 var frame_c = nosuspend async S1.c();
1561 expectEqual(@as(i32, 42), (await frame_c).b);
1562 var frame_d = nosuspend async S1.d();
1563 expectEqual(@as(i32, 42), (try await frame_d).b);
1564}
1565
1566// test "resume nosuspend async function calls" {
1567// const S0 = struct {
1568// b: i32 = 42,
1569// };
1570// const S1 = struct {
1571// fn c() S0 {
1572// suspend;
1573// return S0{};
1574// }
1575// fn d() !S0 {
1576// suspend;
1577// return S0{};
1578// }
1579// };
1580// var frame_c = nosuspend async S1.c();
1581// resume frame_c;
1582// expectEqual(@as(i32, 42), (await frame_c).b);
1583// var frame_d = nosuspend async S1.d();
1584// resume frame_d;
1585// expectEqual(@as(i32, 42), (try await frame_d).b);
1586// }
1587
1588test "nosuspend resume async function calls" {
1589 const S0 = struct {
1590 b: i32 = 42,
1591 };
1592 const S1 = struct {
1593 fn c() S0 {
1594 suspend;
1595 return S0{};
1596 }
1597 fn d() !S0 {
1598 suspend;
1599 return S0{};
1600 }
1601 };
1602 var frame_c = async S1.c();
1603 nosuspend resume frame_c;
1604 expectEqual(@as(i32, 42), (await frame_c).b);
1605 var frame_d = async S1.d();
1606 nosuspend resume frame_d;
1607 expectEqual(@as(i32, 42), (try await frame_d).b);
1608}
1609
15481610test "avoid forcing frame alignment resolution implicit cast to *c_void" {
15491611 const S = struct {
15501612 var x: ?*c_void = null;