]> git.saurik.com Git - redis.git/commitdiff
Tests for redis-cli in non-interactive mode
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Wed, 4 Aug 2010 15:02:13 +0000 (17:02 +0200)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Wed, 4 Aug 2010 15:02:13 +0000 (17:02 +0200)
Minor change in redis-cli output for the (multi-)bulk response but this
will be fixed in the next commit.

src/redis-cli.c
tests/integration/redis-cli.tcl

index 87ebcb69951840597451dab3b2a9652f419525ca..c1cc17a3e9e2ed987af888e382e0cf8fc2c9be04 100644 (file)
@@ -134,7 +134,7 @@ static void printStringRepr(char *s, int len) {
         }
         s++;
     }
-    printf("\"\n");
+    printf("\"");
 }
 
 static int cliReadBulkReply(int fd) {
@@ -152,7 +152,7 @@ static int cliReadBulkReply(int fd) {
     reply = zmalloc(bulklen);
     anetRead(fd,reply,bulklen);
     anetRead(fd,crlf,2);
-    if (config.raw_output || !config.interactive) {
+    if (config.raw_output) {
         if (bulklen && fwrite(reply,bulklen,1,stdout) == 0) {
             zfree(reply);
             return 1;
@@ -161,6 +161,7 @@ static int cliReadBulkReply(int fd) {
         /* If you are producing output for the standard output we want
          * a more interesting output with quoted characters and so forth */
         printStringRepr(reply,bulklen);
+        printf("\n");
     }
     zfree(reply);
     return 0;
index 6e1061351d6092acff6bdcf26b9e5a3c72560288..a10968b1d44d94bbf410a7fd8be6482a25061181 100644 (file)
@@ -41,6 +41,19 @@ start_server {tags {"cli"}} {
         close_cli $fd
     }
 
+    proc run_cli {args} {
+        set fd [open [format "|src/redis-cli -p %d -n 9 $args" [srv port]] "r"]
+        fconfigure $fd -buffering none
+        fconfigure $fd -translation binary
+        set resp [read $fd 1048576]
+        close $fd
+        set _ $resp
+    }
+
+    proc test_noninteractive_cli {name code} {
+        test "Non-interactive CLI: $name" $code
+    }
+
     test_interactive_cli "INFO response should be printed raw" {
         set lines [split [run_command $fd info] "\n"]
         foreach line $lines {
@@ -85,4 +98,26 @@ start_server {tags {"cli"}} {
         assert_equal "OK" [run_command $fd "set key\"\" bar"]
         assert_equal "bar" [r get key]
     }
+
+    test_noninteractive_cli "Status reply" {
+        assert_equal "OK\n" [run_cli set key bar]
+        assert_equal "bar" [r get key]
+    }
+
+    test_noninteractive_cli "Integer reply" {
+        r del counter
+        assert_equal "(integer) 1\n" [run_cli incr counter]
+    }
+
+    test_noninteractive_cli "Bulk reply" {
+        r set key "tab\tnewline\n"
+        assert_equal "\"tab\\tnewline\\n\"\n" [run_cli get key]
+    }
+
+    test_noninteractive_cli "Multi-bulk reply" {
+        r del list
+        r rpush list foo
+        r rpush list bar
+        assert_equal "1. \"foo\"\n2. \"bar\"\n" [run_cli lrange list 0 -1]
+    }
 }