unit testing - How to mock the Expect::expect() function in perl -
i stuck while mocking piece of code involves expect::expect function in perl
it goes this:
my $result = 0; $exp = new expect; $exp->raw_pty(1); $exp->log_stdout(0); $exp->spawn("$some_command"); $exp->expect(undef, [ qr/some text/i, sub { $self = shift; $self->send("$a_param\n"); exp_continue; } ], [ qr/more text/, sub { $self = shift; $self->send("$another_param"); sleep 5; exp_continue; } ], [ qr/some more text/ , sub { $self = shift; $ld_info = "$something"; $self->clear_accum(); $self->send($ld_info); sleep 5; exp_continue; } ], [ qr/further more text/, sub { $self = shift; $result = 1; } ], ); homecoming $result;}
the value of $result final homecoming value. while mocking intend set value of result 1 without running command , trying match patterns. there way of doing this?
you can using
local *
implementation replace code own code. depends on how function called, think can go like:
local *expect::expect = sub { homecoming 1; }
perl unit-testing mocking expect
No comments:
Post a Comment