nagyistoce / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

need IsNull() for matching NULL #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Dale King wrote:

There is a NotNull matcher but not an IsNull matcher. The docmentation
says just use the value NULL for matching against NULL, but that
doesn't work in all cases in Microsoft C++ and possibly other
languages..

So a statement like:

  EXPECT_THAT( thePointer, NULL );

does not compile in MSVC. These do not compile either:

  EXPECT_THAT( thePointer, (void *)NULL );
  EXPECT_THAT( thePointer, Eq( NULL ) );

If I cast NULL to the pointer's type it will work.

Of course, I can (and have) expressed this simple case as

  EXPECT_EQ( NULL, thePointer );

and that works. But sometimes you really need a matcher and cannot use
EXPECT_EQ. The lack of symmetry here bugs me. I can say the opposite
with a matcher:

  EXPECT_THAT( thePointer, NotNull() );

But cannot express check for null with a matcher other than by using
the double negative Not( NotNull() ).

It would be very nice to be able to just say:

  EXPECT_THAT( thePointer, IsNull() );

Original issue reported on code.google.com by zhanyong...@gmail.com on 23 Sep 2009 at 4:06

GoogleCodeExporter commented 9 years ago

Original comment by zhanyong...@gmail.com on 23 Sep 2009 at 10:29

GoogleCodeExporter commented 9 years ago
Fixed in trunk in r 210.

Original comment by zhanyong...@gmail.com on 24 Sep 2009 at 9:42