pw_package: Add googletest

Adds a googletest plugin to pw_package for users who want the full
googletest/googlemock featureset.

Change-Id: I06102da6f175690d6238a1817b0a85d2c7843513
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/88934
Reviewed-by: Rob Mohr <mohrr@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Armando Montanez <amontanez@google.com>
diff --git a/pw_package/py/BUILD.gn b/pw_package/py/BUILD.gn
index 3f86f87..03d49e7 100644
--- a/pw_package/py/BUILD.gn
+++ b/pw_package/py/BUILD.gn
@@ -32,6 +32,7 @@
     "pw_package/packages/chromium_verifier.py",
     "pw_package/packages/crlset.py",
     "pw_package/packages/freertos.py",
+    "pw_package/packages/googletest.py",
     "pw_package/packages/mbedtls.py",
     "pw_package/packages/micro_ecc.py",
     "pw_package/packages/nanopb.py",
diff --git a/pw_package/py/pw_package/packages/googletest.py b/pw_package/py/pw_package/packages/googletest.py
new file mode 100644
index 0000000..adfb4e8
--- /dev/null
+++ b/pw_package/py/pw_package/packages/googletest.py
@@ -0,0 +1,40 @@
+# Copyright 2022 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+"""Install and check status of googletest."""
+
+import pathlib
+from typing import Sequence
+
+import pw_package.git_repo
+import pw_package.package_manager
+
+
+class Googletest(pw_package.git_repo.GitRepo):
+    """Install and check status of googletest."""
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args,
+                         name='googletest',
+                         url='https://github.com/google/googletest',
+                         commit='073293463e1733c5e931313da1c3f1de044e1db3',
+                         **kwargs)
+
+    def info(self, path: pathlib.Path) -> Sequence[str]:
+        return (
+            f'{self.name} installed in: {path}',
+            "Enable by running 'gn args out' and adding this line:",
+            f'  dir_pw_third_party_googletest = "{path}"',
+        )
+
+
+pw_package.package_manager.register(Googletest)
diff --git a/pw_package/py/pw_package/pigweed_packages.py b/pw_package/py/pw_package/pigweed_packages.py
index de4a9e0..98c3a82 100644
--- a/pw_package/py/pw_package/pigweed_packages.py
+++ b/pw_package/py/pw_package/pigweed_packages.py
@@ -21,6 +21,7 @@
 from pw_package.packages import chromium_verifier  # pylint: disable=unused-import
 from pw_package.packages import crlset  # pylint: disable=unused-import
 from pw_package.packages import freertos  # pylint: disable=unused-import
+from pw_package.packages import googletest  # pylint: disable=unused-import
 from pw_package.packages import mbedtls  # pylint: disable=unused-import
 from pw_package.packages import micro_ecc  # pylint: disable=unused-import
 from pw_package.packages import nanopb
diff --git a/pw_unit_test/docs.rst b/pw_unit_test/docs.rst
index 492a92e..f96c56a 100644
--- a/pw_unit_test/docs.rst
+++ b/pw_unit_test/docs.rst
@@ -43,6 +43,9 @@
   To request a feature addition, please
   `let us know <mailto:pigweed@googlegroups.com>`_.
 
+  See `Using upstream Googletest and Googlemock` below for information
+  about using upstream Googletest instead.
+
 ------------------------
 Using the test framework
 ------------------------
@@ -387,3 +390,20 @@
 
   The size of the memory pool to use for test fixture instances. By default this
   is set to 16K.
+
+Using upstream Googletest and Googlemock
+========================================
+
+If you want to use the full upstream Googletest/Googlemock, you must do the
+following:
+
+* Set the GN var ``dir_pw_third_party_googletest`` to the location of the
+  googletest source. You can use ``pw package install googletest`` to fetch the
+  source if desired.
+* Set the GN var ``pw_unit_test_MAIN = "//third_party/googletest:gmock_main"``
+* Set the GN var ``pw_unit_test_PUBLIC_DEPS = [ "//third_party/googletest" ]``
+
+.. note::
+
+  Not all unit tests build properly with upstream Googletest yet. This is a
+  work in progress.