From 1598471ed23a6e1aa60cca7601df1f3429dee223 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 21 Dec 2023 15:52:16 +0100 Subject: [PATCH] add a test for `results.?` compatibility (#484) Finally! (haha) --- tests/testmacro.nim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/testmacro.nim b/tests/testmacro.nim index 01337937..9b19c689 100644 --- a/tests/testmacro.nim +++ b/tests/testmacro.nim @@ -555,3 +555,27 @@ suite "Exceptions tracking": await raiseException() waitFor(callCatchAll()) + + test "Results compatibility": + proc returnOk(): Future[Result[int, string]] {.async: (raises: []).} = + ok(42) + + proc returnErr(): Future[Result[int, string]] {.async: (raises: []).} = + err("failed") + + proc testit(): Future[Result[void, string]] {.async: (raises: []).} = + let + v = await returnOk() + + check: + v.isOk() and v.value() == 42 + + let + vok = ?v + check: + vok == 42 + + discard ?await returnErr() + + check: + waitFor(testit()).error() == "failed"