diff options
author | Piotr Sikora <piotr.sikora@frickle.com> | 2011-04-13 05:45:08 +0000 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2011-05-22 15:24:11 +0200 |
commit | 5793b999a956806f886879fb475e19edd5a98b72 (patch) | |
tree | 0544750ca71569284d90dc7b2bcf83a26281e8aa | |
parent | 875a20939932045ccae4fc6a67db7c26d94f658d (diff) |
Add "make check" target (useful for automated tests).
While there, add "-p" option to "hiredis-test", so that we could run
tests without interrupting Redis instance running on the default port.
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | test.c | 9 |
2 files changed, 12 insertions, 3 deletions
@@ -105,6 +105,12 @@ hiredis-%: %.o $(STLIBNAME) test: hiredis-test ./hiredis-test +check: hiredis-test + echo "daemonize yes\n pidfile /tmp/redis-check.pid\n port 56379" \ + | redis-server - + ./hiredis-test -p 56379 || (kill `cat /tmp/redis-check.pid` && false) + kill `cat /tmp/redis-check.pid` + .c.o: $(CC) -std=c99 -pedantic -c $(CFLAGS) $(OBJARCH) $(DEBUG) $(COMPILE_TIME) $< @@ -22,10 +22,11 @@ static long long usec(void) { } static int use_unix = 0; +static int port = 6379; static redisContext *blocking_context = NULL; static void __connect(redisContext **target) { *target = blocking_context = (use_unix ? - redisConnectUnix("/tmp/redis.sock") : redisConnect((char*)"127.0.0.1", 6379)); + redisConnectUnix("/tmp/redis.sock") : redisConnect((char*)"127.0.0.1", port)); if (blocking_context->err) { printf("Connection error: %s\n", blocking_context->errstr); exit(1); @@ -128,7 +129,7 @@ static void test_blocking_connection(void) { int major, minor; test("Returns error when host cannot be resolved: "); - c = redisConnect((char*)"idontexist.local", 6379); + c = redisConnect((char*)"idontexist.local", port); test_cond(c->err == REDIS_ERR_OTHER && strcmp(c->errstr,"Can't resolve: idontexist.local") == 0); redisFree(c); @@ -517,7 +518,7 @@ static void cleanup(void) { // static redisContext *__connect_nonblock() { // /* Reset callback flags */ // __test_callback_flags = 0; -// return redisConnectNonBlock("127.0.0.1", 6379, NULL); +// return redisConnectNonBlock("127.0.0.1", port, NULL); // } // // static void test_nonblocking_connection() { @@ -601,6 +602,8 @@ int main(int argc, char **argv) { if (argc > 1) { if (strcmp(argv[1],"-s") == 0) use_unix = 1; + if ((strcmp(argv[1],"-p") == 0) && (argc == 3)) + port = atoi(argv[2]); } signal(SIGPIPE, SIG_IGN); |