Working on single assert.
This commit is contained in:
parent
80e8a1c8c5
commit
98ccabf9b4
2 changed files with 29 additions and 0 deletions
22
einheit.nim
22
einheit.nim
|
|
@ -19,6 +19,23 @@ import strutils
|
||||||
when not defined(ECMAScript):
|
when not defined(ECMAScript):
|
||||||
import terminal
|
import terminal
|
||||||
|
|
||||||
|
proc `$`*[T](ar: openarray[T]): string=
|
||||||
|
## Converts an array into a string
|
||||||
|
result = "["
|
||||||
|
if ar.len() > 0:
|
||||||
|
result &= $ar[0]
|
||||||
|
for i in 1..ar.len()-1:
|
||||||
|
result &= ", " & $ar[i]
|
||||||
|
result &= "]"
|
||||||
|
return result
|
||||||
|
|
||||||
|
proc `==`*[T](ar: openarray[T], ar2: openarray[T]): bool=
|
||||||
|
if len(ar) != len(ar2):
|
||||||
|
return false
|
||||||
|
for i in countup(0, ar.len()):
|
||||||
|
if ar[i] != ar2[i]:
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
|
||||||
type
|
type
|
||||||
TestSuite = ref object of RootObj
|
TestSuite = ref object of RootObj
|
||||||
|
|
@ -136,6 +153,9 @@ template assertRaises*(self: TestSuite, error: Exception,
|
||||||
|
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
template assert*(self: TestSuite, d: untyped, msg=""){.immediate.}=
|
||||||
|
assertTrue(self, d)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -183,6 +203,8 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
##
|
##
|
||||||
## when isMainModule:
|
## when isMainModule:
|
||||||
## einheit.runTests()
|
## einheit.runTests()
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
# object reference name inside methods.
|
# object reference name inside methods.
|
||||||
# ie: self, self
|
# ie: self, self
|
||||||
|
|
|
||||||
7
test.nim
7
test.nim
|
|
@ -3,6 +3,7 @@ import einheit
|
||||||
testSuite UnitTests:
|
testSuite UnitTests:
|
||||||
var
|
var
|
||||||
testObj: int
|
testObj: int
|
||||||
|
testArray: array[4, int]
|
||||||
|
|
||||||
proc doThings()=
|
proc doThings()=
|
||||||
# This proc won't be invoked as a test
|
# This proc won't be invoked as a test
|
||||||
|
|
@ -11,6 +12,8 @@ testSuite UnitTests:
|
||||||
|
|
||||||
method setup()=
|
method setup()=
|
||||||
self.testObj = 90
|
self.testObj = 90
|
||||||
|
for i in 0 ..< self.testArray.len():
|
||||||
|
self.testArray[i] = i
|
||||||
|
|
||||||
method tearDown()=
|
method tearDown()=
|
||||||
self.testObj = 0
|
self.testObj = 0
|
||||||
|
|
@ -20,6 +23,9 @@ testSuite UnitTests:
|
||||||
self.doThings()
|
self.doThings()
|
||||||
self.assertTrue(4 == 4)
|
self.assertTrue(4 == 4)
|
||||||
|
|
||||||
|
method testArrayAssert()=
|
||||||
|
self.assertTrue(self.testArray == [0,1,2])
|
||||||
|
|
||||||
method testForC()=
|
method testForC()=
|
||||||
var c = 0
|
var c = 0
|
||||||
# supposed to fail
|
# supposed to fail
|
||||||
|
|
@ -44,6 +50,7 @@ testSuite UnitTestsNew:
|
||||||
|
|
||||||
method testMore()=
|
method testMore()=
|
||||||
self.assertEqual("String", "String")
|
self.assertEqual("String", "String")
|
||||||
|
self.assert 0 == 1
|
||||||
|
|
||||||
method testMoreMore()=
|
method testMoreMore()=
|
||||||
self.assertFalse("String" != "String")
|
self.assertFalse("String" != "String")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue