.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Tickit::Test 3pm" .TH Tickit::Test 3pm "2018-11-01" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" "Tickit::Test" \- unit testing for "Tickit"\-based code .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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" ] ); .Ve .SH "DESCRIPTION" .IX Header "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. .PP This module is used by the \f(CW\*(C`Tickit\*(C'\fR unit tests themselves, and provided as an installable module, so that authors of widget subclasses can use it too. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "mk_term" .IX Subsection "mk_term" .Vb 1 \& $term = mk_term .Ve .PP 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 \f(CW\*(C`mk_term_and_window\*(C'\fR. .PP The mock terminal usually starts with a size of 80 columns and 25 lines, though can be overridden by passing named arguments. .PP .Vb 1 \& $term = mk_term lines => 30, cols => 100; .Ve .SS "mk_window" .IX Subsection "mk_window" .Vb 1 \& $win = mk_window .Ve .PP Construct a root window using the mock terminal, to unit test with. .SS "mk_term_and_window" .IX Subsection "mk_term_and_window" .Vb 1 \& ( $term, $win ) = mk_term_and_window .Ve .PP Constructs and returns the mock terminal and root window; equivalent to calling each of \f(CW\*(C`mk_term\*(C'\fR and \f(CW\*(C`mk_window\*(C'\fR separately. .SS "flush_tickit" .IX Subsection "flush_tickit" .Vb 1 \& flush_tickit .Ve .PP Flushes any pending \f(CW\*(C`later\*(C'\fR events in the testing \f(CW\*(C`Tickit\*(C'\fR object. Because the unit test script has no real event loop, this is required instead, to flush any pending events. .SS "drain_termlog" .IX Subsection "drain_termlog" .Vb 1 \& drain_termlog .Ve .PP Drains any pending events from the method log used by the \f(CW\*(C`is_termlog\*(C'\fR test. Useful to clear up non-tested events before running a test. .SS "clear_term" .IX Subsection "clear_term" .Vb 1 \& clear_term .Ve .PP Clears the entire content form the mock terminal. Useful at the end of a section of tests before starting another one. Don't forget to \f(CW\*(C`drain_termlog\*(C'\fR afterwards. .SS "resize_term" .IX Subsection "resize_term" .Vb 1 \& resize_term( $lines, $cols ) .Ve .PP Resize the virtual testing terminal to the size given .SS "presskey" .IX Subsection "presskey" .Vb 1 \& presskey( $type, $str, $mod ) .Ve .PP Fire a key event .SS "pressmouse" .IX Subsection "pressmouse" .Vb 1 \& pressmouse( $type, $button, $line, $col, $mod ) .Ve .PP Fire a mouse button event .SH "TEST FUNCTIONS" .IX Header "TEST FUNCTIONS" The following functions can be used like \f(CW\*(C`Test::More\*(C'\fR primitives, in unit test scripts. .SS "is_termlog" .IX Subsection "is_termlog" .Vb 1 \& is_termlog( [ @log ], $name ) .Ve .PP Asserts that the mock terminal log contains exactly the given sequence of methods. See also the helper functions below. .PP Because this test is quite fragile, relying on the exact nature and order of drawing methods invoked on the terminal, it should only be used rarely. Most normal cases of widget unit tests should instead only use \f(CW\*(C`is_display\*(C'\fR. .PP .Vb 1 \& is_termlog( { $pos => \e@log, ... }, $name ) .Ve .PP The expectation \s-1HASH\s0 is keyed by strings giving a \s-1GOTO\s0 position, and the test asserts that a sequence of \s-1GOTO\s0 and other operations were performed equivalent to the expectations given in the \s-1HASH.\s0 .PP This differs from the simpler \s-1ARRAY\s0 reference form by being somewhat more robust against rendering order. It checks that every expectation sequence happens exactly once, but does not care which order the sections happen in. .PP .Vb 2 \& is_termlog( { "0,0" => [ PRINT("Hello") ], \& "0,6" => [ PRINT("World!") ] } ); .Ve .SS "is_display" .IX Subsection "is_display" .Vb 1 \& is_display( $lines, $name ) .Ve .PP Asserts that the mock terminal display is exactly that as given by the content of \f(CW$lines\fR, which must be an \s-1ARRAY\s0 reference containing one value for each line of the display. Each item may either be a plain string, or an \s-1ARRAY\s0 reference. .PP If a plain string is given, it asserts that the characters on display are those as given by the string (trailing blanks may be omitted). The pen attributes of the characters do not matter in this case. .PP .Vb 2 \& is_display( [ "some lines of", \& "content here" ] ); .Ve .PP If an \s-1ARRAY\s0 reference is given, it should contain chunks of content from the \&\f(CW\*(C`TEXT\*(C'\fR function. Each chunk represents content on display for the corresponding columns. .PP .Vb 2 \& is_display( [ [TEXT("some"), TEXT(" lines of")], \& "content here" ] ); .Ve .PP The \f(CW\*(C`TEXT\*(C'\fR function accepts pen attributes, to assert that the displayed characters have exactly the attributes given. In character cells containing spaces, only the \f(CW\*(C`bg\*(C'\fR attribute is tested. .PP .Vb 1 \& is_display( [ [TEXT("This is ",fg=>2), TEXT("bold",fg=>2,b=>1) ] ] ); .Ve .PP The \f(CW\*(C`BLANK\*(C'\fR function is a shortcut to providing a number of blank cells .PP .Vb 1 \& BLANK(20,bg=>1) is TEXT(" ",bg=>1) .Ve .PP The \f(CW\*(C`BLANKLINE\*(C'\fR and \f(CW\*(C`BLANKLINES\*(C'\fR functions are a shortcut to providing an entire line, or several lines, of blank content. They yield an array reference or list of array references directly. .PP .Vb 2 \& BLANKLINE is [TEXT("")] \& BLANKLINES(3) is [TEXT("")], [TEXT("")], [TEXT("")] .Ve .SS "is_cursorpos" .IX Subsection "is_cursorpos" .Vb 1 \& is_cursorpos( $line, $col, $name ) .Ve .PP Asserts that the mock terminal cursor is at the given position. .SH "METHOD LOG HELPER FUNCTIONS" .IX Header "METHOD LOG HELPER FUNCTIONS" The following functions can be used to help write the expected log for a call to \f(CW\*(C`is_termlog\*(C'\fR. .PP .Vb 7 \& CLEAR \& GOTO($line,$col) \& ERASECH($count,$move_to_end) \& SCROLLRECT($top,$left,$lines,$cols,$downward,$rightward) \& PRINT($string) \& SETPEN(%attrs) \& SETBG($bg_attr) .Ve .SH "AUTHOR" .IX Header "AUTHOR" Paul Evans