tstringnil.nim 1.2 KB

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