summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorhuantian <davidtianli@gmail.com>2022-04-13 14:03:46 -0700
committerGitHub <noreply@github.com>2022-04-13 23:03:46 +0200
commitef7d7f24594b1ea560fbf25d3fa0d6c51122725f (patch)
tree15dc4511c81bc2a9ea366789d49a9f7862ed3d9f /tests
parent98cebad7debddfb147ee22bc6f3d81221582c4d6 (diff)
downloadNim-ef7d7f24594b1ea560fbf25d3fa0d6c51122725f.tar.gz
Better error message and tests for bad await (#19622)
* Better error message and tests for bad await

* Use compiles to check if await is valid

* temp: disable windows noasync test

* Better error report, simplify test

Co-authored-by: flywind <xzsflywind@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/async/tasync_noasync.nim35
1 files changed, 32 insertions, 3 deletions
diff --git a/tests/async/tasync_noasync.nim b/tests/async/tasync_noasync.nim
index 54f4f597f..0927148bf 100644
--- a/tests/async/tasync_noasync.nim
+++ b/tests/async/tasync_noasync.nim
@@ -1,13 +1,42 @@
 discard """
-  errormsg: "'yield' only allowed in an iterator"
-  cmd: "nim c $file"
-  file: "asyncmacro.nim"
+  cmd: "nim check --hints:off --warnings:off $file"
+  action: "reject"
+  nimout: '''
+tasync_noasync.nim(21, 10) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(25, 12) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(28, 10) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(31, 10) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(35, 10) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(38, 10) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+tasync_noasync.nim(40, 8) Error: Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead
+'''
 """
 import async
 
 proc a {.async.} =
   discard
 
+# Bad await usage
+proc nonAsyncProc =
+  await a()
+
+proc nestedNonAsyncProc {.async.} =
+  proc nested =
+    await a()
+
+iterator customIterator: int =
+  await a()
+
+macro awaitInMacro =
+  await a()
+
+type DummyRef = ref object of RootObj
+method awaitInMethod(_: DummyRef) {.base.} =
+  await a()
+
+proc improperMultisync {.multisync.} =
+  await a()
+
 await a()
 
 # if we overload a fallback handler to get