Skip to content

Conversation

@soxjke
Copy link
Contributor

@soxjke soxjke commented Oct 22, 2017

Checklist

  • Updated CHANGELOG.md.

@andersio
Copy link
Member

Seems like the test has failed to be built on Linux.

/home/travis/build/ReactiveCocoa/ReactiveSwift/Tests/ReactiveSwiftTests/FoundationExtensionsSpec.swift:102:59: error: cannot invoke 'equal' with an argument list of type '(DispatchTimeInterval)'
 expect(DispatchTimeInterval.seconds(Int.max) * 10).to(equal(DispatchTimeInterval.never))
 ^
/home/travis/build/ReactiveCocoa/ReactiveSwift/Tests/ReactiveSwiftTests/FoundationExtensionsSpec.swift:102:59: note: overloads for 'equal' exist with these partially matching parameter lists: (T?), ([T : C]?), ([T]?), ([T?]), (Set<T>?)
 expect(DispatchTimeInterval.seconds(Int.max) * 10).to(equal(DispatchTimeInterval.never))
 ^

CHANGELOG.md Outdated
@@ -1,5 +1,6 @@
# master
*Please add new entries at the top.*
Fixed integer overflow for `DispatchTimeInterval` in FoundationExtensions.swift (#506)
Copy link
Member

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. .

@andersio
Copy link
Member

Thank you for your work. 😸

@soxjke
Copy link
Contributor Author

soxjke commented Oct 22, 2017

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
Copy link
Contributor Author

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.

Copy link
Member

@andersio andersio Oct 22, 2017

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.

Copy link
Contributor Author

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.

Copy link
Member

@andersio andersio Oct 23, 2017

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.

Copy link
Contributor Author

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?

@soxjke
Copy link
Contributor Author

soxjke commented Oct 23, 2017

@andersio
I'm starting to receive

Test Case 'XCTestCase.MutableProperty, should not deadlock' started at 2017-10-23 08:37:59.778

for Linux build from Travis. Could you probably advice because I'm a bit stuck with what's going on with it...

@andersio
Copy link
Member

andersio commented Oct 23, 2017

@soxjke That's an intermittent issue. Restarted the test. :(

@soxjke
Copy link
Contributor Author

soxjke commented Oct 23, 2017

@andersio thanks!

I opened #544 to keep track on it. Probably, I'll run vagrant on a local machine to simulate this over weekend.

Other than that, do you see any changes needed more for this PR?

Copy link
Member

@NachoSoto NachoSoto left a 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
@soxjke soxjke force-pushed the issue-506-integer-overflow branch from 71b3e46 to 17fac49 Compare October 23, 2017 18:05
@soxjke
Copy link
Contributor Author

soxjke commented Oct 23, 2017

@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 :)

@soxjke
Copy link
Contributor Author

soxjke commented Oct 23, 2017

Probably need to re-run tests again, https://travis-ci.org/ReactiveCocoa/ReactiveSwift/jobs/291677337 suffers from the same failure as #544

@andersio andersio merged commit 91fd3f1 into ReactiveCocoa:master Oct 26, 2017
@soxjke soxjke deleted the issue-506-integer-overflow branch October 26, 2017 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants