EulerianTechnologies / eredis

Fast and light Redis C client library built over Hiredis, thread-safe, write replication, auto-reconnect, sync pool, async libev.
BSD 3-Clause "New" or "Revised" License
81 stars 38 forks source link

Run all unit tests automatically with CTest #16

Closed xorangekiller closed 6 years ago

xorangekiller commented 6 years ago

There are two important things going on in this PR. One is a straight-forward bug fix for a bug that I accidentally introduced the last time around (sorry about that!), and the other is a new feature.

  1. First, the bug fix. The first commit in this PR fixes Eredis linkage for CMake 3.0 and later when it is compiled with an alternate LIBEV_ROOT_DIR (something outside of the CMAKE_INSTALL_PREFIX for liberedis.so itself.) This could happen on any system, but it is most likely to be a problem for cross-compiled builds, since they tend to be the ones monkeying around with library/header install paths. This bug only affected CMake 3.0 and later because 3.0 introduced the INTERFACE, PUBLIC, and PRIVATE keywords for target link libraries, whereas 2.8 defaults to PUBLIC visibility for all link libraries. The simple fix is to tell CMake 3.0 and later to do the same, which allows the test programs to link using the same include paths that the eredis library did.

  2. Second, the new feature. This isn't a new feature of Eredis itself, but more of a prerequisite for that: an enhancement for its test suite. I moved the unit tests from the src directory into their own test directory, then I integrated them with the CTest test runner that ships with CMake. I did that by writing a shell script that launches several instances of redis-server, writes a hosts configuration file for Eredis that points to those servers, runs a test executable, and shuts down the servers and cleans up when it's all done. I also made some fairly trivial modifications to the test programs themselves to make them exit automatically, with no user input, to facilitate automated testing. It seems to work pretty well, and the ability to just run make test to run the test suite is pretty nice.