aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-08-22 16:46:18 +0300
committerLasse Collin <lasse.collin@tukaani.org>2022-08-22 16:46:18 +0300
commitdf23c31000283c00e5ef1ca32a0bc3bb757bd707 (patch)
treef02667018280ced4b9a1898e8dd4f60478bf1c4b /CMakeLists.txt
parentxz: Revise --info-memory output. (diff)
downloadxz-df23c31000283c00e5ef1ca32a0bc3bb757bd707.tar.xz
CMake: Add liblzma tests.
Thanks to Jia Tan for the patch.
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt53
1 files changed, 52 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a88af38..5dded28c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,7 @@
#
# Other missing things:
# - No xzgrep or other scripts or their symlinks
-# - No tests (no test failures either!)
+# - No xz tests (liblzma tests only)
#
# NOTE: Even if the code compiles without warnings, the end result may be
# different than via ./configure. Specifically, the list of #defines
@@ -685,3 +685,54 @@ if(NOT MSVC AND HAVE_GETOPT_LONG)
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
COMPONENT xz)
endif()
+
+
+#############################################################################
+# Tests
+#############################################################################
+
+include(CTest)
+
+if(BUILD_TESTING)
+ set(LIBLZMA_TESTS
+ test_bcj_exact_size
+ test_block_header
+ test_check
+ test_filter_flags
+ test_hardware
+ test_index
+ test_stream_flags
+ test_vli
+ )
+
+ foreach(TEST IN LISTS LIBLZMA_TESTS)
+ add_executable("${TEST}" "tests/${TEST}.c")
+
+ target_include_directories("${TEST}" PRIVATE
+ src/common
+ src/liblzma/api
+ lib
+ )
+
+ target_link_libraries("${TEST}" PRIVATE liblzma)
+
+ # Put the test programs into their own subdirectory so they don't
+ # pollute the top-level dir which might contain xz and xzdec.
+ set_target_properties("${TEST}" PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests_bin"
+ )
+
+ add_test(NAME "${TEST}"
+ COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tests_bin/${TEST}"
+ )
+
+ # Set srcdir environment variable so that the tests find their
+ # input files from the source tree.
+ #
+ # Set the return code for skipped tests to match Automake convention.
+ set_tests_properties("${TEST}" PROPERTIES
+ ENVIRONMENT "srcdir=${CMAKE_CURRENT_LIST_DIR}/tests"
+ SKIP_RETURN_CODE 77
+ )
+ endforeach()
+endif()