-
Notifications
You must be signed in to change notification settings - Fork 433
Fixed integer overflows for Foundation extensions #543
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
Fixed integer overflows for Foundation extensions #543
Conversation
|
Seems like the test has failed to be built on Linux. |
CHANGELOG.md
Outdated
| @@ -1,5 +1,6 @@ | |||
| # master | |||
| *Please add new entries at the top.* | |||
| Fixed integer overflow for `DispatchTimeInterval` in FoundationExtensions.swift (#506) | |||
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.
Please start the line with 1. .
|
Thank you for your work. 😸 |
|
Coming up with linux fix 👍 |
| expect((-DispatchTimeInterval.milliseconds(1)).timeInterval).to(beCloseTo(-0.001)) | ||
| expect((-DispatchTimeInterval.microseconds(1)).timeInterval).to(beCloseTo(-0.000001, within: 0.0000001)) | ||
| expect((-DispatchTimeInterval.nanoseconds(1)).timeInterval).to(beCloseTo(-0.000000001, within: 0.0000000001)) | ||
| expect((-DispatchTimeInterval.never).timeInterval) == Double.infinity |
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.
@andersio also if you don't mind I suggest changes to 3 particular test case expressions within this file. From my point of view, expect.to.equal syntax explicitly expresses expectation of equality when == operator makes people get inside Nimble and look for necessary overload to make sure whether expression is not false-positive.
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 thought this is Equatable based, and the stdlib floating point types already imply IEEE 754 compliant equality for ==.
Edit: Could you elaborate on why this has come up in your mind?
makes people get inside Nimble and look for necessary overload to make sure whether expression is not false-positive.
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.
Sure, the idea is following:
Using any kind of spec + expectation/matchers framework: (Kiwi, Specta/Expecta, Quick/Nimble) I expect the following pseudo-syntax line for test assertion:
expect(inspectable-expression) -> kind-of-expectation(to/notTo, eventually, eventuallyBeforeTimingOutAfter..) -> matcher-expression
All of mentioned above frameworks provide us with some DSL to set test expectations, so as a developer I expect an expectation (sorry for tautology) to be set using DSL. With Expecta I can write expect(someInt) == 0, and it won't warn me because I can compare returned object with 0 in Objective-C. But the test flow will be wrong, because it won't verify this against any matcher. Instead I should write expect(someInt).to.equal(0), which is correct in terms of its DSL.
Seeing expect((-DispatchTimeInterval.never).timeInterval) == Double.infinity in Swift makes me find whether its valid DSL syntax first. I get to https://github.com/Quick/Nimble/blob/master/Sources/Nimble/Matchers/Equal.swift#L172 and find that there's an implementation of == operator which makes lhs.to(equal(rhs) that I expected in the first place.
Maybe my confusion is connected with unsafe Objective-C background, where equality comparisons could be done mistakingly with reference arithmetics, and we should disregard it, however I would still wonder why to use operator == over matcher syntax for particular equality case. Especially, if this operator is implemented by calling matcher syntax.
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.
== are the fluent conveniences of the matchers that are meant to help reduce the verbosity AFAIK. It could be confusing for Swift newcomers with C family language background, but IMO it does make sense given equality and inequality in Swift are implemented as operators, with compile time overloading & type safety guarding for the problems you may otherwise encounter.
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.
No problem, bringing == syntax back. I don't have that strong opinion regarding this readability case, so knowing that's just a convenience matcher makes me fine with this approach. Also, I've checked Nimble matchers README and they show using operator == for equality matcher and === for identity matcher. Thus this point might be considered resolved?
|
@andersio for Linux build from Travis. Could you probably advice because I'm a bit stuck with what's going on with it... |
|
@soxjke That's an intermittent issue. Restarted the test. :( |
NachoSoto
left a comment
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.
Thanks!
Do you mind squashing/removing the last commit? 🙏
- Added overflow test case - Removed note on value limits for DispatchTimeInterval `*` operator - Updated CHANGELOG.md
…/jobs/291102863 - Update CHANGELOG.md
71b3e46 to
17fac49
Compare
|
@NachoSoto Sure, I've made overall feature history prettification and dropped also two "Update CHANGELOG.MD" commits as well. Hope Linux tests will succeed this time :) |
|
Probably need to re-run tests again, https://travis-ci.org/ReactiveCocoa/ReactiveSwift/jobs/291677337 suffers from the same failure as #544 |
timerfunction on specifying seconds interval greater than 21474.836471 #506) …*operatorChecklist