The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tickit::Test - unit testing for Tickit-based code

SYNOPSIS

 use Test::More tests => 2;
 use Tickit::Test;

 use Tickit::Widget::Static;

 my $win = mk_window;

 my $widget = Tickit::Widget::Static->new( text => "Message" );

 $widget->set_window( $win );

 flush_tickit;

 is_termlog( [ SETPEN,
               CLEAR,
               GOTO(0,0),
               SETPEN,
               PRINT("Message"),
               SETBG(undef),
               ERASECH(73) ] );

 is_display( [ "Message" ] );

DESCRIPTION

This module helps write unit tests for Tickit-based code, such as Tickit::Widget subclasses. Primarily, it provides a mock terminal implementation, allowing the code under test to affect a virtual terminal, whose state is inspectable by the unit test script.

This module is used by the Tickit unit tests themselves, and provided as an installable module, so that authors of widget subclasses can use it too.

FUNCTIONS

$term = mk_term

Constructs and returns the mock terminal to unit test with. This object will be cached and returned if this function is called again. Most unit tests will want a root window as well; for convenience see instead mk_term_and_window.

The mock terminal usually starts with a size of 80 columns and 25 lines, though can be overridden by passing named arguments.

 $term = mk_term lines => 30, cols => 100;

$win = mk_window

Construct a root window using the mock terminal, to unit test with.

( $term, $win ) = mk_term_and_window

Constructs and returns the mock terminal and root window; equivalent to calling each of mk_term and mk_window separately.

flush_tickit

Flushes any pending later events in the testing Tickit object. Because the unit test script has no real event loop, this is required instead, to flush any pending events.

resize_term( $lines, $cols )

Resize the virtual testing terminal to the size given

presskey( $type, $str )

Fire a key event

pressmouse( $ev, $button, $line, $col )

Fire a mouse button event

TEST FUNCTIONS

The following functions can be used like Test::More primatives, in unit test scripts.

is_termlog( $log, $name )

Asserts that the mock terminal log contains exactly the given sequence of methods. See also the helper functions below.

is_display( $lines, $name )

Asserts that the mock terminal display is exactly that given in $lines, which must be an ARRAY reference of strings. These strings will be padded with spaces out to the terminal width, and the array itself extended with blank lines, so it is of the correct size.

The mock terminal display contains only the printed characters, it does not consider formatting. For formatting-aware unit tests, use the is_termlog test.

is_cursorpos( $line, $col, $name )

Asserts that the mock terminal cursor is at the given position.

METHOD LOG HELPER FUNCTIONS

The following functions can be used to help write the expected log for a call to is_termlog.

 CLEAR
 GOTO($line,$col)
 ERASECH($count,$move_to_end)
 INSERTCH($count)
 DELETECH($count)
 SCROLL($from,$to,$by)
 PRINT($string)
 SETPEN(%attrs)
 SETBG($bg_attr)

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>