New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash and new features in unittest #4639
Conversation
For example, in `check meth == httpPOST` write `meth was httpGET` but not `httpPOST was httpPOST`.
I've added a few simple improvements to the unittest module. Seems GitHub added them to my bugfix pull request, hope that is OK.
I've tried to find any unintended side effects, but so far these changes seem OK and backwards-compatible. Here is a test case (the first two tests fail on purpose, the last doesn't compile without patch): import unittest
type
Car = object
color: Color
passengers: seq[string] not nil
Color = object
name: string not nil
HttpMethod = enum
httpGET, httpPOST
suite "ShowsFeatures":
test "Shows fields on failure":
let c = Car(color:Color(name:"blue"), passengers: @["Anne", "Bob"])
check c.color.name == "red"
check c.passengers[0] == "Anna"
test "Supresses constants on failure":
let meth = httpGET
check meth == httpPOST
test "Allow let in check":
let x = 3
check:
x == 3
let square = x*x
square == 9 Here is the output with patch
|
@@ -270,6 +284,10 @@ macro check*(conditions: untyped): untyped = | |||
var paramAst = exp[i] | |||
if exp[i].kind == nnkIdent: | |||
argsPrintOuts.add getAst(print(argStr, paramAst)) | |||
if exp[i].kind == nnkDotExpr: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a case exp[i]
here please.
Please also add the test case. The testing framework is not really documented, but you can look at over 500 examples to figure it out. :-) |
Thanks for the review. I also just found out that there is a builtin Once I figure out how to write a test that passes if it actually fails but doesn't crash, I'll add the test. |
This is really nice, thank you for your contribution! For the future, it's helpful to create a new branch for each PR. That way you can work on other things in another branch, and not worry about an older PR including your new commits. |
@jdmansour Did you have the time to fix the issues here? |
No feedback. Closing. |
The following unit test crashes currently:
The reason is that the unittest module just checks wheter
string($str)
compiles, and then prints out$str
even ifstr
isnil
. I've added a check fornil
and it doesn't crash anymore.Maybe long term it should use something like
repr
instead of$
, which handlesnil
and also adds quotation marks. I didn't use it here because it also prepends the memory address, which I didn't want in the test output.