On Fri Mar 05 17:04:38 2010, POSSUM wrote:
Show quoted text> On Fri Mar 05 17:01:27 2010, POSSUM wrote:
>
> > Find attached a patch that leaves the $argz variable uninitialized (as
> > far as I can tell, we don't care what it is until after the following
> > if/else) and a unit test for the issue.
>
> Please ignore the prior patch, it had extra data such as the
> Makefile.old (I had attached the wrong file). I have attached a new
> patch now, which has only the relevant changes.
It turns out there was another issue, that the tests were reported
incorrectly.
The patch (against the CPAN version) attached to this message also takes
that into consideration, and includes a test case to prevent the wrong
number of tests.
I am now using the version with this patch applied in production code.
diff -Naur lib/Object/Exercise/Execute.pm lib/Object/Exercise/Execute.pm
--- lib/Object/Exercise/Execute.pm 2009-01-13 08:41:56.000000000 -0500
+++ lib/Object/Exercise/Execute.pm 2010-03-05 17:53:16.000000000 -0500
@@ -125,7 +125,7 @@
my( $obj, $element ) = @_;
- my $argz = '';
+ my $argz;
my $expect = '';
my $method = '';
my $message = '';
@@ -150,7 +150,7 @@
{
no warnings;
- @$argz = @$element;
+ $argz = $element;
$message = join ' ', @$argz;
}
@@ -187,9 +187,9 @@
$cmd
);
}
- elsif( $verbose )
- {
- $log_message->( "Successful: $message" );
+ else {
+ pass "Successful: $message" unless $noplan;
+ $log_message->( "Successful: $message" ) if $verbose;
}
},
@@ -238,8 +238,6 @@
(ref $_) # ignore breaks
&&
(ref $_ eq q{ARRAY}) # check for array
- &&
- (ref $_->[0]) # test in initial location
}
@_;
diff -Naur t/05-ignore-return.t t/05-ignore-return.t
--- t/05-ignore-return.t 1969-12-31 19:00:00.000000000 -0500
+++ t/05-ignore-return.t 2010-03-05 17:46:38.000000000 -0500
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use Test::More;
+# Fail if plan is wrong.
+BEGIN {
+ no warnings 'redefine';
+ my $old_plan = *Test::More::plan{CODE};
+ *Test::More::plan = sub {
+ die "Wrong number of tests ($_[1])" unless $_[1] == 3;
+ goto &$old_plan;
+ };
+}
+
+use Object::Exercise;
+
+my $frob = Frobnicate->new;
+
+my @testz = ( [qw( set foo bar )], [qw( get foo )], [qw( get bar )], );
+
+$frob->$exercise( @testz );
+
+package Frobnicate;
+
+use strict;
+
+sub new
+{
+ my $proto = shift;
+
+ bless {}, ref $proto || $proto
+}
+
+sub set
+{
+ my ( $obj, $key, $value ) = @_;
+
+ @_ > 2
+ ? $obj->{ $key } = $value
+ : delete $obj->{ $key }
+}
+
+sub get
+{
+ my ( $obj, $key ) = @_;
+
+ $obj->{ $key }
+}
+
+__END__
+