|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# |
| 3 | +# This source code is licensed under the MIT license found in the |
| 4 | +# LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +# Builds the C++ unit tests in ReactCommon/**/tests against the libraries the |
| 7 | +# Fantom tester already compiles, one GoogleTest executable per tests |
| 8 | +# directory. Run them with ctest from this directory's build directory. |
| 9 | + |
| 10 | +cmake_minimum_required(VERSION 3.13) |
| 11 | + |
| 12 | +enable_testing() |
| 13 | +include(GoogleTest) |
| 14 | + |
| 15 | +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) |
| 16 | +add_subdirectory(${FANTOM_THIRD_PARTY_DIR}/googletest googletest EXCLUDE_FROM_ALL) |
| 17 | + |
| 18 | +add_react_common_subdir(react/networking) |
| 19 | +add_react_common_subdir(react/renderer/animations) |
| 20 | +add_react_common_subdir(react/renderer/element) |
| 21 | + |
| 22 | +# rrc_textinput compiles the Android platform sources, which need the Android |
| 23 | +# text layout; the tests only use the cross-platform base. |
| 24 | +file(GLOB react_common_tests_textinput_SRC CONFIGURE_DEPENDS |
| 25 | + ${REACT_COMMON_DIR}/react/renderer/components/textinput/*.cpp) |
| 26 | +add_library(react_common_tests_textinput OBJECT ${react_common_tests_textinput_SRC}) |
| 27 | +target_link_libraries(react_common_tests_textinput |
| 28 | + PUBLIC |
| 29 | + react_renderer_attributedstring |
| 30 | + react_renderer_core |
| 31 | + rrc_text |
| 32 | + rrc_view) |
| 33 | +target_compile_reactnative_options(react_common_tests_textinput PRIVATE) |
| 34 | + |
| 35 | +# The folly executors some tests use, and what they pull in, which |
| 36 | +# folly_runtime leaves out. |
| 37 | +set(folly_DIR ${FANTOM_THIRD_PARTY_DIR}/folly/folly) |
| 38 | +add_library(react_common_tests_folly STATIC |
| 39 | + ${folly_DIR}/ExceptionString.cpp |
| 40 | + ${folly_DIR}/Executor.cpp |
| 41 | + ${folly_DIR}/SingletonThreadLocal.cpp |
| 42 | + ${folly_DIR}/concurrency/ProcessLocalUniqueId.cpp |
| 43 | + ${folly_DIR}/detail/MemoryIdler.cpp |
| 44 | + ${folly_DIR}/detail/StaticSingletonManager.cpp |
| 45 | + ${folly_DIR}/detail/ThreadLocalDetail.cpp |
| 46 | + ${folly_DIR}/detail/thread_local_globals.cpp |
| 47 | + ${folly_DIR}/executors/ManualExecutor.cpp |
| 48 | + ${folly_DIR}/executors/QueuedImmediateExecutor.cpp |
| 49 | + ${folly_DIR}/io/async/Request.cpp |
| 50 | + ${folly_DIR}/memory/MallctlHelper.cpp |
| 51 | + ${folly_DIR}/memory/ReentrantAllocator.cpp |
| 52 | + ${folly_DIR}/portability/SysMembarrier.cpp |
| 53 | + ${folly_DIR}/synchronization/AsymmetricThreadFence.cpp |
| 54 | + ${folly_DIR}/synchronization/Hazptr.cpp |
| 55 | + ${folly_DIR}/synchronization/HazptrDomain.cpp |
| 56 | + ${folly_DIR}/system/Pid.cpp) |
| 57 | +target_compile_options(react_common_tests_folly PRIVATE -fexceptions -frtti) |
| 58 | +target_link_libraries(react_common_tests_folly PUBLIC folly_runtime) |
| 59 | + |
| 60 | +# Test headers are included by the paths Buck exports them under. |
| 61 | +set(react_common_tests_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) |
| 62 | +configure_file( |
| 63 | + ${REACT_COMMON_DIR}/callinvoker/ReactCommon/tests/TestCallInvoker.h |
| 64 | + ${react_common_tests_INCLUDE_DIR}/ReactCommon/TestCallInvoker.h |
| 65 | + COPYONLY) |
| 66 | + |
| 67 | +get_target_property(react_common_tests_LIBS fantom_tester LINK_LIBRARIES) |
| 68 | + |
| 69 | +# Pre-existing failures in OSS, on macOS and Linux alike, excluded by gtest |
| 70 | +# name per test target. |
| 71 | +set(jsinspector_modern_tests_EXCLUDED |
| 72 | + # Debugger.setBreakpointByUrl resolves no locations for a columnless |
| 73 | + # breakpoint. |
| 74 | + JsiIntegrationHermesTest/*.ResolveColumnlessBreakpointAfterEval |
| 75 | + JsiIntegrationHermesTest/*.ResolveColumnlessBreakpointAfterReload |
| 76 | + # The second session gets no Debugger.scriptParsed once the first disables |
| 77 | + # Debugger. |
| 78 | + JsiIntegrationHermesTest/*.TwoConnectionsDebuggerLifecycle) |
| 79 | + |
| 80 | +file(GLOB_RECURSE react_common_tests_SRC CONFIGURE_DEPENDS ${REACT_COMMON_DIR}/*.cpp) |
| 81 | +list(FILTER react_common_tests_SRC INCLUDE REGEX "/tests/") |
| 82 | +list(FILTER react_common_tests_SRC EXCLUDE REGEX "/benchmarks/") |
| 83 | + |
| 84 | +set(react_common_tests_DIRS) |
| 85 | +foreach(source ${react_common_tests_SRC}) |
| 86 | + string(REGEX REPLACE "^(.*/tests)/.*$" "\\1" test_dir ${source}) |
| 87 | + list(APPEND react_common_tests_DIRS ${test_dir}) |
| 88 | +endforeach() |
| 89 | +list(REMOVE_DUPLICATES react_common_tests_DIRS) |
| 90 | +list(SORT react_common_tests_DIRS) |
| 91 | + |
| 92 | +set(react_common_tests_TARGETS) |
| 93 | +foreach(test_dir ${react_common_tests_DIRS}) |
| 94 | + file(RELATIVE_PATH test_name ${REACT_COMMON_DIR} ${test_dir}) |
| 95 | + string(MAKE_C_IDENTIFIER ${test_name} test_target) |
| 96 | + |
| 97 | + set(test_dir_SRC ${react_common_tests_SRC}) |
| 98 | + list(FILTER test_dir_SRC INCLUDE REGEX "^${test_dir}/") |
| 99 | + |
| 100 | + add_executable(${test_target} EXCLUDE_FROM_ALL ${test_dir_SRC}) |
| 101 | + # Header-only ReactCommon libraries export -Werror -Wpedantic, and source |
| 102 | + # options are the only ones placed after them on the command line. |
| 103 | + set_source_files_properties(${test_dir_SRC} PROPERTIES COMPILE_OPTIONS -Wno-error) |
| 104 | + target_include_directories(${test_target} |
| 105 | + PRIVATE |
| 106 | + ${react_common_tests_INCLUDE_DIR} |
| 107 | + ${test_dir} |
| 108 | + ${test_dir}/..) |
| 109 | + target_link_libraries(${test_target} |
| 110 | + PRIVATE |
| 111 | + ${react_common_tests_LIBS} |
| 112 | + react_common_tests_folly |
| 113 | + react_common_tests_textinput |
| 114 | + react_networking |
| 115 | + react_renderer_animations |
| 116 | + react_renderer_element |
| 117 | + GTest::gmock_main) |
| 118 | + target_compile_options(${test_target} |
| 119 | + PRIVATE |
| 120 | + -fexceptions |
| 121 | + -frtti |
| 122 | + -std=c++20) |
| 123 | + |
| 124 | + set(test_FILTER "*") |
| 125 | + if(DEFINED ${test_target}_EXCLUDED) |
| 126 | + list(JOIN ${test_target}_EXCLUDED ":" test_EXCLUDED) |
| 127 | + set(test_FILTER "*-${test_EXCLUDED}") |
| 128 | + endif() |
| 129 | + |
| 130 | + # One process per test case: some suites leave global state behind, such as |
| 131 | + # registered HostTargets in jsinspector-modern, that later suites trip over. |
| 132 | + gtest_discover_tests(${test_target} |
| 133 | + TEST_PREFIX ${test_name}/ |
| 134 | + TEST_FILTER ${test_FILTER} |
| 135 | + NO_PRETTY_TYPES |
| 136 | + NO_PRETTY_VALUES |
| 137 | + DISCOVERY_MODE PRE_TEST) |
| 138 | + list(APPEND react_common_tests_TARGETS ${test_target}) |
| 139 | +endforeach() |
| 140 | + |
| 141 | +add_custom_target(react_common_tests) |
| 142 | +add_dependencies(react_common_tests ${react_common_tests_TARGETS}) |
0 commit comments