timescaledb/cmake/GenerateTestSchedule.cmake
Mats Kindahl 05dd4787d1 Support test groups with different configurations
To support tests with different configuration options, we split the
tests into *test configurations*. Each test configuration NAME will have

- A configuration template file `NAME.conf.in` that is used to run the
  suite of tests.
- A variable `TEST_FILES_<NAME>` listing the test files available for
  that test suite.
- A variable `SOLO_TESTS_<NAME>` that lists the tests that need to be
  run as solo tests.

The code to generate test schedules is then factored out into a
separate file and used for each configuration.
2022-02-02 11:55:19 +01:00

56 lines
1.7 KiB
CMake

# generate_test_schedul(<output file> ...)
#
# A test schedule is generated for the files in TEST_FILES. The test schedule
# groups the tests into groups of size GROUP_SIZE, with the exceptions of any
# tests mentioned in the list SOLO, which will be in their own test group.
#
# TEST_FILES <file> ...
#
# Test files to generate a test schedule for.
#
# SOLO <test> ...
#
# Names of tests that should be run as solo tests. Note that these are test
# names, not file names.
#
# GROUP_SIZE
#
# Size of each group in the test schedule.
function(generate_test_schedule OUTPUT_FILE)
set(options)
set(oneValueArgs GROUP_SIZE)
set(multiValueArgs TEST_FILES SOLO)
cmake_parse_arguments(_generate "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
list(SORT _generate_TEST_FILES)
file(REMOVE ${OUTPUT_FILE})
# We put the solo tests in the test file first. Note that we do not generate
# groups for solo tests that are not in the list of test files.
foreach(_solo ${_generate_SOLO})
if("${_solo}.sql" IN_LIST _generate_TEST_FILES)
file(APPEND ${OUTPUT_FILE} "test: ${_solo}\n")
endif()
endforeach()
# Generate groups of tests
set(_members 0)
foreach(_file ${_generate_TEST_FILES})
string(REGEX REPLACE "(.+)\.sql" "\\1" _test ${_file})
if(NOT (_test IN_LIST _generate_SOLO))
if(_members EQUAL 0)
file(APPEND ${OUTPUT_FILE} "test: ")
endif()
file(APPEND ${OUTPUT_FILE} "${_test} ")
if(_members LESS _generate_GROUP_SIZE)
math(EXPR _members "${_members} + 1")
else()
set(_members 0)
file(APPEND ${OUTPUT_FILE} "\n")
endif()
endif()
endforeach()
file(APPEND ${OUTPUT_FILE} "\n")
endfunction()