[SERVER-57713] Teach unittest macros to usefully compare with nullptr Created: 15/Jun/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: George Wangensteen Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: sa-remove-fv-backlog-22
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:

 Description   

Sometimes in unittests, you'd like to check that a pointer is nullptr.

You can't use the comparison macros like: ASSERT_EQ(ptr, nullptr) because none of the overloads satisfy: we can't use the one made for pointers here because nullptr is not a pointer according to std::is_pointer, and we can't use the generic one because the actual ptr is a pointer according to std::is_pointer.

You could just use ASSERT_FALSE(ptr), but this has limited utility, because on failure it will just print "Expected: !(ptr)" rather than the actual value of the pointer. But when we see this message in logs in a hard-to-repro failure, it would be useful to see the actual value (is the pointer corrupted? or is it just set to something when it shouldn't be?)



 Comments   
Comment by Daniel Gottlieb (Inactive) [ 16/Jun/21 ]

Ah that makes sense, thanks. I think this is a worthwhile change.

Comment by George Wangensteen [ 16/Jun/21 ]

daniel.gottlieb I didn't have a BF in mind when I filed this; I was just writing unittests and after grepping around to see how we ordinarily check for nullptr and after chatting with Billy about it thought that the current situation is less-than-ideal/life might be easier if we could just use ASSERT_EQ or at least see the value of the pointer. But, if I find a BF or local failure demonstrating this, I'll link it

Comment by Daniel Gottlieb (Inactive) [ 16/Jun/21 ]

george.wangensteen is there a BF ticket this can be linked to? I'm interested in taking a quick peek to see what else we might be able to glean without a whole coredump at our disposal.

Generated at Thu Feb 08 05:42:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.