diff options
author | David Phillips <david@yeah.nah.nz> | 2020-04-04 14:25:27 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2020-04-04 14:29:59 +1300 |
commit | cdae7275d29c9c370ec7e714dd71af2a1076c0d0 (patch) | |
tree | 99ee7ddfe501644a8e595045400c184a32624b8f /test | |
parent | 7744defa1f8a5f1b54d8eb78657bd2c8d73df29f (diff) | |
download | idalius-cdae7275d29c9c370ec7e714dd71af2a1076c0d0.tar.xz |
WIP: Add Mock::CommandRegistry for testing commands
Diffstat (limited to 'test')
-rw-r--r-- | test/TODO.md | 5 | ||||
-rwxr-xr-x | test/test_echo.t | 41 | ||||
-rwxr-xr-x | test/test_ping.t | 46 |
3 files changed, 39 insertions, 53 deletions
diff --git a/test/TODO.md b/test/TODO.md index e235325..4c4f14a 100644 --- a/test/TODO.md +++ b/test/TODO.md @@ -1,9 +1,6 @@ # To Do -* **Refactor command registration tests.** There should be a Mock::Misc utility - method which forms a dict mapping commands to their sub refs. Checking if - a command was registers then becomes checking keys, and checking return - values under different conditions becomes more feasible, and globals go away. +* ... ### The following need tests written at all: 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"); + diff --git a/test/test_ping.t b/test/test_ping.t index f7ae60f..c31c538 100755 --- a/test/test_ping.t +++ b/test/test_ping.t @@ -2,33 +2,27 @@ use strict; use warnings; - use Test::Simple tests => 2; +use Mock::CommandRegistry; use Plugin::Ping; -our $registered; -our $response; -my $expected = "user: pong"; - -sub register_cmd { - my ($module, $name, $run) = @_; - - $registered = 1; - - $response = $run->( - undef, # irc - undef, # logger - 'user!who@example.com', - undef, # where - undef, # ided - undef, # rest - undef, # no reenter - undef, # arguments - ); -} - -Plugin::Ping->configure(\®ister_cmd, undef, undef, undef); - -ok($registered, "plugin registered command"); -ok($response eq $expected, "echo expectation met"); +my $cr = new Mock::CommandRegistry; +my $register = sub { $cr->register(@_); }; +Plugin::Ping->configure($register, undef, undef, undef); +ok($cr->is_registered_to_owner("Plugin::Ping", "ping"), "registered command"); + +my $pinger = "somelad"; +my %ctx = ( + irc => undef, + logger => undef, + who => "$pinger!who\@example.com", + where => undef, + ided => undef, + rest => undef, + no_reenter => undef, + args => undef +); +my $expected = "$pinger: pong"; +my $response = $cr->run_owned("Plugin::Ping", "ping", %ctx); +ok($response eq $expected, "pong format correct"); |