Bot::Net::Test - helper for building Bot::Net tests


  use strict;
  use warnings;

  # Make this test script a bot
  use Bot::Net::Bot;
  use Bot::Net::Mixin::Bot::IRC;

  use Bot::Net::Test tests => 20;

  # Start the server in class MyBotNet::Server::Main

  # Connect the bot in class MyBotNet::Bot::Count

  on bot connected => run {
      for ( 1 .. 10 ) {
          yield send_to => count => 'something';

  on bot message_to_me => run {
      my $event = get ARG0;
      my $count_expected = (recall('count') || 0) + 1;
      remember count => $count_expected;

      is($event->sender_nick, 'count');
      is($event->message, $count_expected);

      if ($count_expected == 10) {
          yield irc => quit => 'Test finished.';

  # Startup this bot


Provides some tools to make testing your bots and servers a little easier. The typical pattern for using this class is to make your test script into a bot or server by implementing whichever set of mixins you need.

You can start orther servers or bots using "start_bot" or "start_server". You can define any states you need to handle for testing. Then, you start that server or bot using "run_test".

Make sure that you tell your bot to shutdown when you're finished with your tests. (For example, for an IRC bot, you can issue a quit or disconnect state to the IRC POE component as showin the "SYNOPSIS".)



Builds a test configuration for your test file.

start_server SERVER

Starts the named server. This server will shutdown when the test bot quits or when "stop_server" is called.

stop_server SERVER

Stops the named server.

start_bot BOT

Starts the named bot. This bot will shutdown when the test bot quits or when "stop_bot" is called.

stop_bot BOT

Stops the named bot.


Tells the test to setup the bot or server and tell the POE kernel to start the event loop.


on _start

Sets up a timer which kills the whole test if it doesn't receive any messages within 30 seconds.

If you have a test that may run for longer than 30 seconds, make sure your events yield "something_happened":

  on bot message_to_me => run {
      yield 'something_happened';

      # do whatever else you like...

on spawn_all_servers

For each server added in the test file, tell those servers to start.

on spawn_all_bots_after_servers

Checks to see if all the servers have reported ready status yet. If they have, this handler will tell all the bots to start. Otherwise, it yields the event again to try again in the next time slice.

on connect_after_bots

Checks to see if all the bots have spawned yet. If they have, then this emits bot connect to connect the test bot (assuming the test is a test bot). If all the bots have not yet connected, then this will re-emit "on connect_after_bots" to try again in another time slice.

on child_reaper

Reaps the child bot and server processes.

on shutdown_unless_something_happened

Clears the "soemthing_happened" flag if set. If not set, it tells the bot and/or server to quit.

on something_happened

Sets the "something_happened" flag.

on [ bot quit, server quit ]

Shutdown any bots and servers that haven't yet been stopped.

on wait_for_stop

Called at on bot quit to wait for all the processes to shutdown. It will wait 10 seconds for this before giving. Unless your OS is doing something wonky, that should never happen... if it does, let me know.


Andrew Sterling Hanenkamp <>


Copyright 2007 Boomer Consulting, Inc. All Rights Reserved.

This program is free software and may be modified and distributed under the same terms as Perl itself.