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.
""" 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...
=podand run test then:
=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
ok 1 - 3+2 ok 2 - [2,5,5,{foo => 'bar'}] 1..2
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.