GoogleTest#

Pigweed AI summary: The GoogleTest module provides helpers to use GoogleTest/GoogleMock with pw_unit_test. To use the full upstream GoogleTest/GoogleMock, one must add GoogleTest to the workspace and configure pw_unit_test to use it. This can be done in GN, CMake, or Bazel. However, not all unit tests build properly with upstream GoogleTest yet.

The $dir_pw_third_party/googletest/ module provides various helpers to optionally use full upstream GoogleTest/GoogleMock with pw_unit_test.

Using upstream GoogleTest and GoogleMock#

Pigweed AI summary: This article provides instructions for using the full upstream GoogleTest/GoogleMock in your workspace. The steps include adding GoogleTest to your workspace, configuring pw_unit_test to use upstream GoogleTest/GoogleMock, and setting label flags in your target config or on the command line. However, not all unit tests build properly with upstream GoogleTest yet.

If you want to use the full upstream GoogleTest/GoogleMock, you must do the following:

Add GoogleTest to your workspace with the following command.

git submodule add https://github.com/google/googletest third_party/googletest

Configure pw_unit_test to use upstream GoogleTest/GoogleMock.

  • Set the GN var dir_pw_third_party_googletest to the location of the GoogleTest source. If you used the command above this will be //third_party/googletest.

  • Set the GN var pw_unit_test_MAIN to dir_pigweed + "/third_party/googletest:gmock_main".

  • Set the GN var pw_unit_test_GOOGLETEST_BACKEND to "//third_party/googletest".

Pigweed unit tests that do not work with upstream GoogleTest can be disabled by setting enable_if to pw_unit_test_GOOGLETEST_BACKEND == "$dir_pw_unit_test:light".

  • Set the dir_pw_third_party_googletest to the location of the GoogleTest source.

  • Set the var pw_unit_test_MAIN to pw_third_party.googletest.gmock_main.

  • Set the var pw_unit_test_GOOGLETEST_BACKEND to pw_third_party.googletest.

  • pw_unit_test_googletest_backend to @com_google_googletest//:gtest.

  • pw_unit_test_main to @com_google_googletest//:gtest_main.

For example:

bazel test //... \
   --@pigweed_config//:pw_unit_test_googletest_backend=@com_google_googletest//:gtest \
   --@pigweed_config//:pw_unit_test_main=@com_google_googletest//:gtest_main

Note

Not all unit tests build properly with upstream GoogleTest yet. This is a work in progress.