From 89ffb6658e66c2ac286612dc30d178b832516150 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 29 May 2020 02:47:29 -0400 Subject: [PATCH] CMake: improvements to testing usability Replace USE_TESTS with BUILD_TESTING variable already exported by CTest. Use the CMake 3.17 CMAKE_CTEST_ARGUMENTS to pass "-V" to ctest. #651 --- CMakeLists.txt | 15 +++++++-------- README.md | 12 ++++++++---- tests/metric.cpp | 1 - tests/rotate.cpp | 1 - 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0af9bf7bf..67fae63a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) include(GNUInstallDirs) ###################### USER-SELECTABLE OPTIONS ########################### +# BUILD_TESTING is defined by CTest option(DFSG_BUILD "DFSG build (no non-free media/code)" OFF) option(USE_COVERAGE "Assess code coverage with llvm-cov/lcov" OFF) option(USE_DOXYGEN "Build HTML cross reference with doxygen" OFF) @@ -22,7 +23,6 @@ option(USE_QRCODEGEN "Disable libqrcodegen QR code support" ON) option(USE_RUST "Build Rust wrappers (experimental)" OFF) option(USE_SIXEL "Build Sixel support" OFF) option(USE_STATIC "Build static libraries (in addition to shared)" ON) -option(USE_TESTS "Build doctest unit tests" ON) set(USE_MULTIMEDIA "ffmpeg" CACHE STRING "Multimedia engine, one of 'ffmpeg', 'oiio', or 'none'") set_property(CACHE USE_MULTIMEDIA PROPERTY STRINGS ffmpeg oiio none) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo Coverage) @@ -84,7 +84,7 @@ if(NOT "${HAVE_QRCODEGEN_H}") endif() endif() find_library(LIBRT rt) -if(${USE_TESTS}) +if(${BUILD_TESTING}) find_package(doctest 2.3.5 REQUIRED) endif() @@ -526,10 +526,8 @@ target_compile_definitions(notcurses-view endif() # Testing -if(${USE_TESTS}) -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - include(CTest) -endif() +include(CTest) +if(${BUILD_TESTING}) file(GLOB TESTSRCS CONFIGURE_DEPENDS tests/*.cpp) add_executable(notcurses-tester ${TESTSRCS}) target_include_directories(notcurses-tester @@ -543,7 +541,8 @@ target_link_libraries(notcurses-tester notcurses++ "${TERMINFO_LIBRARIES}" ) - +# sadly, this doesn't take effect until CMake 3.17... +set(CMAKE_CTEST_ARGUMENTS "-V") enable_testing() add_test( NAME notcurses-tester @@ -688,7 +687,7 @@ install(PROGRAMS src/pydemo/notcurses-pydemo DESTINATION bin) install(TARGETS notcurses-demo DESTINATION bin) install(TARGETS notcurses-input DESTINATION bin) install(TARGETS notcurses-ncreel DESTINATION bin) -if(${USE_TESTS}) +if(${BUILD_TESTING}) install(TARGETS notcurses-tester DESTINATION bin) endif() install(TARGETS notcurses-tetris DESTINATION bin) diff --git a/README.md b/README.md index f8d95b742..e60673766 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,13 @@ or `none`. Without a multimedia engine, Notcurses will be unable to decode images and videos. Run unit tests with `make test` following a successful build. If you have unit -test failures, *please* file a bug including the output of `./notcurses-tester -> log 2>&1` (`make test` also runs `notcurses-tester`, but hides important -output). Install with `make install` following a successful build. +test failures, *please* file a bug including the output of + +`./notcurses-tester -p ../data` + +(`make test` also runs `notcurses-tester`, but hides important output). + +Install with `make install` following a successful build. To watch the bitchin' demo, run `./notcurses-demo -p ../data`. More details can be found on the `notcurses-demo(1)` man page. @@ -144,12 +148,12 @@ To set the C compiler, export `CC`. To set the C++ compiler, export `CXX`. The `CMAKE_BUILD_TYPE` CMake variable can be defined to any of its standard values, but must be `Debug` for use of `USE_COVERAGE`. +* `BUILD_TESTING`: build `notcurses-tester` using doctest * `DFSG_BUILD`: leave out all content considered non-free under the Debian Free Software Guidelines. * `USE_MULTIMEDIA`: `ffmpeg` for FFmpeg, `oiio` for OpenImageIO, `none` for none. * `USE_QRCODEGEN`: build qrcode support via libqrcodegen * `USE_SIXEL`: build Sixel support via libsixel -* `USE_TESTS`: build `notcurses-tester` using doctest * `USE_PANDOC`: build man pages with pandoc * `USE_DOXYGEN`: build interlinked HTML documentation with Doxygen * `USE_PYTHON`: build the Python wrappers diff --git a/tests/metric.cpp b/tests/metric.cpp index 4b619ec4a..d6999fbf1 100644 --- a/tests/metric.cpp +++ b/tests/metric.cpp @@ -330,7 +330,6 @@ TEST_CASE("Metric") { uintmax_t val = 9027854993; uintmax_t decimal = GIG; REQUIRE(qprefix(val, decimal, buf, 0)); -fprintf(stderr, "%s %s\n", gold, buf); CHECK(!strcmp(buf, gold)); } diff --git a/tests/rotate.cpp b/tests/rotate.cpp index ef464502f..8412a5f38 100644 --- a/tests/rotate.cpp +++ b/tests/rotate.cpp @@ -176,7 +176,6 @@ TEST_CASE("Rotate") { for(int i = 0 ; i < height * width / 2 ; ++i){ if(rgbaret[i] & CELL_BG_MASK){ CHECK(rgbaret[i] == htonl(rgba[i])); -fprintf(stderr, "%08x %08x\n", rgbaret[i], htonl(rgba[i])); } } free(rgbaret);