summary refs log tree commit diff stats
path: root/tests/caas/idetools_api.nim
diff options
context:
space:
mode:
authorGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-07-06 20:00:12 +0200
committerGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-07-06 20:00:12 +0200
commitbaf4f8c9ebcf542fad62275f1513fd7ed62e777d (patch)
tree8851cbcf5dcb1af9d5bec1d202dc4c4a272a598f /tests/caas/idetools_api.nim
parent383d047763a4ef336fca7e299dd36d0c71a29d58 (diff)
downloadNim-baf4f8c9ebcf542fad62275f1513fd7ed62e777d.tar.gz
Documents idetools skMacro with failure test case.
Diffstat (limited to 'tests/caas/idetools_api.nim')
-rw-r--r--tests/caas/idetools_api.nim30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim
index 351ec0583..7d27ffdf8 100644
--- a/tests/caas/idetools_api.nim
+++ b/tests/caas/idetools_api.nim
@@ -1,4 +1,4 @@
-import unicode, sequtils
+import unicode, sequtils, macros
 
 proc test_enums() =
   var o: Tfile
@@ -53,3 +53,31 @@ proc findVowelPosition(text: string) =
   echo found
 
 findVowelPosition("Zerg") # should output 1, position of vowel.
+
+macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
+  ## Expect docstrings
+  let exp = callsite()
+  template expectBody(errorTypes, lineInfoLit: expr,
+                      body: stmt): PNimrodNode {.dirty.} =
+    try:
+      body
+      assert false
+    except errorTypes:
+      nil
+
+  var body = exp[exp.len - 1]
+
+  var errorTypes = newNimNode(nnkBracket)
+  for i in countup(1, exp.len - 2):
+    errorTypes.add(exp[i])
+
+  result = getAst(expectBody(errorTypes, exp.lineinfo, body))
+
+proc err =
+  raise newException(EArithmetic, "some exception")
+
+proc testMacro() =
+  expect(EArithmetic):
+    err()
+
+testMacro()
' href='#n192'>192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289