2

I would like to write a custom clang-tidy check to port code from cppunit to googletest.

class SomeTest: public CPPUNIT_NS::TestFixture {
  CPPUNIT_TEST_SUITE(SomeTest);
  CPPUNIT_TEST(shouldDoSomething);
  CPPUNIT_TEST_SUITE_END();

...

protected:
  void shouldDoSomething();
  void otherFunction(int times = 0);
};

CPPUNITFRAMEWORK_TEST_SUITE_REGISTRATION(SomeTest);

...

void SomeTest::shouldDoSomething() {...}
void SomeTest::otherFunction(int) {}

I would like to be able to replace

void SomeTest::shouldDoSomething() {...}

with

TEST_F(SomeTest, shouldDoSomething) {...}

I can match a function name from CPPUNIT_TEST(...) macro with

stringLiteral(hasAncestor(callExpr(callee(functionDecl(hasName("getTestNameFor"))))))

but I have no idea whether it is possible to reuse this information to match the function declaration so I can actually replace it with googletest.

4

0 回答 0