Skip to content

Commit

Permalink
build: replace CMARK_TESTS with BUILD_TESTING
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
compnerd committed Dec 21, 2023
1 parent cd960cc commit 7f0ad79
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
matrix:
cmake_opts:
- '-DCMARK_SHARED=ON'
- ''
- '-DBUILD_TESTING=YES'
compiler:
- c: 'clang'
cpp: 'clang++'
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
matrix:
cmake_opts:
- '-DCMARK_SHARED=ON'
- ''
- '-DBUILD_TESTING=YES'
compiler:
- c: 'clang'
cpp: 'clang++'
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
matrix:
cmake_opts:
- '-DCMARK_SHARED=ON'
- ''
- '-DBUILD_TESTING=YES'
env:
CMAKE_OPTIONS: ${{ matrix.cmake_opts }}

Expand Down
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions api_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ if(CMARK_SHARED)
else()
target_link_libraries(api_test cmark_static)
endif()

add_test(NAME api_test COMMAND api_test)

8 changes: 1 addition & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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)

0 comments on commit 7f0ad79

Please sign in to comment.