Skip Menu |

This queue is for tickets about the Test-MockObject CPAN distribution.

Report information
The Basics
Id: 37787
Status: new
Priority: 0/
Queue: Test-MockObject

People
Owner: Nobody in particular
Requestors: Brent.Cowgill [...] FT.com
Cc:
AdminCc:

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



Subject: Test::MockObject 1.09 bug found in call_args() ( NOT IMPORTANT: )
Date: Fri, 18 Jul 2008 15:23:21 +0100
To: bug-Test-MockObject [...] rt.cpan.org
From: Brent.Cowgill [...] FT.com
Hi There, See the sample code below which demonstrates what I think is a bug in Test::MockObject 1.09 call_args() perl v5.8.0 SunOS 5.8 Generic_117350-16 sun4u sparc SUNW,Ultra-4 #!/opt/customer/local/perl58/bin/perl # Demonstrates a bug in MockObject. # the call_pos() method is well behaved when trying to get the name of a # method call at a position that doesn't exist, but the call_args() # method does not, throwing an exception and aborting the test plan # instead of just returning undef or an empty array # # 1..8 # ok 1 - checking that id() was called first # ok 2 - checking that id() was called second # ok 3 - checking that id() was called first with 42 # ok 4 - checking that id() was called second with 56 # not ok 5 - checking that id() was called first # # Failed test 'checking that id() was called first' # # at ./MockObjectBug.t line 68. # # got: undef # # expected: 'id' # not ok 6 - checking that id() was called second # # Failed test 'checking that id() was called second' # # at ./MockObjectBug.t line 69. # # got: undef # # expected: 'id' # Testing Aborted: Can't use an undefined value as an ARRAY reference at /export/home/bcowgill/.cpan/build/Test-MockObject-1.09 /blib/lib/Test/MockObject.pm line 166. # # # Looks like you planned 8 tests but only ran 6. # # Looks like you failed 2 tests of 6 run. use strict; use warnings; use English qw( -no_match_vars ); use diagnostics; use Test::More tests => 8; use Test::MockObject; my $DEBUG = 0; eval { test_run(); }; if ($EVAL_ERROR) { print "Testing Aborted: $@\n"; } # if ($EVAL_ERROR) #-------------------------------------------------------------------------- # Individual test suites #-------------------------------------------------------------------------- sub run_successful_test { my ($mock_schema) = @ARG; # An example when the test runs successfully and mock methods get called. $mock_schema->id(42); $mock_schema->id(56); } # successful_test() sub run_failed_test { my ($mock_schema) = @ARG; # In this case, we assume a bug has been introduced in the code causing # the mock object method calls not to happen. We expect test case to fail # but instead the whole test plan gets aborted. # Do not call ->id() method on mock schema } # run_failed_test() sub test_run { # Mock the database my $mock_schema = Test::MockObject->new(); $mock_schema->fake_module( 'FT::Release::DBIC::Schema' ); $mock_schema->set_always('id', 1); run_successful_test($mock_schema); show_mock_calls('mock_schema', $mock_schema) if $DEBUG; is($mock_schema->call_pos(1), 'id', 'checking that id() was called first'); is($mock_schema->call_pos(2), 'id', 'checking that id() was called second'); is(($mock_schema->call_args(1))[1], 42, 'checking that id() was called first with 42'); is(($mock_schema->call_args(2))[1], 56, 'checking that id() was called second with 56'); $mock_schema->clear(); run_failed_test($mock_schema); show_mock_calls('mock_schema', $mock_schema) if $DEBUG; is($mock_schema->call_pos(1), 'id', 'checking that id() was called first'); is($mock_schema->call_pos(2), 'id', 'checking that id() was called second'); # HERE WE GO, TESTS SHOULD JUST FAIL BUT NO, THEY ABORT COMPLETELY is(($mock_schema->call_args(1))[1], 42, 'checking that id() was called first with 42'); is(($mock_schema->call_args(2))[1], 56, 'checking that id() was called second with 56'); $mock_schema->clear(); print "# Test plan complete\n"; } # test_run() #-------------------------------------------------------------------------- # Helpers #-------------------------------------------------------------------------- sub show_mock_calls { my ( $var, $rMock ) = @ARG; print "# Calls made on mock object '$var'\n"; my $calls = 0; eval { while (my ($method, $raArgs) = $rMock->next_call()) { ++$calls; print "# $method(@{[join(', ', @$raArgs)]})\n"; }; print "# None\n" unless $calls; }; if ( $EVAL_ERROR ) { print "# WARNING: no calls made on mock object '$var': $@\n"; } # if } # show_mock_calls($var, $rMock) Cheers, Brent I am experiencing email problems. I can send, but don't receive. It seems if IMPORTANT: is in the subject line it gets through. Contact me on AIM bsac ft or x4845 if you need me. ********************************************************************************** This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. We may monitor email to and from our network. This email was sent by a company within the FT Group. The Financial Times Limited, registered in England and Wales number 227590. Registered office: Number One Southwark Bridge, London SE1 9HL. VAT: GB 278 5371 21. The Financial Times (HK) Limited, registered in Hong Kong number 108204. Registered office: Unit 5905-5912, 59/F The Center, No.99 Queen’s Road Central, Hong Kong. FT Publications Inc, incorporated in New York, number 13-2545828. Registered Office: 1330 Avenue of the Americas, New York, NY 10019, USA.