Documents idetools skMacro with failure test case.

This commit is contained in:
Grzegorz Adam Hankiewicz 2013-07-06 20:00:12 +02:00
commit baf4f8c9eb
3 changed files with 53 additions and 1 deletions

View file

@ -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()