From 58d0e283331e778b11f4104d8cb4e8d5d7d9aa09 Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Mon, 21 Jan 2019 13:56:59 -0600 Subject: [PATCH] Enable make test Signed-off-by: Justin Brewer --- CMakeLists.txt | 4 ++-- test.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ef322a..51020ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,12 +46,12 @@ INSTALL(FILES hiredis.h read.h sds.h async.h INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -# Add tests: Currently, I don't know how to make the tests actually run -# without hanging! ENABLE_TESTING() ADD_EXECUTABLE(hiredis-test test.c) TARGET_LINK_LIBRARIES(hiredis-test hiredis) +ADD_TEST(NAME hiredis-test + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh) # Add examples IF(ENABLE_EXAMPLES) diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..8dce61b --- /dev/null +++ b/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh -ue + +REDIS_SERVER=${REDIS_SERVER:-redis-server} +REDIS_PORT=${REDIS_PORT:-56379} + +tmpdir=$(mktemp -d) +PID_FILE=${tmpdir}/hiredis-test-redis.pid +SOCK_FILE=${tmpdir}/hiredis-test-redis.sock + +cleanup() { + set +e + kill $(cat ${PID_FILE}) + rm -rf ${tmpdir} +} +trap cleanup INT TERM EXIT + +${REDIS_SERVER} - <