From 5b2c7b837364b8cf391673bcab4f2ae4ac761e10 Mon Sep 17 00:00:00 2001 From: "David L. Jones" Date: Wed, 30 Mar 2022 13:44:42 -0700 Subject: [PATCH] [CMake] Declare remaining tests, and add a test output option. (#9705) The new option will allow us to generate test XML output. CTest can discover tests from googletest, but it generates one file per case. We have several thousand cases, so one file each would be far from optimal. The approach in this change will generate one file per test (executable). --- cmake/tests.cmake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 28551f52c3..0fecfa5d58 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -1,5 +1,7 @@ option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF) +option(protobuf_TEST_XML_OUTDIR "Output directory for XML logs from tests." "") + option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH "Using absolute test_plugin path in tests" ON) mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) @@ -239,6 +241,13 @@ if(MINGW) endif() +if(protobuf_TEST_XML_OUTDIR) + if(NOT "${protobuf_TEST_XML_OUTDIR}" MATCHES "[/\\]$") + string(APPEND protobuf_TEST_XML_OUTDIR "/") + endif() + set(protobuf_GTEST_ARGS "--gtest_output=xml:${protobuf_TEST_XML_OUTDIR}") +endif() + add_executable(tests ${tests_files}) if (MSVC) target_compile_options(tests PRIVATE @@ -263,17 +272,23 @@ set(lite_test_files add_executable(lite-test ${lite_test_files}) target_link_libraries(lite-test protobuf-lite-test-common libprotobuf-lite GTest::gmock_main) +add_test(NAME lite-test + COMMAND lite-test ${protobuf_GTEST_ARGS}) + set(lite_arena_test_files ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_arena_unittest.cc ) add_executable(lite-arena-test ${lite_arena_test_files}) target_link_libraries(lite-arena-test protobuf-lite-test-common libprotobuf-lite GTest::gmock_main) +add_test(NAME lite-arena-test + COMMAND lite-arena-test ${protobuf_GTEST_ARGS}) + add_custom_target(check COMMAND tests DEPENDS tests test_plugin WORKING_DIRECTORY ${protobuf_SOURCE_DIR}) add_test(NAME check - COMMAND tests + COMMAND tests ${protobuf_GTEST_ARGS} WORKING_DIRECTORY "${protobuf_SOURCE_DIR}")