xref: /aosp_15_r20/external/pigweed/third_party/googletest/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1.. _module-pw_third_party_googletest:
2
3==========
4GoogleTest
5==========
6The ``$dir_pw_third_party/googletest/`` module provides various helpers to
7optionally use full upstream `GoogleTest/GoogleMock`__ with
8:ref:`module-pw_unit_test`.
9
10.. __: https://github.com/google/googletest
11
12.. _module-pw_third_party_googletest-using_upstream:
13
14----------------------------------------
15Using upstream GoogleTest and GoogleMock
16----------------------------------------
17If you want to use the full upstream GoogleTest/GoogleMock, you must do the
18following:
19
20Add GoogleTest to your workspace with the following command.
21
22.. code-block:: sh
23
24   git submodule add https://github.com/google/googletest third_party/googletest
25
26Configure ``pw_unit_test`` to use upstream GoogleTest/GoogleMock.
27
28.. tab-set::
29
30   .. tab-item:: GN
31
32      * Set the GN var ``dir_pw_third_party_googletest`` to the location of the
33        GoogleTest source. If you are using a different version of the upstream
34        GoogleTest, or a different target than ``//third_party/googletest``, set
35        ``pw_unit_test_GOOGLETEST_BACKEND`` to point to your GoogleTest target
36        instead.
37      * Set the GN var ``pw_unit_test_MAIN`` to
38        ``dir_pigweed + "/third_party/googletest:gmock_main"``.
39      * Set the GN var ``pw_unit_test_BACKEND`` to
40        ``"//pw_unit_test:googletest"``.
41
42      Pigweed unit tests that do not work with upstream GoogleTest can be
43      disabled by setting ``enable_if`` to
44      ``pw_unit_test_BACKEND == "$dir_pw_unit_test:light"``.
45
46   .. tab-item:: CMake
47
48      * Set the ``dir_pw_third_party_googletest`` to the location of the
49        GoogleTest source.
50      * Set the var
51        ``pw_unit_test_MAIN`` to ``pw_third_party.googletest.gmock_main``.
52      * Set the var ``pw_unit_test_BACKEND`` to
53        ``pw_unit_test.googletest``.
54
55   .. tab-item:: Bazel
56
57      Set the following :ref:`label flags <docs-build_system-bazel_flags>`,
58      either in your
59      :ref:`target config <docs-build_system-bazel_configuration>` or on
60      the command line:
61
62      * ``//pw_unit_test:backend`` to
63        ``@pigweed//pw_unit_test:googletest``.
64      * ``//pw_unit_test:main`` to ``@com_google_googletest//:gtest_main``.
65
66      For example:
67
68      .. code-block:: sh
69
70         bazel test //... \
71            --@pigweed//pw_unit_test:backend=@pigweed//pw_unit_test:googletest \
72            --@pigweed//pw_unit_test:main=@com_google_googletest//:gtest_main
73
74.. note::
75
76  Not all unit tests build properly with upstream GoogleTest yet. This is a
77  work in progress.
78