I wrote Test::ShellPerl

tokuhirom on 2007-07-16T11:26:05

I wrote Test::ShellPerl.

This module likes doctest@python.

The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.


Here's a small example module of doctest@python:
"""
This is the "example" module.

>>> factorial(5) 120 """ def factorial(n): """Return the factorial of n, an exact integer >= 0.

If the result is small enough to fit in an int, return an int. Else return a long.

>>> [factorial(n) for n in range(6)] [1, 1, 2, 6, 24, 120] >>> [factorial(long(n)) for n in range(6)] [1, 1, 2, 6, 24, 120] >>> factorial(30) 265252859812191058636308480000000L >>> factorial(30L) 265252859812191058636308480000000L >>> factorial(-1) Traceback (most recent call last): ... ValueError: n must be >= 0

Factorials of floats are OK, but the float must be an exact integer: >>> factorial(30.1) Traceback (most recent call last): ... ValueError: n must be exact integer >>> factorial(30.0) 265252859812191058636308480000000L

It must also not be ridiculously large: >>> factorial(1e100) Traceback (most recent call last): ... OverflowError: n too large """ (snip the imprementation...


Now, you can get this feature at Perl, with Shell::Perl.

Shell::Perl is cool interactive interface for Perl.You can use this interface for testing.like follow:

=pod

=head1 DESCRIPTION

This is just a simple example module.

=begin test

pirl @> 3+2 5 pirl @> :set out DD pirl @> [2,5,5,{foo => 'bar'}] @var = ( [ 2, 5, 5, { 'foo' => 'bar' } ] );

=end test

=cut
and run test then:
ok 1 - 3+2
ok 2 - [2,5,5,{foo => 'bar'}]
1..2


You can get the this module at my japanese blog.

http://d.hatena.ne.jp/tokuhirom/20070711/1184123829


Release it!

ferreira on 2007-07-16T17:22:57

Hey, I liked the idea! It would be very nice if you package the code as a CPAN distribution for general consumption. I might provide some hooks in the next versions of Shell::Perl to make it easier to write Test::ShellPerl and also to make my own code more testable. Please, go ahead!

Maybe the module deserves a more general name like Test::Snippet - Testing code examples via Shell::Perl which could be abstracted later to another shells.