Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-57713

Teach unittest macros to usefully compare with nullptr

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Service Arch

      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?)

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            george.wangensteen@mongodb.com George Wangensteen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: