summary refs log tree commit diff stats
path: root/tests/assert
diff options
context:
space:
mode:
Diffstat (limited to 'tests/assert')
-rw-r--r--tests/assert/panicoverride.nim15
-rw-r--r--tests/assert/t21195.nim6
-rw-r--r--tests/assert/tassert.nim2
-rw-r--r--tests/assert/tassert2.nim58
-rw-r--r--tests/assert/tassert_c.nim15
-rw-r--r--tests/assert/tdoassert.nim20
-rw-r--r--tests/assert/testhelper.nim12
-rw-r--r--tests/assert/trelativeassert.nim11
8 files changed, 51 insertions, 88 deletions
diff --git a/tests/assert/panicoverride.nim b/tests/assert/panicoverride.nim
new file mode 100644
index 000000000..53ad64215
--- /dev/null
+++ b/tests/assert/panicoverride.nim
@@ -0,0 +1,15 @@
+# panicoverride.nim
+
+proc printf(fmt: cstring) {.varargs, importc, header:"stdio.h".}
+proc exit(code: cint) {.importc, header:"stdlib.h".}
+
+{.push stack_trace: off, profiler:off.}
+
+proc rawoutput(s: cstring) =
+  printf("RAW: %s\n", s)
+  
+proc panic(s: cstring) {.noreturn.} =
+  printf("PANIC: %s\n", s)
+  exit(0)
+
+{.pop.}
\ No newline at end of file
diff --git a/tests/assert/t21195.nim b/tests/assert/t21195.nim
new file mode 100644
index 000000000..b690d22a0
--- /dev/null
+++ b/tests/assert/t21195.nim
@@ -0,0 +1,6 @@
+discard """
+  matrix: "--verbosity:0 --os:standalone --mm:none"
+"""
+# bug #21195
+var n = 11
+assert(n == 12)
diff --git a/tests/assert/tassert.nim b/tests/assert/tassert.nim
index 99929f080..a14fec317 100644
--- a/tests/assert/tassert.nim
+++ b/tests/assert/tassert.nim
@@ -10,7 +10,7 @@ proc callC() = callA()
 
 try:
   callC()
-except AssertionError:
+except AssertionDefect:
   write(stdout, "assertion failure!")
 except:
   write(stdout, "unknown exception!")
diff --git a/tests/assert/tassert2.nim b/tests/assert/tassert2.nim
index 50753ba11..e32ab72e1 100644
--- a/tests/assert/tassert2.nim
+++ b/tests/assert/tassert2.nim
@@ -1,59 +1,44 @@
 discard """
   output: '''
-test1:ok
-test2:ok
-test3:ok
-test4:ok
-test5:ok
-test6:ok
-test7:ok
+`false` first assertion from bar
+`false` second assertion from bar
 -1
-tassert2.nim
-test8:ok
-test9:ok
-test10:ok
-test11:ok
 '''
 """
-import testhelper
+from strutils import endsWith
+
 type
   TLineInfo = tuple[filename: string, line: int, column: int]
   TMyError = object of Exception
     lineinfo: TLineInfo
   EMyError = ref TMyError
 
-echo("")
 
 # NOTE: when entering newlines, adjust `expectedEnd` outputs
 
 try:
   doAssert(false, "msg1") # doAssert test
-except AssertionError as e:
-  checkMsg(e.msg, "tassert2.nim(30, 11) `false` msg1", "test1")
-
-try:
-  assert false, "msg2"  # assert test
-except AssertionError as e:
-  checkMsg(e.msg, "tassert2.nim(35, 10) `false` msg2", "test2")
+except AssertionDefect as e:
+  assert e.msg.endsWith "tassert2.nim(20, 11) `false` msg1"
 
 try:
   assert false # assert test with no msg
-except AssertionError as e:
-  checkMsg(e.msg, "tassert2.nim(40, 10) `false` ", "test3")
+except AssertionDefect as e:
+  assert e.msg.endsWith "tassert2.nim(25, 3) `false` "
 
 try:
   let a = 1
   doAssert(a+a==1) # assert test with Ast expression
   # BUG: const folding would make "1+1==1" appear as `false` in
   # assert message
-except AssertionError as e:
-  checkMsg(e.msg, "`a + a == 1` ", "test4")
+except AssertionDefect as e:
+  assert e.msg.endsWith "`a + a == 1` "
 
 try:
   let a = 1
   doAssert a+a==1 # ditto with `doAssert` and no parens
-except AssertionError as e:
-  checkMsg(e.msg, "`a + a == 1` ", "test5")
+except AssertionDefect as e:
+  assert e.msg.endsWith "`a + a == 1` "
 
 proc fooStatic() =
   # protect against https://github.com/nim-lang/Nim/issues/8758
@@ -80,12 +65,12 @@ block:
   proc bar: int =
     # local overrides that are active only in this proc
     onFailedAssert(msg):
-      checkMsg(msg, "tassert2.nim(85, 11) `false` first assertion from bar", "test6")
+      echo msg[^32..^1]
 
     assert(false, "first assertion from bar")
 
     onFailedAssert(msg):
-      checkMsg(msg, "tassert2.nim(91, 11) `false` second assertion from bar", "test7")
+      echo msg[^33..^1]
       return -1
 
     assert(false, "second assertion from bar")
@@ -97,8 +82,7 @@ block:
     foo()
   except:
     let e = EMyError(getCurrentException())
-    echo e.lineinfo.filename
-    checkMsg(e.msg, "tassert2.nim(77, 11) `false` assertion from foo", "test8")
+    assert e.msg.endsWith "tassert2.nim(62, 11) `false` assertion from foo"
 
 block: ## checks for issue https://github.com/nim-lang/Nim/issues/8518
   template fun(a: string): string =
@@ -107,21 +91,21 @@ block: ## checks for issue https://github.com/nim-lang/Nim/issues/8518
 
   try:
     doAssert fun("foo1") == fun("foo2"), "mymsg"
-  except AssertionError as e:
+  except AssertionDefect as e:
     # used to expand out the template instantiaiton, sometimes filling hundreds of lines
-    checkMsg(e.msg, """tassert2.nim(109, 14) `fun("foo1") == fun("foo2")` mymsg""", "test9")
+    assert e.msg.endsWith ""
 
 block: ## checks for issue https://github.com/nim-lang/Nim/issues/9301
   try:
     doAssert 1 + 1 == 3
-  except AssertionError as e:
+  except AssertionDefect as e:
     # used to const fold as false
-    checkMsg(e.msg, "tassert2.nim(116, 14) `1 + 1 == 3` ", "test10")
+    assert e.msg.endsWith "tassert2.nim(100, 5) `1 + 1 == 3` "
 
 block: ## checks AST isn't transformed as it used to
   let a = 1
   try:
     doAssert a > 1
-  except AssertionError as e:
+  except AssertionDefect as e:
     # used to rewrite as `1 < a`
-    checkMsg(e.msg, "tassert2.nim(124, 14) `a > 1` ", "test11")
+    assert e.msg.endsWith "tassert2.nim(108, 5) `a > 1` "
diff --git a/tests/assert/tassert_c.nim b/tests/assert/tassert_c.nim
index 84ccea823..e3e3b8147 100644
--- a/tests/assert/tassert_c.nim
+++ b/tests/assert/tassert_c.nim
@@ -1,14 +1,14 @@
 discard """
-  cmd: "nim $target $options --excessiveStackTrace:off $file"
+  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(27)       failedAssertImpl
-assertions.nim(20)       raiseAssert
-fatal.nim(55)            sysFatal"""
+assertions.nim(*)       failedAssertImpl
+assertions.nim(*)       raiseAssert
+"""
 
 proc tmatch(x, p: string): bool =
   var i = 0
@@ -33,7 +33,8 @@ try:
   proc foo() =
     assert(false)
   foo()
-except AssertionError:
+except AssertionDefect:
   let e = getCurrentException()
   let trace = e.getStackTrace
-  echo tmatch(trace, expected)
+  if tmatch(trace, expected): echo true
+  else: echo "wrong trace:\n" & trace
diff --git a/tests/assert/tdoassert.nim b/tests/assert/tdoassert.nim
deleted file mode 100644
index fa9893505..000000000
--- a/tests/assert/tdoassert.nim
+++ /dev/null
@@ -1,20 +0,0 @@
-discard """
-  cmd: "nim $target -d:release $options $file"
-  output: '''
-test1:ok
-test2:ok
-'''
-"""
-
-import testhelper
-
-onFailedAssert(msg):
-  checkMsg(msg, "tdoassert.nim(15, 9) `a == 2` foo", "test1")
-
-var a = 1
-doAssert(a == 2, "foo")
-
-onFailedAssert(msg):
-  checkMsg(msg, "tdoassert.nim(20, 10) `a == 3` ", "test2")
-
-doAssert a == 3
diff --git a/tests/assert/testhelper.nim b/tests/assert/testhelper.nim
deleted file mode 100644
index 03bdd2468..000000000
--- a/tests/assert/testhelper.nim
+++ /dev/null
@@ -1,12 +0,0 @@
-from strutils import endsWith, split
-from os import isAbsolute
-
-proc checkMsg*(msg, expectedEnd, name: string, absolute = true)=
-  let filePrefix = msg.split(' ', maxSplit = 1)[0]
-  if absolute and not filePrefix.isAbsolute:
-    echo name, ":not absolute: `", msg & "`"
-  elif not msg.endsWith expectedEnd:
-    echo name, ":expected suffix:\n`" & expectedEnd & "`\ngot:\n`" & msg & "`"
-  else:
-    echo name, ":ok"
-
diff --git a/tests/assert/trelativeassert.nim b/tests/assert/trelativeassert.nim
deleted file mode 100644
index 62ab2c421..000000000
--- a/tests/assert/trelativeassert.nim
+++ /dev/null
@@ -1,11 +0,0 @@
-discard """
-  cmd: "nim $target $options --excessiveStackTrace:off $file"
-  output: '''
-test:ok
-'''
-"""
-import testhelper
-try:
-  doAssert(false, "msg")
-except AssertionError as e:
-  checkMsg(e.msg, "trelativeassert.nim(9, 11) `false` msg", "test", false)