Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(111)

Issue 7049: Extend GoogleTest EXPECT_NE() to allow immediate NULLs (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
16 years, 11 months ago by chandlerc
Modified:
15 years, 3 months ago
Reviewers:
Zhanyong
CC:
googletestframework_googlegroups.com
Base URL:
http://googletest.googlecode.com/svn/trunk/
Visibility:
Public.

Description

Currently GoogleTest allows the following highly convenient syntax: TEST(Foo, test) { EXPECT_EQ(NULL, SomeNullReturningFunc()); } However it does not allow the opposing expectation to be made: TEST(Foo, test) { EXPECT_NE(NULL, SomeNonNullReturningFunc()); } This patch adds the latter to the expectation system in precisely the same way as the _EQ variant. That said, this patch is extremely sub-optimal, as it completely duplicates the EqHelper as NotEqHelper with the only substantive change calling CmpHelperNE instead of CmpHelperEQ. This can be trivially accomplished by passing a function pointer, but that seems undue run-time overhead. I attempted to unify them through an added template parameter to provide the CmpHelper* method to be called, but that was non-trivial without using TR, C++0x, or Boost related helpers. Perhaps you can find a cleaner way Zhanyong? This is also untested. I can certainly add the tests, but I didn't see a prime place for them, as EXPECT_EQ is never tested anywher. Thoughts? Finally, the EXPECT_EQ() form has special (and IMO nicer) logging surrounding the idea of "expected" vs. "actual". I would personally enjoy extending this to EXPECT_NE() by using the idea of "unexpected" vs. "actual" terminology. I have already used those as more descriptive internal variables, but the logging refactoring would shuffle more around than I wanted in this change. I'd appreciate feedback on whether this is even desirable.

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+71 lines, -4 lines) Patch
M include/gtest/gtest.h View 3 chunks +71 lines, -4 lines 0 comments Download

Messages

Total messages: 1
chandlerc
16 years, 11 months ago (2008-10-04 21:25:42 UTC) #1
Currently GoogleTest allows the following highly convenient syntax:

TEST(Foo, test) {
  EXPECT_EQ(NULL, SomeNullReturningFunc());
}

However it does not allow the opposing expectation to be made:

TEST(Foo, test) {
  EXPECT_NE(NULL, SomeNonNullReturningFunc());
}

This patch adds the latter to the expectation system in precisely the same way
as the _EQ variant. That said, this patch is extremely sub-optimal, as it
completely duplicates the EqHelper as NotEqHelper with the only substantive
change calling CmpHelperNE instead of CmpHelperEQ. This can be trivially
accomplished by passing a function pointer, but that seems undue run-time
overhead. I attempted to unify them through an added template parameter to
provide the CmpHelper* method to be called, but that was non-trivial without
using TR, C++0x, or Boost related helpers. Perhaps you can find a cleaner way
Zhanyong?

This is also untested. I can certainly add the tests, but I didn't see a prime
place for them, as EXPECT_EQ is never tested anywher. Thoughts?

Finally, the EXPECT_EQ() form has special (and IMO nicer) logging surrounding
the idea of "expected" vs. "actual". I would personally enjoy extending this to
EXPECT_NE() by using the idea of "unexpected" vs. "actual" terminology. I have
already used those as more descriptive internal variables, but the logging
refactoring would shuffle more around than I wanted in this change. I'd
appreciate feedback on whether this is even desirable.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b