tfailedassert_stacktrace.nim 847 B

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