[patch] Perl Cache::Memcached tests

Ronald J Kimball rkimball+memcached at pangeamedia.com
Tue Aug 7 20:18:23 UTC 2007


Here are two patches to update the tests for Cache::Memcached.

The first patch updates 02_keys.t.  It clarifies the test names, adds 
tests for delete(), and adds a test to make sure replace() actually 
changes the value.  It also deletes the old stats() tests, because 
that's tested in 03_stats.t now.

The second patch just does a bit of cleanup on all three test files, to 
make them consistent with each other.

I'm planning to add some more tests later, such as for get_multi().

Ronald
-------------- next part --------------
diff -u -r Cache-Memcached-1.24.orig/t/02_keys.t Cache-Memcached-1.24/t/02_keys.t
--- Cache-Memcached-1.24.orig/t/02_keys.t	2007-07-03 14:14:12.000000000 -0400
+++ Cache-Memcached-1.24/t/02_keys.t	2007-08-07 16:05:38.000000000 -0400
@@ -9,7 +9,7 @@
 my $msock = IO::Socket::INET->new(PeerAddr => $testaddr,
                                   Timeout  => 3);
 if ($msock) {
-    plan tests => 10;
+    plan tests => 13;
 } else {
     plan skip_all => "No memcached instance running at $testaddr\n";
     exit 0;
@@ -20,25 +20,27 @@
     namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/",
 });
 
+isa_ok($memd, 'Cache::Memcached');
 
-ok($memd->set("key1", "val1"), "set succeeded");
+ok($memd->set("key1", "val1"), "set key1 as val1");
 
-is($memd->get("key1"), "val1", "get worked");
-ok(! $memd->add("key1", "val-replace"), "add properly failed");
-ok($memd->add("key2", "val2"), "add worked on key2");
-is($memd->get("key2"), "val2", "get worked");
+is($memd->get("key1"), "val1", "get key1 is val1");
+ok(! $memd->add("key1", "val-replace"), "add key1 properly failed");
+ok($memd->add("key2", "val2"), "add key2 as val2");
+is($memd->get("key2"), "val2", "get key2 is val2");
 
-ok($memd->replace("key2", "val-replace"), "replace worked");
-ok(! $memd->replace("key-noexist", "bogus"), "replace failed");
+ok($memd->replace("key2", "val-replace"), "replace key2 as val-replace");
+is($memd->get("key2"), "val-replace", "get key2 is val-replace");
+ok(! $memd->replace("key-noexist", "bogus"), "replace key-noexist properly failed");
 
-my $stats = $memd->stats;
-ok($stats, "got stats");
-is(ref $stats, "HASH", "is a hashref");
+ok($memd->delete("key1"), "delete key1");
+ok(! $memd->get("key1"), "get key1 properly failed");
 
 
-# also make one without a hashref
+# also test creating the object with a list rather than a hash-ref
 my $mem2 = Cache::Memcached->new(
                                  servers   => [ ],
                                  debug     => 1,
-                                 );
+                                );
+isa_ok($mem2, 'Cache::Memcached');
 ok($mem2->{debug}, "debug is set on alt constructed instance");
-------------- next part --------------
diff -r -u Cache-Memcached-1.24.orig/t/01_use.t Cache-Memcached-1.24/t/01_use.t
--- Cache-Memcached-1.24.orig/t/01_use.t	2007-08-07 15:41:55.000000000 -0400
+++ Cache-Memcached-1.24/t/01_use.t	2007-08-07 15:42:10.000000000 -0400
@@ -1,7 +1,8 @@
 #!/usr/bin/env perl -w
+
 use strict;
-use Test;
-BEGIN { plan tests => 1 }
+use Test::More;
+
+plan tests => 1;
 
-use Cache::Memcached; ok(1);
-exit;
+use_ok('Cache::Memcached');
diff -r -u Cache-Memcached-1.24.orig/t/02_keys.t Cache-Memcached-1.24/t/02_keys.t
--- Cache-Memcached-1.24.orig/t/02_keys.t	2007-08-07 16:05:38.000000000 -0400
+++ Cache-Memcached-1.24/t/02_keys.t	2007-08-07 16:02:13.000000000 -0400
@@ -1,4 +1,4 @@
-# -*-perl-*-
+#!/usr/bin/env perl -w
 
 use strict;
 use Test::More;
diff -r -u Cache-Memcached-1.24.orig/t/03_stats.t Cache-Memcached-1.24/t/03_stats.t
--- Cache-Memcached-1.24.orig/t/03_stats.t	2007-08-07 15:41:55.000000000 -0400
+++ Cache-Memcached-1.24/t/03_stats.t	2007-08-07 15:42:13.000000000 -0400
@@ -1,4 +1,4 @@
-# -*-perl-*-
+#!/usr/bin/env perl -w
 
 use strict;
 use Test::More;


More information about the memcached mailing list