@matheusbsbs / matheus-bagliano / commits / c4b2f41b5f
Fork 0

cmake: support for testing git with ctest

This patch provides an alternate way to test git using ctest. CTest ships with CMake, so there is no additional dependency being introduced. To perform the tests with ctest do this after building: ctest -j[number of jobs] NOTE: -j is optional, the default number of jobs is 1 Each of the jobs does this: cd t/ && sh t[something].sh The reason for using CTest is that it logs the output of the tests in a neat way, which can be helpful during diagnosis of failures. After the tests have run ctest generates three log files located in `build-directory`/Testing/Temporary/ These log files are: CTestCostData.txt: This file contains the time taken to complete each test. LastTestsFailed.log: This log file contains the names of the tests that have failed in the run. LastTest.log: This log file contains the log of all the tests that have run. A snippet of the file is given below. 10/901 Testing: D:/my/git-master/t/t0009-prio-queue.sh 10/901 Test: D:/my/git-master/t/t0009-prio-queue.sh Command: "sh.exe" "D:/my/git-master/t/t0009-prio-queue.sh" Directory: D:/my/git-master/t "D:/my/git-master/t/t0009-prio-queue.sh" Output: ---------------------------------------------------------- ok 1 - basic ordering ok 2 - mixed put and get ok 3 - notice empty queue ok 4 - stack order passed all 4 test(s) 1..4 <end of output> Test time = 1.11 sec NOTE: Testing only works when building in source for now. Signed-off-by: Sibi Siddharthan <sibisiddharthan.github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sibi Siddharthan committed Jun 26, 2020 at 16:11 UTC c4b2f41b5f5bd4905cb3b36183957150d73d9e59
1 file changed +124
contrib/buildsystems/CMakeLists.txt
+124
@@ -96,6 +96,7 @@ include(CheckIncludeFile)
96 include(CheckFunctionExists)
97 include(CheckSymbolExists)
98 include(CheckStructHasMember)
99 +include(CTest)
100
101 find_package(ZLIB REQUIRED)
102 find_package(CURL)
@@ -748,3 +749,126 @@ install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/
749 if(MSGFMT_EXE)
750 install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share)
751 endif()
752 +
753 +
754 +if(BUILD_TESTING)
755 +
756 +#tests-helpers
757 +add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
758 +target_link_libraries(test-fake-ssh common-main)
759 +
760 +add_executable(test-line-buffer ${CMAKE_SOURCE_DIR}/t/helper/test-line-buffer.c)
761 +target_link_libraries(test-line-buffer common-main vcs-svn)
762 +
763 +add_executable(test-svn-fe ${CMAKE_SOURCE_DIR}/t/helper/test-svn-fe.c)
764 +target_link_libraries(test-svn-fe common-main vcs-svn)
765 +
766 +#test-tool
767 +parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
768 +
769 +list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
770 +add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
771 +target_link_libraries(test-tool common-main)
772 +
773 +set_target_properties(test-fake-ssh test-line-buffer test-svn-fe test-tool
774 + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
775 +
776 +#wrapper scripts
777 +set(wrapper_scripts
778 + git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext)
779 +
780 +set(wrapper_test_scripts
781 + test-fake-ssh test-line-buffer test-svn-fe test-tool)
782 +
783 +
784 +foreach(script ${wrapper_scripts})
785 + file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
786 + string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
787 + string(REPLACE "@@PROG@@" "${script}" content "${content}")
788 + file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
789 +endforeach()
790 +
791 +foreach(script ${wrapper_test_scripts})
792 + file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
793 + string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
794 + string(REPLACE "@@PROG@@" "t/helper/${script}" content "${content}")
795 + file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
796 +endforeach()
797 +
798 +file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
799 +string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
800 +string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
801 +file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
802 +
803 +#options for configuring test options
804 +option(PERL_TESTS "Perform tests that use perl" ON)
805 +option(PYTHON_TESTS "Perform tests that use python" ON)
806 +
807 +#GIT-BUILD-OPTIONS
808 +set(TEST_SHELL_PATH ${SHELL_PATH})
809 +set(DIFF diff)
810 +set(PYTHON_PATH /usr/bin/python)
811 +set(TAR tar)
812 +set(NO_CURL )
813 +set(NO_EXPAT )
814 +set(USE_LIBPCRE1 )
815 +set(USE_LIBPCRE2 )
816 +set(NO_LIBPCRE1_JIT )
817 +set(NO_PERL )
818 +set(NO_PTHREADS )
819 +set(NO_PYTHON )
820 +set(PAGER_ENV "LESS=FRX LV=-c")
821 +set(DC_SHA1 YesPlease)
822 +set(RUNTIME_PREFIX true)
823 +set(NO_GETTEXT )
824 +
825 +if(NOT CURL_FOUND)
826 + set(NO_CURL 1)
827 +endif()
828 +
829 +if(NOT EXPAT_FOUND)
830 + set(NO_EXPAT 1)
831 +endif()
832 +
833 +if(NOT Intl_FOUND)
834 + set(NO_GETTEXT 1)
835 +endif()
836 +
837 +if(NOT PERL_TESTS)
838 + set(NO_PERL 1)
839 +endif()
840 +
841 +if(NOT PYTHON_TESTS)
842 + set(NO_PYTHON 1)
843 +endif()
844 +
845 +file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n")
846 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n")
847 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n")
848 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n")
849 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n")
850 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n")
851 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n")
852 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n")
853 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "USE_LIBPCRE1='${USE_LIBPCRE1}'\n")
854 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_LIBPCRE1_JIT='${NO_LIBPCRE1_JIT}'\n")
855 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
856 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
857 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
858 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n")
859 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n")
860 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X=''\n")
861 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
862 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
863 +file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
864 +
865 +file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
866 +
867 +#test
868 +foreach(tsh ${test_scipts})
869 + add_test(NAME ${tsh}
870 + COMMAND ${SH_EXE} ${tsh}
871 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
872 +endforeach()
873 +
874 +endif()#BUILD_TESTING