SilasTheMonk has asked for the wisdom of the Perl Monks concerning the following question:
When it runs on my system the output is "I expect to be dead before we get to this point at print.t line 15." and the file "K" says "hello".#!perl use strict; use warnings; use FileHandle; use Test::MockObject::Extends; my $mock= Test::MockObject::Extends->new(FileHandle->new); $mock->set_false( 'print' ); $mock->fake_new('FileHandle'); my $a = FileHandle->new; $a->open(">K") or die "could not open"; print {$a} "hello" or die "I expect to die here"; $a->print("hello") or die "I expect to be dead before we get to this p +oint";
Edit:I have put together a more basic example.
#!perl use strict; use warnings; package A; sub new { my $class = shift; return bless {}, $class; } sub whoami { my $self = shift; return "I am an A.\n"; } sub sayhi { my $self = shift; return "Hi!\n"; } package main; my $a = A->new; print $a->whoami; print $a->sayhi; use Test::MockObject::Extends; $a = Test::MockObject::Extends->new($a); $a->mock('sayhi', sub {return "Nope. Won't say 'Hi!'.\n";}); my $a2 = A->new; print $a2->whoami; print $a2->sayhi; $a->fake_new('A'); my $a3 = A->new; print $a3->whoami; print $a3->sayhi;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Test::MockObject::Extends and FileHandle
by chromatic (Archbishop) on Jan 23, 2010 at 01:58 UTC | |
by SilasTheMonk (Chaplain) on Jan 23, 2010 at 10:40 UTC | |
by chromatic (Archbishop) on Jan 23, 2010 at 18:54 UTC | |
by SilasTheMonk (Chaplain) on Jan 23, 2010 at 19:30 UTC | |
by Khen1950fx (Canon) on Jan 23, 2010 at 12:12 UTC | |
by SilasTheMonk (Chaplain) on Jan 23, 2010 at 14:10 UTC | |
|
Re: Test::MockObject::Extends and FileHandle
by Khen1950fx (Canon) on Jan 23, 2010 at 01:42 UTC |