Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CppUnit with GoogleTest in AX tests #1919

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

tstraubinger
Copy link

This is a work-in-progress pull request. I've begun by adding GoogleTest to the AX unit test runner and am currently running both the existing CppUnit test suite as well as any added GoogleTest tests. The intention is to migrate the test cases one-by-one and then remove CppUnit completely afterwards.

Resolves #1917

…l conversion; convert TestPrinters to gtest

Signed-off-by: Tim Straubinger <[email protected]>
Copy link

linux-foundation-easycla bot commented Sep 27, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@tstraubinger tstraubinger marked this pull request as draft September 27, 2024 20:13
…d declarations to PointExecutable

Signed-off-by: Tim Straubinger <[email protected]>
…nd declarations to VolumeExecutable

Signed-off-by: Tim Straubinger <[email protected]>
… gtest and cppunit to test/util.h

Signed-off-by: Tim Straubinger <[email protected]>
…cppunit dual support from utils.h

Signed-off-by: Tim Straubinger <[email protected]>
@tstraubinger tstraubinger changed the title Draft PR: replace CppUnit with GoogleTest in AX tests Replace CppUnit with GoogleTest in AX tests Oct 29, 2024
@tstraubinger tstraubinger marked this pull request as ready for review October 29, 2024 00:13
@tstraubinger
Copy link
Author

These changes are ready for review. I've completely removed CppUnit from the AX tests but it remains a dependency at the top level. I think I'll put in a second pull request to remove it there as well, separately from this one.
@Idclip @richhones @danrbailey

@@ -173,7 +48,7 @@ inline void testFunctionOptions(unittest_util::AXTestHarness& harness,
const ast::Tree::Ptr syntaxTree = ast::parse(code.c_str());
timer.stop();

CPPUNIT_ASSERT_MESSAGE(syntaxTree, "Invalid AX passed to testFunctionOptions.");
ASSERT_TRUE(syntaxTree) << "Invalid AX passed to testFunctionOptions.";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arguments to CPPUNIT_ASSERT_MESSAGE were reversed here. If I understand correctly then, this was ensuring that the string literal evaluates to true (which as a non-null pointer, it does) and would otherwise have printed out the pointer to the AST (perhaps via shared_ptr's operator<<(ostream&))

Comment on lines +1665 to +1673
// NOTE: GTest's ASSERT_* macros create a 'return;' statement
// which errors here. Exceptions are being used instead to
// exit early.

// test the builder is pointing to the correct location
CPPUNIT_ASSERT(&B != &_B);
if (&B == &_B)
{
throw std::runtime_error("Builder should be different");
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some opinionated changes: GTest ASSERT_* macros can't be used in a non-void function because they expand to a void return statement (I suppose Google wanted to support code bases with C++ exceptions disabled). I've replaced the assertions with equivalent if-statements and explicit C++ exceptions. I've confirmed that GTest reports a failure as expected when these are thrown here.

Comment on lines -200 to +204
friend class ::TestLogger;
FRIEND_TEST(TestLogger, testParseSetsTree);
FRIEND_TEST(TestLogger, testAddError);
FRIEND_TEST(TestLogger, testAddWarning);
Copy link
Author

@tstraubinger tstraubinger Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have been possible to avoid these changes to a header file in order to test private members, but this is the GTest-recommended approach. See https://google.github.io/googletest/advanced.html#testing-private-code

@tstraubinger
Copy link
Author

I've created a secondary branch off of this one that further removes all mentions of CppUnit from the build dependencies and instructions. Shall I create a merge request into this branch, wait until this is merged, or just push the changes to this branch?
https://github.com/tstraubinger/openvdb/tree/feature/remove_cppunit

@danrbailey
Copy link
Contributor

I've created a secondary branch off of this one that further removes all mentions of CppUnit from the build dependencies and instructions. Shall I create a merge request into this branch, wait until this is merged, or just push the changes to this branch? https://github.com/tstraubinger/openvdb/tree/feature/remove_cppunit

Thanks, I'm fine to have these changes in this branch as they're all closely related. I've just approved the CI running, but note there are some conflicts, so this branch likely needs to be updated and the conflicts resolved which may affect the result of the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUILD] Migrate AX Unit Tests from CppUnit to GTest
2 participants