afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-09-11 01:45 pm

[dw-free] Many tests in t/ fail

[commit: http://hg.dwscoalition.org/dw-free/rev/6fdc677f6e0f]

http://bugs.dwscoalition.org/show_bug.cgi?id=1721

Eliminate comment-related warnings.

Patch by [personal profile] szabgab.

Files modified:
  • cgi-bin/talklib.pl
  • t/comment.t
--------------------------------------------------------------------------------
diff -r e4021aab73e7 -r 6fdc677f6e0f cgi-bin/talklib.pl
--- a/cgi-bin/talklib.pl	Fri Sep 11 00:33:04 2009 +0000
+++ b/cgi-bin/talklib.pl	Fri Sep 11 13:44:33 2009 +0000
@@ -661,6 +661,7 @@ sub get_talk_data
     # if it seems necessary.
     my $rp_memkey = $nodetype eq "L" ? [$u->{'userid'}, "rp:$u->{'userid'}:$nodeid"] : undef;
     my $rp_count = $rp_memkey ? LJ::MemCache::get($rp_memkey) : 0;
+    $rp_count ||= 0; # avoid warnings, FIXME how can LJ::MemCache::get return undef or sg that is not undef?
 
     # hook for tests to count memcache gets
     if ($LJ::_T_GET_TALK_DATA_MEMCACHE) {
@@ -3366,6 +3367,10 @@ sub post_comment {
     # check for dup ID in memcache.
     my $memkey;
     if (@LJ::MEMCACHE_SERVERS) {
+        # avoid warnings FIXME this should be done elsewhere
+        foreach my $field (qw(body subject subjecticon preformat picture_keyword)) {
+            $comment->{$field} = '' if not defined $comment->{$field};
+        }
         my $md5_b64 = Digest::MD5::md5_base64(
             join(":", ($comment->{body}, $comment->{subject},
                        $comment->{subjecticon}, $comment->{preformat},
@@ -3382,6 +3387,7 @@ sub post_comment {
         $comment->{pic} = $pic;
 
         # put the post in the database
+        $item->{anum} ||= 0; # avoid warning FIXME this should be done elsewhere
         my $ditemid = $item->{itemid}*256 + $item->{anum};
         $jtalkid = enter_comment($journalu, $parent, $item, $comment, $errref);
         return 0 unless $jtalkid;
diff -r e4021aab73e7 -r 6fdc677f6e0f t/comment.t
--- a/t/comment.t	Fri Sep 11 00:33:04 2009 +0000
+++ b/t/comment.t	Fri Sep 11 13:44:33 2009 +0000
@@ -1,7 +1,7 @@
 # -*-perl-*-
 
 use strict;
-use Test::More tests => 177;
+use Test::More tests => 189;
 use lib "$ENV{LJHOME}/cgi-bin";
 require 'ljlib.pl';
 require 'talklib.pl';
@@ -55,6 +55,8 @@ sub run_tests {
         # set a prop once, then re-set its value again
         my $jtalkid = $c2->jtalkid;
 
+        # FIXME the whole idea of using undef as one of the loop values seem to make the code 
+        # more complex, check if this can be changed
         foreach my $propval (0,1,undef,1) {
             # re-instantiate if we've blown $c2 away
             $c2 ||= LJ::Comment->new($u, jtalkid => $jtalkid);
@@ -69,11 +71,11 @@ sub run_tests {
             if (defined $propval) {
                 ok($inserted == 1 && $deleted == 0, "$propval: Inserted talkprop row prop-erly");
             } else {
-                ok($deleted == 1 && $inserted == 0, "$propval: Deleted talkprop row prop-erly");
+                ok($deleted == 1 && $inserted == 0, "undef: Deleted talkprop row prop-erly");
             }
                 
-            ok($c2->prop('opt_preformatted') == $propval, "$propval: Set prop and read back via ->prop");
-            ok($c2->props->{opt_preformatted} == $propval, "$propval: Set prop and read back via ->props");
+            is($c2->prop('opt_preformatted'),  $propval, (defined $propval ? $propval : 'undef') . ": Set prop and read back via ->prop");
+            is($c2->props->{opt_preformatted}, $propval, (defined $propval ? $propval : 'undef') . ": Set prop and read back via ->props");
 
             # clear the singleton and load again
             LJ::Comment->reset_singletons;
@@ -82,7 +84,8 @@ sub run_tests {
             
             my $c2_new = LJ::Comment->new($u, jtalkid => $jtalkid);
             my $propval = $c2_new->prop('opt_preformatted');
-            ok($loaded == 1 && $c2_new != $c2 && $propval == $propval, "$propval, Re-instantiated comment and re-loaded prop");
+            ok($loaded == 1, (defined $propval ? $propval : 'undef') . ", Re-instantiated comment and re-loaded prop");
+            ok($c2_new != $c2, (defined $propval ? $propval : 'undef') . ", Re-instantiated comment and re-loaded prop");
         }
 
         # test raw prop setting/modifying
@@ -139,7 +142,7 @@ sub run_tests {
                 my $c4 = $e4->t_enter_comment;
 
                 $c4->set_props('opt_preformatted' => undef, 'picture_keyword' => 2);
-                ok($c4->prop('opt_preformatted') == undef() && $c4->prop('picture_keyword') == 2 && 
+                ok(!defined( $c4->prop('opt_preformatted') ) && $c4->prop('picture_keyword') == 2 && 
                    $inserted == 1 && $deleted == 1 && $queried == 1,
                    "Set 1 prop, deleted 1, and read back");
             }
@@ -151,7 +154,7 @@ sub run_tests {
                 my $c5 = $e5->t_enter_comment;
 
                 $c5->set_props('opt_preformatted' => undef, 'picture_keyword' => undef);
-                ok($c5->prop('opt_preformatted') == undef && $c5->prop('picture_keyword') == undef && 
+                ok(!defined( $c5->prop('opt_preformatted') ) && !defined( $c5->prop('picture_keyword') ) && 
                    $inserted == 0 && $deleted == 1 && $queried == 1,
                    "Set 1 prop, deleted 1, and read back");
             }
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org