Low hanging fruit - Write a formatter or a streamer

0 views
Skip to first unread message

Michael G Schwern

unread,
Sep 10, 2010, 10:56:01 PM9/10/10
to test-mo...@googlegroups.com
If you want to play with an interesting part of Test::Builder2 that's fairly
stable and well thought out, try writing a formatter or streamer, or improving
the existing ones.

Formatters and Streamers are largely disconnected from the rest of
Test::Builder2 and have very narrow interfaces. So they're easy to wrap your
head around.

Formatters are easy. They need three methods:

INNER_begin()

Called when the test begins. Gives you a chance to output headers. Gets a
hash of options.

INNER_result()

Called whenever there's a result to be formatted. Gets a
Test::Builder2::Result object.

INNER_end()

Called when the test ends. Gives you a change to output a footer. Gets a
hash of options.

Here's a dirt simple HTML formatter.
http://github.com/schwern/test-more/blob/Test-Builder2/examples/TB2/lib/TB2/Formatter/SimpleHTML.pm

Jeff Lavalee is working on a JUnit formatter. The POSIX formatter needs love
if anyone's interested. I was serious about a GUI formatter, something that
showed a green bar. notbenh is working on improving the TAP formatter,
there's two branches open for that. There's already a formatter that does
nothing.

Also, I mentioned the possibility of TB2 using multiple formatters at once via
a multiplexer. It seems I wrote that multiplexer at some point.
http://github.com/schwern/test-more/blob/Test-Builder2/lib/Test/Builder2/Formatter/Multi.pm

Streamers are even easier. They implement one method, write().

Another possibility is a Streamer that captures all output to a file as well
as printing it off to its destination. That would probably best be
implemented as a Streamer class which takes two arguments, a real Streamer
object and place to write to. It delegates everything to the real Streamer
and puts a shim into write() to write everything to a file before handing it
off the real Streamer.


--
The mind is a terrible thing,
and it must be stopped.

Reply all
Reply to author
Forward
0 new messages