NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

## All the Perl that's Practical to Extract and Report

#### tokuhirom (7396)

tokuhirom
(email not shown publicly)
http://d.hatena.ne.jp/tokuhirom/

### Journal of tokuhirom (7396)

Monday July 16, 2007
06:26 AM

### I wrote Test::ShellPerl

[ #33817 ]
I wrote Test::ShellPerl.

This module likes doctest@python.
<blockquote>
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.
</blockquote>

Here's a small example module of doctest@python:
<pre>
"""
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...
</pre>

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:

<pre>
=pod

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

You can get the this module at my japanese blog.

http://d.hatena.ne.jp/tokuhirom/20070711/1184123829
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.

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.