xref: /curl/tests/CMakeLists.txt (revision d82f9f96)
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24option(CURL_TEST_BUNDLES "Bundle libtests/unittests into single binaries" OFF)
25
26find_program(TEST_NGHTTPX "nghttpx")
27if(NOT TEST_NGHTTPX)
28  set(TEST_NGHTTPX "nghttpx")
29endif()
30mark_as_advanced(TEST_NGHTTPX)
31# Consumed variables: TEST_NGHTTPX
32configure_file("config.in" "${CMAKE_CURRENT_BINARY_DIR}/config" @ONLY)
33
34add_custom_target(testdeps)
35add_subdirectory(http)
36add_subdirectory(http/clients)
37add_subdirectory(server)
38add_subdirectory(libtest)
39add_subdirectory(unit)
40add_subdirectory(certs EXCLUDE_FROM_ALL)
41
42function(add_runtests _targetname _test_flags)
43  if(CURL_TEST_BUNDLES)
44    set(_test_flags "${_test_flags} -bundle")
45  endif()
46  # Skip walking through dependent targets before running tests in CI.
47  # This avoids: GNU Make doing a slow re-evaluation of all targets and
48  # skipping them, MSBuild doing a re-evaluation, and actually rebuilding them.
49  unset(_depends)
50  if(NOT _targetname STREQUAL "test-ci")
51    set(_depends "testdeps")
52  endif()
53  # Use a special '$TFLAGS' placeholder as last argument which will be
54  # replaced by the contents of the environment variable in runtests.pl.
55  # This is a workaround for CMake's limitation where commands executed by
56  # 'make' or 'ninja' cannot portably reference environment variables.
57  string(REPLACE " " ";" _test_flags_list "${_test_flags}")
58  add_custom_target(${_targetname}
59    COMMAND
60      "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runtests.pl"
61      ${_test_flags_list}
62      "\$TFLAGS"
63    DEPENDS "${_depends}"
64    VERBATIM USES_TERMINAL
65  )
66endfunction()
67
68function(add_pytest _targetname _test_flags)
69  unset(_depends)
70  if(NOT _targetname STREQUAL "pytest-ci")
71    set(_depends "test-http-clients")
72  endif()
73  string(REPLACE " " ";" _test_flags_list "${_test_flags}")
74  add_custom_target(${_targetname}
75    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
76    COMMAND pytest ${_test_flags_list} "${CMAKE_CURRENT_SOURCE_DIR}/http"
77    DEPENDS "${_depends}"
78    VERBATIM USES_TERMINAL
79  )
80endfunction()
81
82# Create configurehelp.pm, used by tests needing to run the C preprocessor.
83if(MSVC OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
84  set(CURL_CPP "\"${CMAKE_C_COMPILER}\" -E")
85  if(APPLE AND CMAKE_OSX_SYSROOT)
86    set(CURL_CPP "${CURL_CPP} -isysroot ${CMAKE_OSX_SYSROOT}")
87  endif()
88  # Add header directories, like autotools builds do.
89  get_property(_include_dirs TARGET ${LIB_SELECTED} PROPERTY INCLUDE_DIRECTORIES)
90  foreach(_include_dir IN LISTS _include_dirs)
91    set(CURL_CPP "${CURL_CPP} -I${_include_dir}")
92  endforeach()
93else()
94  set(CURL_CPP "cpp")
95endif()
96# Generate version script for the linker, for versioned symbols.
97# Consumed variable:
98#   CURL_CPP
99configure_file(
100  "${CMAKE_CURRENT_SOURCE_DIR}/configurehelp.pm.in"
101  "${CMAKE_CURRENT_BINARY_DIR}/configurehelp.pm" @ONLY)
102
103add_runtests(test-quiet     "-a -s")
104add_runtests(test-am        "-a -am")
105add_runtests(test-full      "-a -p -r")
106# ~flaky means that it ignores results of tests using the flaky keyword
107add_runtests(test-nonflaky  "-a -p ~flaky ~timing-dependent")
108add_runtests(test-ci        "-a -p ~flaky ~timing-dependent -r -rm -j2")
109add_runtests(test-torture   "-a -t -j2")
110add_runtests(test-event     "-a -e")
111
112add_pytest(curl-pytest      "")
113add_pytest(curl-pytest-ci   "-v")
114