From cdae7275d29c9c370ec7e714dd71af2a1076c0d0 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 4 Apr 2020 14:25:27 +1300 Subject: WIP: Add Mock::CommandRegistry for testing commands --- test/test_echo.t | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'test/test_echo.t') diff --git a/test/test_echo.t b/test/test_echo.t index 73ff0e8..d8c1b69 100755 --- a/test/test_echo.t +++ b/test/test_echo.t @@ -2,33 +2,28 @@ use strict; use warnings; - use Test::Simple tests => 2; +use Mock::CommandRegistry; use Plugin::Echo; -my $expected = " Ping pong do the echo thing!"; -our $registered; -our $response; - -sub register_cmd { - my ($module, $name, $run) = @_; - - $registered = 1; +my $cr = new Mock::CommandRegistry; +my $register = sub { $cr->register(@_); }; - $response = $run->( - undef, # irc - undef, # logger - undef, # who - undef, # where - undef, # ided - $expected, - undef, # no reenter - undef, # arguments - ); -} +Plugin::Echo->configure($register, undef, undef, undef); +ok($cr->is_registered_to_owner("Plugin::Echo", "echo"), "registered command"); -Plugin::Echo->configure(\®ister_cmd, undef, undef, undef); - -ok($registered, "plugin registered command"); +my $expected = " Ping pong do the echo thing!"; +my %ctx = ( + irc => undef, + logger => undef, + who => undef, + where => undef, + ided => undef, + rest => $expected, + no_reenter => undef, + args => undef +); +my $response = $cr->run_owned("Plugin::Echo", "echo", %ctx); ok($response eq $expected, "echo expectation met"); + -- cgit v1.1