From 7f0ad794e1c7c6ce58b245e0a4f3ee280edece36 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 21 Dec 2023 13:41:50 -0800 Subject: [PATCH] build: replace `CMARK_TESTS` with `BUILD_TESTING` `BUILD_TESTING` is the CMake sanctioned option for the control of tests (c.f. https://cmake.org/cmake/help/latest/module/CTest.html). Use the standard option to control the build of test targets. --- .github/workflows/ci.yml | 6 +++--- CMakeLists.txt | 9 ++++----- Makefile | 5 +++-- api_test/CMakeLists.txt | 3 +++ test/CMakeLists.txt | 8 +------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44d918c04..ff55121c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: matrix: cmake_opts: - '-DCMARK_SHARED=ON' - - '' + - '-DBUILD_TESTING=YES' compiler: - c: 'clang' cpp: 'clang++' @@ -64,7 +64,7 @@ jobs: matrix: cmake_opts: - '-DCMARK_SHARED=ON' - - '' + - '-DBUILD_TESTING=YES' compiler: - c: 'clang' cpp: 'clang++' @@ -92,7 +92,7 @@ jobs: matrix: cmake_opts: - '-DCMARK_SHARED=ON' - - '' + - '-DBUILD_TESTING=YES' env: CMAKE_OPTIONS: ${{ matrix.cmake_opts }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a4a4be65..2df5af451 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make") endif() -option(CMARK_TESTS "Build cmark tests and enable testing" ON) option(CMARK_STATIC "Build static libcmark library" ON) option(CMARK_SHARED "Build shared libcmark library" ON) option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF) @@ -60,16 +59,16 @@ function(cmark_add_compile_options target) endfunction() add_subdirectory(src) -if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC)) - add_subdirectory(api_test) -endif() # TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME # to Windows, but defines `MINGW`. if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) add_subdirectory(man) endif() -if(CMARK_TESTS) +if(BUILD_TESTING) enable_testing() + if(CMARK_SHARED OR CMARK_STATIC) + add_subdirectory(api_test) + endif() add_subdirectory(test testdir) endif() diff --git a/Makefile b/Makefile index 4938044e3..71b2449fc 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,8 @@ $(BUILDDIR): -G "$(GENERATOR)" \ -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DBUILD_TESTING=YES install: $(BUILDDIR) $(MAKE) -C $(BUILDDIR) install @@ -76,7 +77,7 @@ prof: afl: @[ -n "$(AFL_PATH)" ] || { echo '$$AFL_PATH not set'; false; } mkdir -p $(BUILDDIR) - cd $(BUILDDIR) && cmake .. -DCMARK_TESTS=0 -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang + cd $(BUILDDIR) && cmake .. -DBUILD_TESTING=NO -DCMAKE_C_COMPILER=$(AFL_PATH)/afl-clang $(MAKE) $(AFL_PATH)/afl-fuzz \ -i test/afl_test_cases \ diff --git a/api_test/CMakeLists.txt b/api_test/CMakeLists.txt index 8f19ff70c..127d96711 100644 --- a/api_test/CMakeLists.txt +++ b/api_test/CMakeLists.txt @@ -10,3 +10,6 @@ if(CMARK_SHARED) else() target_link_libraries(api_test cmark_static) endif() + +add_test(NAME api_test COMMAND api_test) + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 106d3a9fe..a415a2d26 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,10 +19,6 @@ else() IMPORTED_LOCATION ${PYTHON_EXECUTABLE}) endif() -if (CMARK_SHARED OR CMARK_STATIC) - add_test(NAME api_test COMMAND api_test) -endif() - if (WIN32) file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR) set(NEWPATH "${WIN_DLL_DIR};$ENV{PATH}") @@ -82,9 +78,7 @@ IF (Python_Interpreter_FOUND) ELSE(Python_Interpreter_FOUND) - message("\n*** A python 3 interpreter is required to run the spec tests.\n") - add_test(skipping_spectests - echo "Skipping spec tests, because no python 3 interpreter is available.") + message(WARNING "A Python 3 Interpreter is required to run the spec tests") ENDIF(Python_Interpreter_FOUND)