File: tassert_c.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (40 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
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
discard """
  matrix: "-d:nimPreviewSlimSystem --stackTrace:on --excessiveStackTrace:off"
  output: '''true'''
"""
import std/assertions
const expected = """
tassert_c.nim(35)        tassert_c
tassert_c.nim(34)        foo
assertions.nim(*)       failedAssertImpl
assertions.nim(*)       raiseAssert
"""

proc tmatch(x, p: string): bool =
  var i = 0
  var k = 0
  while i < p.len:
    if p[i] == '*':
      let oldk = k
      while k < x.len and x[k] in {'0'..'9'}: inc k
      # no digit skipped?
      if oldk == k: return false
      inc i
    elif k < x.len and p[i] == x[k]:
      inc i
      inc k
    else:
      return false
  while k < x.len and x[k] in {' ', '\L', '\C'}: inc k
  result = i >= p.len and k >= x.len


try:
  proc foo() =
    assert(false)
  foo()
except AssertionDefect:
  let e = getCurrentException()
  let trace = e.getStackTrace
  if tmatch(trace, expected): echo true
  else: echo "wrong trace:\n" & trace