-
Notifications
You must be signed in to change notification settings - Fork 138
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
Introduce the Test.assertEqual
function
#2571
Introduce the Test.assertEqual
function
#2571
Conversation
This function has built-in support for showing the difference between the expected and the actual value.
Codecov Report
@@ Coverage Diff @@
## master #2571 +/- ##
=======================================
Coverage 78.54% 78.55%
=======================================
Files 336 336
Lines 77666 77704 +38
=======================================
+ Hits 61005 61042 +37
+ Misses 14386 14384 -2
- Partials 2275 2278 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Nice!
Label: sema.ArgumentLabelNotRequired, | ||
Identifier: "actual", | ||
TypeAnnotation: sema.NewTypeAnnotation( | ||
sema.AnyStructType, |
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.
I wonder if equality of two types could be enforced easily.
By that I mean that if types are not equal then the very first test execution is not going to pass anyway. So, its not something that important. On the other hand having comparisons of ints to strings fail at the compile time could've been nice too.
Also, may be there is already a check at the compile time that I've missed.
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.
import Test
pub fun test() {
Test.assertEqual(true, 1)
}
We have such a test, and the assertion error is the following:
assertion failed: not equal: expected: true, actual: 1
But since the assertEqual
method should work for any sub-type of AnyStruct
, this is the expected behavior.
On the other-hand, for types that do not support equality, e.g resources, we also have a test case:
import Test
pub fun test() {
let f1 <- create Foo()
let f2 <- create Foo()
Test.assertEqual(<-f1, <-f2)
}
pub resource Foo {}
And it fails with:
errs := checker.RequireCheckerErrors(t, err, 2)
assert.IsType(t, &sema.TypeMismatchError{}, errs[0])
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.
Right, cadence is interpreted language, my bad.
Great, that you've covered that in test. "not equal: expected: true, actual: 1" as discussed in PMs may be error message can specify that types differ.
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.
Although, commit is merged and I think this point is "matter of taste"/minor. So, fine for me either way.
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.
Great, thanks for pointing it out though 🙌
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.
All good!
Closes onflow/cadence-tools#93
Description
This function has built-in support for showing the difference between the expected and the actual value. For example:
master
branchFiles changed
in the Github PR explorer