blob: df408910ec827dfd99f28dbbbbb90c5c2c623c08 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# bug #1744
import macros
type
SuiteTest = object
suiteName: string
suiteDesc: string
testName: string
testDesc: string
testBlock: NimNode
proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: NimNode): tuple[tests: seq[SuiteTest]] {.compileTime.} =
var
tests:seq[SuiteTest] = @[]
for child in suiteBloc.children():
case $child[0].ident:
of "test":
var testObj = SuiteTest()
if suiteName.kind == nnkNilLit:
testObj.suiteName = ""
else:
testObj.suiteName = $suiteName
if suiteDesc.kind == nnkNilLit:
testObj.suiteDesc = ""
else:
testObj.suiteDesc = suiteDesc.strVal
testObj.testName = $child[1] # should not ever be nil
if child[2].kind == nnkNilLit:
testObj.testDesc = ""
else:
testObj.testDesc = child[2].strVal
testObj.testBlock = child[1]
tests.add(testObj)
else:
discard
return (tests: tests)
macro suite(suiteName, suiteDesc, suiteBloc: untyped): typed =
let contents = buildSuiteContents(suiteName, suiteDesc, suiteBloc)
# Test above
suite basics, "Description of such":
test(t5, ""):
assert false
|