-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable GoogleMock in the GoogleTest setup
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
32 changed files
with
15,325 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2024 Google Inc. | ||
# All Rights Reserved. | ||
# | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# https://bazel.build/external/overview#bzlmod | ||
|
||
module( | ||
name = "googletest", | ||
version = "head", | ||
compatibility_level = 1, | ||
) | ||
|
||
# Only direct dependencies need to be listed below. | ||
# Please keep the versions in sync with the versions in the WORKSPACE file. | ||
|
||
bazel_dep(name = "abseil-cpp", | ||
version = "20240116.0", | ||
repo_name = "com_google_absl") | ||
|
||
bazel_dep(name = "platforms", | ||
version = "0.0.8") | ||
|
||
bazel_dep(name = "re2", | ||
repo_name = "com_googlesource_code_re2", | ||
version = "2023-11-01") | ||
|
||
bazel_dep(name = "rules_python", | ||
version = "0.29.0") | ||
|
||
|
||
fake_fuchsia_sdk = use_repo_rule("//:fake_fuchsia_sdk.bzl", "fake_fuchsia_sdk") | ||
fake_fuchsia_sdk(name = "fuchsia_sdk") | ||
|
||
# https://github.com/bazelbuild/rules_python/blob/main/BZLMOD_SUPPORT.md#default-toolchain-is-not-the-local-system-python | ||
register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2024 Google Inc. | ||
# All Rights Reserved. | ||
# | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# https://bazel.build/external/migration#workspace.bzlmod | ||
# | ||
# This file is intentionally empty. When bzlmod is enabled and this | ||
# file exists, the content of WORKSPACE is ignored. This prevents | ||
# bzlmod builds from unintentionally depending on the WORKSPACE file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. | ||
This is needed since bazel queries on targets that depend on //:gtest (eg: | ||
`bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not | ||
defined when bazel is evaluating the transitive closure of the query target. | ||
See https://github.com/google/googletest/issues/4472. | ||
""" | ||
|
||
def _fake_fuchsia_sdk_impl(repo_ctx): | ||
for stub_target in repo_ctx.attr._stub_build_targets: | ||
stub_package = stub_target | ||
stub_target_name = stub_target.split("/")[-1] | ||
repo_ctx.file("%s/BUILD.bazel" % stub_package, """ | ||
filegroup( | ||
name = "%s", | ||
) | ||
""" % stub_target_name) | ||
|
||
fake_fuchsia_sdk = repository_rule( | ||
doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", | ||
implementation = _fake_fuchsia_sdk_impl, | ||
attrs = { | ||
"_stub_build_targets": attr.string_list( | ||
doc = "The stub build targets to initialize.", | ||
default = [ | ||
"pkg/fdio", | ||
"pkg/syslog", | ||
"pkg/zx", | ||
], | ||
), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
######################################################################## | ||
# Note: CMake support is community-based. The maintainers do not use CMake | ||
# internally. | ||
# | ||
# CMake build script for Google Mock. | ||
# | ||
# To run the tests for Google Mock itself on Linux, use 'make test' or | ||
# ctest. You can select which tests to run using 'ctest -R regex'. | ||
# For more options, run 'ctest --help'. | ||
|
||
option(gmock_build_tests "Build all of Google Mock's own tests." OFF) | ||
|
||
# A directory to find Google Test sources. | ||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") | ||
set(gtest_dir gtest) | ||
else() | ||
set(gtest_dir ../googletest) | ||
endif() | ||
|
||
# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). | ||
include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) | ||
|
||
if (COMMAND pre_project_set_up_hermetic_build) | ||
# Google Test also calls hermetic setup functions from add_subdirectory, | ||
# although its changes will not affect things at the current scope. | ||
pre_project_set_up_hermetic_build() | ||
endif() | ||
|
||
######################################################################## | ||
# | ||
# Project-wide settings | ||
|
||
# Name of the project. | ||
# | ||
# CMake files in this project can refer to the root source directory | ||
# as ${gmock_SOURCE_DIR} and to the root binary directory as | ||
# ${gmock_BINARY_DIR}. | ||
# Language "C" is required for find_package(Threads). | ||
cmake_minimum_required(VERSION 3.13) | ||
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) | ||
|
||
if (COMMAND set_up_hermetic_build) | ||
set_up_hermetic_build() | ||
endif() | ||
|
||
# Instructs CMake to process Google Test's CMakeLists.txt and add its | ||
# targets to the current scope. We are placing Google Test's binary | ||
# directory in a subdirectory of our own as VC compilation may break | ||
# if they are the same (the default). | ||
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") | ||
|
||
|
||
# These commands only run if this is the main project | ||
if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") | ||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to | ||
# make it prominent in the GUI. | ||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) | ||
else() | ||
mark_as_advanced(gmock_build_tests) | ||
endif() | ||
|
||
# Although Google Test's CMakeLists.txt calls this function, the | ||
# changes there don't affect the current scope. Therefore we have to | ||
# call it again here. | ||
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake | ||
|
||
# Adds Google Mock's and Google Test's header directories to the search path. | ||
# Get Google Test's include dirs from the target, gtest_SOURCE_DIR is broken | ||
# when using fetch-content with the name "GTest". | ||
get_target_property(gtest_include_dirs gtest INCLUDE_DIRECTORIES) | ||
set(gmock_build_include_dirs | ||
"${gmock_SOURCE_DIR}/include" | ||
"${gmock_SOURCE_DIR}" | ||
"${gtest_include_dirs}") | ||
include_directories(${gmock_build_include_dirs}) | ||
|
||
######################################################################## | ||
# | ||
# Defines the gmock & gmock_main libraries. User tests should link | ||
# with one of them. | ||
|
||
# Google Mock libraries. We build them using more strict warnings than what | ||
# are used for other targets, to ensure that Google Mock can be compiled by | ||
# a user aggressive about warnings. | ||
if (MSVC) | ||
cxx_library(gmock | ||
"${cxx_strict}" | ||
"${gtest_dir}/src/gtest-all.cc" | ||
src/gmock-all.cc) | ||
|
||
cxx_library(gmock_main | ||
"${cxx_strict}" | ||
"${gtest_dir}/src/gtest-all.cc" | ||
src/gmock-all.cc | ||
src/gmock_main.cc) | ||
else() | ||
cxx_library(gmock "${cxx_strict}" src/gmock-all.cc) | ||
target_link_libraries(gmock PUBLIC gtest) | ||
set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION}) | ||
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc) | ||
target_link_libraries(gmock_main PUBLIC gmock) | ||
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) | ||
endif() | ||
|
||
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}") | ||
target_include_directories(gmock SYSTEM INTERFACE | ||
"$<BUILD_INTERFACE:${dirs}>" | ||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") | ||
target_include_directories(gmock_main SYSTEM INTERFACE | ||
"$<BUILD_INTERFACE:${dirs}>" | ||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") | ||
|
||
######################################################################## | ||
# | ||
# Install rules. | ||
install_project(gmock gmock_main) | ||
|
||
######################################################################## | ||
# | ||
# Google Mock's own tests. | ||
# | ||
# You can skip this section if you aren't interested in testing | ||
# Google Mock itself. | ||
# | ||
# The tests are not built by default. To build them, set the | ||
# gmock_build_tests option to ON. You can do it by running ccmake | ||
# or specifying the -Dgmock_build_tests=ON flag when running cmake. | ||
|
||
if (gmock_build_tests) | ||
# This must be set in the root directory for the tests to be run by | ||
# 'make test' or ctest. | ||
enable_testing() | ||
|
||
if (MINGW OR CYGWIN) | ||
add_compile_options("-Wa,-mbig-obj") | ||
endif() | ||
|
||
############################################################ | ||
# C++ tests built with standard compiler flags. | ||
|
||
cxx_test(gmock-actions_test gmock_main) | ||
cxx_test(gmock-cardinalities_test gmock_main) | ||
cxx_test(gmock_ex_test gmock_main) | ||
cxx_test(gmock-function-mocker_test gmock_main) | ||
cxx_test(gmock-internal-utils_test gmock_main) | ||
cxx_test(gmock-matchers-arithmetic_test gmock_main) | ||
cxx_test(gmock-matchers-comparisons_test gmock_main) | ||
cxx_test(gmock-matchers-containers_test gmock_main) | ||
cxx_test(gmock-matchers-misc_test gmock_main) | ||
cxx_test(gmock-more-actions_test gmock_main) | ||
cxx_test(gmock-nice-strict_test gmock_main) | ||
cxx_test(gmock-port_test gmock_main) | ||
cxx_test(gmock-spec-builders_test gmock_main) | ||
cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) | ||
cxx_test(gmock_test gmock_main) | ||
|
||
if (DEFINED GTEST_HAS_PTHREAD) | ||
cxx_test(gmock_stress_test gmock) | ||
endif() | ||
|
||
# gmock_all_test is commented to save time building and running tests. | ||
# Uncomment if necessary. | ||
# cxx_test(gmock_all_test gmock_main) | ||
|
||
############################################################ | ||
# C++ tests built with non-standard compiler flags. | ||
|
||
if (MSVC) | ||
cxx_library(gmock_main_no_exception "${cxx_no_exception}" | ||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) | ||
|
||
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" | ||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) | ||
|
||
else() | ||
cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc) | ||
target_link_libraries(gmock_main_no_exception PUBLIC gmock) | ||
|
||
cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc) | ||
target_link_libraries(gmock_main_no_rtti PUBLIC gmock) | ||
endif() | ||
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" | ||
gmock_main_no_exception test/gmock-more-actions_test.cc) | ||
|
||
cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}" | ||
gmock_main_no_rtti test/gmock-spec-builders_test.cc) | ||
|
||
cxx_shared_library(shared_gmock_main "${cxx_default}" | ||
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) | ||
|
||
# Tests that a binary can be built with Google Mock as a shared library. On | ||
# some system configurations, it may not possible to run the binary without | ||
# knowing more details about the system configurations. We do not try to run | ||
# this binary. To get a more robust shared library coverage, configure with | ||
# -DBUILD_SHARED_LIBS=ON. | ||
cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}" | ||
shared_gmock_main test/gmock-spec-builders_test.cc) | ||
set_target_properties(shared_gmock_test_ | ||
PROPERTIES | ||
COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") | ||
|
||
############################################################ | ||
# Python tests. | ||
|
||
cxx_executable(gmock_leak_test_ test gmock_main) | ||
py_test(gmock_leak_test) | ||
|
||
cxx_executable(gmock_output_test_ test gmock) | ||
py_test(gmock_output_test) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ | ||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ | ||
|
||
Name: gmock | ||
Description: GoogleMock (without main() function) | ||
Version: @PROJECT_VERSION@ | ||
URL: https://github.com/google/googletest | ||
Requires: gtest = @PROJECT_VERSION@ | ||
Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ | ||
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ | ||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ | ||
|
||
Name: gmock_main | ||
Description: GoogleMock (with main() function) | ||
Version: @PROJECT_VERSION@ | ||
URL: https://github.com/google/googletest | ||
Requires: gmock = @PROJECT_VERSION@ | ||
Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ | ||
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ |
Oops, something went wrong.