1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

clar: add CMake support

Now that we're using `clar` as powerful test framework, we have to
adjust the Visual C build (read: the CMake definition) to be able to
handle that, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2024-09-04 16:17:25 +02:00 committed by Junio C Hamano
parent c9763684ea
commit 894deb76a0

View file

@ -1004,6 +1004,59 @@ foreach(unit_test ${unit_test_PROGRAMS})
endif()
endforeach()
parse_makefile_for_scripts(unit_tests_SUITES "UNIT_TESTS_SUITES" "")
set(clar_decls "")
set(clar_cbs "")
set(clar_cbs_count 0)
set(clar_suites "static struct clar_suite _clar_suites[] = {\n")
list(LENGTH unit_tests_SUITES clar_suites_count)
foreach(suite ${unit_tests_SUITES})
file(STRINGS "${CMAKE_SOURCE_DIR}/t/unit-tests/${suite}.c" decls
REGEX "^void test_${suite}__[a-zA-Z_0-9][a-zA-Z_0-9]*\\(void\\)$")
list(LENGTH decls decls_count)
string(REGEX REPLACE "void (test_${suite}__([a-zA-Z_0-9]*))\\(void\\)" " { \"\\2\", &\\1 },\n" cbs ${decls})
string(JOIN "" cbs ${cbs})
list(TRANSFORM decls PREPEND "extern ")
string(JOIN ";\n" decls ${decls})
string(APPEND clar_decls "${decls};\n")
string(APPEND clar_cbs
"static const struct clar_func _clar_cb_${suite}[] = {\n"
${cbs}
"};\n")
string(APPEND clar_suites
" {\n"
" \"${suite}\",\n"
" { NULL, NULL },\n"
" { NULL, NULL },\n"
" _clar_cb_${suite}, ${decls_count}, 1\n"
" },\n")
math(EXPR clar_cbs_count "${clar_cbs_count}+${decls_count}")
endforeach()
string(APPEND clar_suites
"};\n"
"static const size_t _clar_suite_count = ${clar_suites_count};\n"
"static const size_t _clar_callback_count = ${clar_cbs_count};\n")
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h" "${clar_decls}")
file(WRITE "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite" "${clar_decls}" "${clar_cbs}" "${clar_suites}")
list(TRANSFORM unit_tests_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/")
list(TRANSFORM unit_tests_SUITES APPEND ".c")
add_library(unit-tests-lib ${unit_tests_SUITES} "${CMAKE_SOURCE_DIR}/t/unit-tests/clar/clar.c")
target_include_directories(unit-tests-lib PRIVATE "${CMAKE_SOURCE_DIR}/t/unit-tests")
add_executable(unit-tests "${CMAKE_SOURCE_DIR}/t/unit-tests/unit-test.c")
target_link_libraries(unit-tests unit-tests-lib common-main)
set_target_properties(unit-tests
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
if(MSVC)
set_target_properties(unit-tests
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
set_target_properties(unit-tests
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
endif()
#test-tool
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)