Slash Boxes
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

use Perl Log In

Log In

[ Create a new account ]

tokuhirom (7396)

  (email not shown publicly)

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.
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)
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)
    >>> factorial(30L)
    >>> 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)

    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 follow:



This is just a simple example module.

=begin test

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

=end test

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

You can get the this module at my japanese blog.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • 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.