HubFramework icon indicating copy to clipboard operation
HubFramework copied to clipboard

Use more appropriate asserts

Open cerihughes opened this issue 8 years ago • 6 comments

Always use XCTAssertEqualObjects when comparing objects for equality. XCTAssertEqual was causing some issues with NSIndexPath equality on 32 bit architectures (possibly because 64-bit architectures pool instances that are equal?)

cerihughes avatar Dec 22 '16 14:12 cerihughes

3 Messages
:book: Executed 339 tests, with 0 failures (0 unexpected) in 7.275 (8.472) seconds
:book: Executed 336 tests, with 0 failures (0 unexpected) in 7.320 (8.682) seconds
:book: Executed 9 tests, with 0 failures (0 unexpected) in 147.943 (147.952) seconds

Generated by :no_entry_sign: danger

spotify-ci-bot avatar Dec 22 '16 14:12 spotify-ci-bot

Current coverage is 93.43% (diff: 100%)

Merging #259 into master will increase coverage by 0.07%

@@             master       #259   diff @@
==========================================
  Files            72         72          
  Lines          5015       5015          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           4682       4686     +4   
+ Misses          333        329     -4   
  Partials          0          0          

Powered by Codecov. Last update b9852cb...bb26062

codecov-io avatar Dec 22 '16 14:12 codecov-io

@spotify/objc-dev

cerihughes avatar Dec 22 '16 14:12 cerihughes

@JohnSundell : I would assume that by default we'd want to be checking object equality in tests, unless we have a requirement that something returns the same instance under certain conditions. Only then would we want to test the actual instances.

The NSIndexPath case is a good example - on some platforms (for some reason) calls to factory methods will return different instances, and on other platforms they return the same instance (I haven't verified this, but it's one explanation for what's happening). Ultimately though, it shouldn't matter, as long as we use object equality, not instance equality as isEqualTo: will take care of all the differences for us.

Only fixing the cases with NSIndexPath because we know there are problems with that right now seems a bit broken, as the same issue could arise with other classes in future OS releases (as an example).

cerihughes avatar Dec 22 '16 15:12 cerihughes

@cerihughes NSIndexPaths of two elements are tagged pointers on 64-bit systems. Same sort of fun happens with short strings.

JensAyton avatar Dec 22 '16 15:12 JensAyton

@cerihughes I’m in favor of the changes made in this PR. Unless we explicitly want to check that two objects are the same instance we should use XCTAssertEqualObjects(obj1, obj2, desc, …).

Further I think we should, like you’re doing here, use XCTAssertTrue() with a description (or comment) when we actually want to check for instance equality. I’d also be fine with adding a function or macro like HUBAssertEqualInstances(ins1, ins2, desc, …) to make the code more self-explanatory.

rastersize avatar Jan 04 '17 20:01 rastersize