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

Teach unittest macros to usefully compare with nullptr

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: None

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

        Attachments

          Activity

            People

            Assignee:
            backlog-server-servicearch Backlog - Service Architecture
            Reporter:
            george.wangensteen George Wangensteen
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: