Skip Menu |

This queue is for tickets about the Object-Exercise CPAN distribution.

Report information
The Basics
Id: 55270
Status: resolved
Priority: 0/
Queue: Object-Exercise

People
Owner: LEMBARK [...] cpan.org
Requestors: POSSUM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.14
Fixed in: (no value)



Subject: Entries without expected return value break [PATCH and TEST]
As documented in the accompanying pod, the "$execute->($obj, [ qw(method arg arg) ])" format for running a test (ignoring the return value) does not work. Furthermore, there are no test cases for it. The issue here was that the variable $argz in Object::Exercise::Execute is initialized to an empty string, but then is dereferenced as an array ref. 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.
Subject: object-exercise_ignore_return.patch

Message body is not shown because it is too large.

On Fri Mar 05 17:01:27 2010, POSSUM wrote: Show quoted text
> 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.
Subject: object-exercise_ignore_return.patch
diff -Naur Object-Exercise-1.14/lib/Object/Exercise/Execute.pm Object-Exercise-1.14.possum/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 16:58:35.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; } diff -Naur Object-Exercise-1.14/t/05-ignore-return.t Object-Exercise-1.14.possum/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 16:42:56.000000000 -0500 @@ -0,0 +1,42 @@ +use strict; + +use Object::Exercise; + +my $frob = Frobnicate->new; + +my @testz = ( + [ qw( set foo bar ) ], + [ qw( get foo ) ], +); + +$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__ +
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.
Subject: object-exercise_ignore_return.patch
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__ +
Subject: Re: [rt.cpan.org #55270] Entries without expected return value break [PATCH and TEST]
Date: Sat, 6 Mar 2010 19:20:18 -0500
To: bug-Object-Exercise [...] rt.cpan.org
From: Steven Lembark <lembark [...] wrkhors.com>
On Fri, 5 Mar 2010 17:04:39 -0500 "Daniel LeWarne via RT" <bug-Object-Exercise@rt.cpan.org> wrote: Show quoted text
> Queue: Object-Exercise > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=55270 > > > 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.
I'll try it out Monday. thanks -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark@wrkhors.com +1 888 359 3508
Egads! I thought this had been closed; the issue was fixed several versions ago.