Monday July 16, 2007
06:26 AM
I wrote Test::ShellPerl
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
=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
</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
Release it! (Score:1)
Maybe the module deserves a more general name like
Test::Snippet - Testing code examples via Shell::Perlwhich could be abstracted later to another shells.