Skip to content

Commit

Permalink
Use standard CMake configuration option to disable tests. (#1707)
Browse files Browse the repository at this point in the history
Fixes #1617.
  • Loading branch information
remyabel authored and coryan committed Dec 19, 2018
1 parent b3eeb2d commit 1e4ad81
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 373 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ matrix:
BUILD_TYPE=Coverage
DISTRO=ubuntu
DISTRO_VERSION=18.04
- # Compile with tests disabled.
os: linux
compiler: gcc
env:
BUILD_TESTING=no
CMAKE_FLAGS=-DBUILD_TESTING=OFF
DISTRO=ubuntu
DISTRO_VERSION=18.04
- # Compile with exceptions disabled.
os: linux
compiler: gcc
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# interested in compiling and running the gRPC tests.
include(IncludeGrpc)

# Enable testing in this directory so we can do a top-level `make test`.
enable_testing()
# Enable testing in this directory so we can do a top-level `make test`. This
# also includes the BUILD_TESTING option, which is on by default.
include(CTest)

# Each subproject adds dependencies to this target to have their docs generated.
add_custom_target(doxygen-docs)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ after cloning this repo:

```bash
git submodule update --init
# Add -DBUILD_TESTING=OFF to disable tests
cmake -H. -Bbuild-output

# Adjust the number of threads used by modifying parameter for `-j 4`
Expand All @@ -245,6 +246,7 @@ You will find compiled binaries in `build-output/` respective to their source pa
```bash
git submodule update --init
export OPENSSL_ROOT_DIR=/usr/local/opt/libressl
# Add -DBUILD_TESTING=OFF to disable tests
cmake -H. -Bbuild-output

# Adjust the number of threads used by modifying parameter for `-j 4`
Expand Down
28 changes: 15 additions & 13 deletions ci/travis/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,22 @@ if [ -n "${ccache_command}" ]; then
"${ccache_command}" --zero-stats --cleanup --max-size="${max_size}"
fi

# Run the tests and output any failures.
echo
echo "${COLOR_YELLOW}Running unit and integration tests $(date)${COLOR_RESET}"
echo
cd "${BUILD_DIR}"
ctest --output-on-failure

# Run the integration tests. Not all projects have them, so just iterate over
# the ones that do.
for subdir in google/cloud google/cloud/bigtable google/cloud/storage; do
if [ "${BUILD_TESTING:-}" != "no" ]; then
# Run the tests and output any failures.
echo
echo "${COLOR_YELLOW}Running unit and integration tests $(date)${COLOR_RESET}"
echo
echo "${COLOR_GREEN}Running integration tests for ${subdir}${COLOR_RESET}"
/v/${subdir}/ci/run_integration_tests.sh
done
cd "${BUILD_DIR}"
ctest --output-on-failure

# Run the integration tests. Not all projects have them, so just iterate over
# the ones that do.
for subdir in google/cloud google/cloud/bigtable google/cloud/storage; do
echo
echo "${COLOR_GREEN}Running integration tests for ${subdir}${COLOR_RESET}"
/v/${subdir}/ci/run_integration_tests.sh
done
fi

# Test the install rule and that the installation works.
if [ "${TEST_INSTALL:-}" = "yes" ]; then
Expand Down
1 change: 1 addition & 0 deletions ci/travis/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sudo docker run \
--env CC="${CC}" \
--env NCPU="${NCPU:-2}" \
--env BUILD_TYPE="${BUILD_TYPE:-Release}" \
--env BUILD_TESTING="${BUILD_TESTING:-}" \
--env CHECK_ABI="${CHECK_ABI:-}" \
--env CHECK_STYLE="${CHECK_STYLE:-}" \
--env SCAN_BUILD="${SCAN_BUILD:-}" \
Expand Down
114 changes: 58 additions & 56 deletions google/cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,66 +154,68 @@ set_target_properties(
create_bazel_config(google_cloud_cpp_common)
google_cloud_cpp_add_clang_tidy(google_cloud_cpp_common)

add_library(google_cloud_cpp_testing
testing_util/capture_log_lines_backend.h
testing_util/capture_log_lines_backend.cc
testing_util/check_predicate_becomes_false.h
testing_util/chrono_literals.h
testing_util/environment_variable_restore.h
testing_util/environment_variable_restore.cc
testing_util/expect_exception.h
testing_util/expect_future_error.h
testing_util/custom_google_mock_main.cc
testing_util/init_google_mock.h
testing_util/init_google_mock.cc
testing_util/testing_types.h
testing_util/testing_types.cc)
target_link_libraries(google_cloud_cpp_testing
PUBLIC google_cloud_cpp_common GTest::gmock)
if (BUILD_TESTING)
add_library(google_cloud_cpp_testing
testing_util/capture_log_lines_backend.h
testing_util/capture_log_lines_backend.cc
testing_util/check_predicate_becomes_false.h
testing_util/chrono_literals.h
testing_util/environment_variable_restore.h
testing_util/environment_variable_restore.cc
testing_util/expect_exception.h
testing_util/expect_future_error.h
testing_util/custom_google_mock_main.cc
testing_util/init_google_mock.h
testing_util/init_google_mock.cc
testing_util/testing_types.h
testing_util/testing_types.cc)
target_link_libraries(google_cloud_cpp_testing
PUBLIC google_cloud_cpp_common GTest::gmock)

create_bazel_config(google_cloud_cpp_testing)
create_bazel_config(google_cloud_cpp_testing)

set(google_cloud_cpp_common_unit_tests
future_generic_test.cc
future_generic_then_test.cc
future_void_test.cc
future_void_then_test.cc
iam_bindings_test.cc
internal/backoff_policy_test.cc
internal/big_endian_test.cc
internal/filesystem_test.cc
internal/future_impl_test.cc
internal/invoke_result_test.cc
internal/random_test.cc
internal/retry_policy_test.cc
internal/throw_delegate_test.cc
log_test.cc
optional_test.cc
terminate_handler_test.cc)
set(google_cloud_cpp_common_unit_tests
future_generic_test.cc
future_generic_then_test.cc
future_void_test.cc
future_void_then_test.cc
iam_bindings_test.cc
internal/backoff_policy_test.cc
internal/big_endian_test.cc
internal/filesystem_test.cc
internal/future_impl_test.cc
internal/invoke_result_test.cc
internal/random_test.cc
internal/retry_policy_test.cc
internal/throw_delegate_test.cc
log_test.cc
optional_test.cc
terminate_handler_test.cc)

# Export the list of unit tests so the Bazel BUILD file can pick it up.
export_list_to_bazel("google_cloud_cpp_common_unit_tests.bzl"
"google_cloud_cpp_common_unit_tests")
# Export the list of unit tests so the Bazel BUILD file can pick it up.
export_list_to_bazel("google_cloud_cpp_common_unit_tests.bzl"
"google_cloud_cpp_common_unit_tests")

foreach (fname ${google_cloud_cpp_common_unit_tests})
string(REPLACE "/"
"_"
target
${fname})
string(REPLACE ".cc"
""
target
${target})
add_executable(${target} ${fname})
target_link_libraries(${target}
PRIVATE google_cloud_cpp_testing
google_cloud_cpp_common
GTest::gmock_main
GTest::gmock
GTest::gtest
google_cloud_cpp_common_options)
add_test(NAME ${target} COMMAND ${target})
endforeach ()
foreach (fname ${google_cloud_cpp_common_unit_tests})
string(REPLACE "/"
"_"
target
${fname})
string(REPLACE ".cc"
""
target
${target})
add_executable(${target} ${fname})
target_link_libraries(${target}
PRIVATE google_cloud_cpp_testing
google_cloud_cpp_common
GTest::gmock_main
GTest::gmock
GTest::gtest
google_cloud_cpp_common_options)
add_test(NAME ${target} COMMAND ${target})
endforeach ()
endif ()

# Export the CMake targets to make it easy to create configuration files.
install(EXPORT google_cloud_cpp_common-targets
Expand Down
Loading

0 comments on commit 1e4ad81

Please sign in to comment.