From 20011a7a1c1f08644cd82a3c3e1d57cba9980695 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 9 Mar 2018 21:05:54 -0500 Subject: [PATCH] add behavior test for coroutine frame allocation failure --- test/cases/coroutines.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/cases/coroutines.zig b/test/cases/coroutines.zig index d5469a5d03..12235cf40b 100644 --- a/test/cases/coroutines.zig +++ b/test/cases/coroutines.zig @@ -130,3 +130,16 @@ fn early_seq(c: u8) void { early_points[early_seq_index] = c; early_seq_index += 1; } + +test "coro allocation failure" { + var failing_allocator = std.debug.FailingAllocator.init(std.debug.global_allocator, 0); + if (async(&failing_allocator.allocator) asyncFuncThatNeverGetsRun()) { + @panic("expected allocation failure"); + } else |err| switch (err) { + error.OutOfMemory => {}, + } +} + +async fn asyncFuncThatNeverGetsRun() void { + @panic("coro frame allocation should fail"); +}