tassert_c.nim 900 B

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