Added recursive object printing. Bumped version up!
This commit is contained in:
parent
e3d27fa550
commit
74846335b5
3 changed files with 70 additions and 9 deletions
48
README.md
48
README.md
|
|
@ -133,6 +133,7 @@ is this:
|
|||
Condition: check(self.returnTrue())
|
||||
Where:
|
||||
self.returnTrue() -> false
|
||||
self -> ref UnitTestsNew(testObj: 90, name: UnitTestsNew, currentTestName: testMoreMore, testsPassed: 2, numTests: 4)
|
||||
Location: test.nim; line 59
|
||||
|
||||
|
||||
|
|
@ -153,12 +154,13 @@ is this:
|
|||
Condition: check(self.returnTrue())
|
||||
Where:
|
||||
self.returnTrue() -> false
|
||||
self -> ref UnitTestsNew(testObj: 90, name: TestInherit, currentTestName: testMoreMore, testsPassed: 2, numTests: 4)
|
||||
Location: test.nim; line 59
|
||||
|
||||
[Failed] testRaises
|
||||
Condition: checkRaises(OSError, self.raisesOs())
|
||||
Where:
|
||||
self.raisesOs() -> Exception
|
||||
self.raisesOs() -> SystemError
|
||||
Location: test.nim; line 72
|
||||
|
||||
|
||||
|
|
@ -184,30 +186,66 @@ is this:
|
|||
Condition: check(self.returnTrue())
|
||||
Where:
|
||||
self.returnTrue() -> false
|
||||
self -> ref UnitTestsNew(testObj: 12345, name: MoreInheritance, currentTestName: testMoreMore, testsPassed: 1, numTests: 4)
|
||||
Location: test.nim; line 59
|
||||
|
||||
[Failed] testRaises
|
||||
Condition: checkRaises(OSError, self.raisesOs())
|
||||
Where:
|
||||
self.raisesOs() -> Exception
|
||||
self.raisesOs() -> SystemError
|
||||
Location: test.nim; line 72
|
||||
|
||||
[OK] testTestObj
|
||||
[OK] testNewObj
|
||||
[Failed] testRefObject
|
||||
Condition: check(d == k)
|
||||
Where:
|
||||
k -> ref TestObj(t: 30)
|
||||
d -> ref TestObj(t: 3)
|
||||
Location: test.nim; line 123
|
||||
|
||||
[Failed] testObject
|
||||
Condition: check(d == k)
|
||||
Where:
|
||||
k -> TestObj(t: 30)
|
||||
d -> TestObj(t: 3)
|
||||
Location: test.nim; line 138
|
||||
|
||||
[Failed] testComplexObject
|
||||
Condition: check(x.isObj(p))
|
||||
Where:
|
||||
x.isObj(p) -> false
|
||||
p -> 4
|
||||
x -> Obj2(d: Obj1(e: Hey))
|
||||
Location: test.nim; line 150
|
||||
|
||||
[Failed] testTuple
|
||||
Condition: check(t == r)
|
||||
Where:
|
||||
r -> tuple Person(name: P, age: 3)
|
||||
t -> tuple Person(name: Peter, age: 30)
|
||||
Location: test.nim; line 161
|
||||
|
||||
[Failed] testComplex
|
||||
Condition: check(self.doStuff(a, s) == "5stuff" and self.doStuff(a, self.doStuff(a, self.doStuff(y, s))) == "something?")
|
||||
Condition: check(self.doStuff(a, s) == "5stuff" and self.doStuff(a, self.doStuff(a, self.doStuff(y, s))) == "something?")
|
||||
Where:
|
||||
self.doStuff(a, s) -> 5stuff
|
||||
a -> 5
|
||||
self -> ref MoreInheritance(testObj: 12345, name: MoreInheritance, currentTestName: testComplex, testsPassed: 3, numTests: 12)
|
||||
self.doStuff(a, self.doStuff(a, self.doStuff(y, s))) -> 5545stuff
|
||||
y -> 45
|
||||
s -> stuff
|
||||
self.doStuff(y, s) -> 45stuff
|
||||
self.doStuff(a, self.doStuff(y, s)) -> 545stuff
|
||||
Location: test.nim; line 134
|
||||
Location: test.nim; line 169
|
||||
|
||||
|
||||
[3/8] tests passed for MoreInheritance. ----------------------------------------
|
||||
[3/12] tests passed for MoreInheritance. ---------------------------------------
|
||||
|
||||
|
||||
[Summary]
|
||||
|
||||
[8/24] tests passed.
|
||||
```
|
||||
|
||||
Notice that on failure, the test runner gives some useful information about the test in question. This is useful for determining why the test failed.
|
||||
|
|
|
|||
29
einheit.nim
29
einheit.nim
|
|
@ -35,11 +35,34 @@ proc `$`*[T](some:typedesc[T]): string = name(T)
|
|||
proc `$`*(s: ref object): string =
|
||||
result = ($type(s)).replace(":ObjectType", "") & $s[]
|
||||
|
||||
proc objToStr*[T: object](obj: T): string =
|
||||
result = $type(obj) & system.`$`(obj)
|
||||
template tupleObjToStr(obj): string {.dirty.} =
|
||||
var res = $type(obj)
|
||||
template helper(n) {.gensym.} =
|
||||
res.add("(")
|
||||
var firstElement = true
|
||||
for name, value in n.fieldPairs():
|
||||
if not firstElement:
|
||||
res.add(", ")
|
||||
res.add(name)
|
||||
res.add(": ")
|
||||
when (value is object or value is tuple):
|
||||
when (value is tuple):
|
||||
res.add("tuple " & $type(value))
|
||||
else:
|
||||
res.add($type(value))
|
||||
helper(value)
|
||||
else:
|
||||
res.add($value)
|
||||
firstElement = false
|
||||
res.add(")")
|
||||
helper(obj)
|
||||
res
|
||||
|
||||
proc objToStr*[T: object](obj: var T): string =
|
||||
tupleObjToStr(obj)
|
||||
|
||||
proc objToStr*[T: tuple](obj: T): string =
|
||||
result = "tuple " & $type(obj) & system.`$`(obj)
|
||||
result = "tuple " & tupleObjToStr(obj)
|
||||
|
||||
macro toString*(obj: typed): untyped =
|
||||
## this macro is to work around not being
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[Package]
|
||||
name = "einheit"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
author = "Joey Payne"
|
||||
description = "Tool for providing unit tests. Einheit is German for Unit."
|
||||
license = "MIT"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue