tassert_c.nim 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. matrix: "-d:nimPreviewSlimSystem --stackTrace:on --excessiveStackTrace:off"
  3. output: '''true'''
  4. """
  5. import std/assertions
  6. const expected = """
  7. tassert_c.nim(35) tassert_c
  8. tassert_c.nim(34) foo
  9. assertions.nim(*) failedAssertImpl
  10. assertions.nim(*) raiseAssert
  11. """
  12. proc tmatch(x, p: string): bool =
  13. var i = 0
  14. var k = 0
  15. while i < p.len:
  16. if p[i] == '*':
  17. let oldk = k
  18. while k < x.len and x[k] in {'0'..'9'}: inc k
  19. # no digit skipped?
  20. if oldk == k: return false
  21. inc i
  22. elif k < x.len and p[i] == x[k]:
  23. inc i
  24. inc k
  25. else:
  26. return false
  27. while k < x.len and x[k] in {' ', '\L', '\C'}: inc k
  28. result = i >= p.len and k >= x.len
  29. try:
  30. proc foo() =
  31. assert(false)
  32. foo()
  33. except AssertionDefect:
  34. let e = getCurrentException()
  35. let trace = e.getStackTrace
  36. if tmatch(trace, expected): echo true
  37. else: echo "wrong trace:\n" & trace