Rafael Caceres <[EMAIL PROTECTED]> wrote:
>On Wed, 2004-06-09 at 13:58, James G Smith wrote:
>> Chris Shiflett <[EMAIL PROTECTED]> wrote:
>> >Not to discourage any PHP bashing (I'll often join in), but a few things
>> >on your list aren't really that accurate:
>> >
>> >--- James G Smith <[EMAIL PROTECTED]> wrote:
>> >> o No support for testing
>> >> o No support for documentation
>> >> o No way to declare variables / manage typos
>
>>
>> Right now, in Perl, I can embed my documentation and tests right next
>> to the code being documented and tested. The tests themselves become
>> part of the documentation. This also means I can write the
>> documentation and tests and then hand the file off to someone else
>> for implementation; they will have all the examples and explanations
>> they need (or the tests aren't complete) when they write the code. (I
>> will admit that even this is stetching the Perl support a bit and
>> required that I write some code myself which I have yet to release on
>> CPAN [trying to think of a suitable name atm]).
>
>I'm familiar with POD, but how can you embed tests, or do you mean only
>documentation about tests?
I use Pod::Tests to extract the tests from the Pod.
For example (using the code I've put together):
=head2 path2regex
...
=begin testing
# path2regex
my %paths = (
'/' => q{\/},
'/this' => q{\/this},
'/*' => q{\/([^\/[EMAIL PROTECTED]|\&]+)},
'//*' => q{\/+(?:([^\/[EMAIL PROTECTED]|\&]+)\/+)*(?:\/)*([^\/[EMAIL
PROTECTED]|\&]+)},
'//[EMAIL PROTECTED]' => q{\/+(?:([^\/[EMAIL
PROTECTED]|\&]+)\/+)*(?:\/)*([^\/[EMAIL PROTECTED]|\&]+)\@([^\/[EMAIL
PROTECTED]|\&]+)},
'//[EMAIL PROTECTED]' => q{\/+(?:([^\/[EMAIL
PROTECTED]|\&]+)\/+)*(?:\/)*([^\/[EMAIL PROTECTED]|\&]+)[EMAIL PROTECTED],
'//* & //name' => q{(?(?=\/+(?:([^\/[EMAIL PROTECTED]|\&]+)\/+)*(?:\/)*([^\/[EMAIL
PROTECTED]|\&]+))(?:\/+(?:([^\/[EMAIL PROTECTED]|\&]+)\/+)*(?:\/)*name))},
);
foreach my $path (sort keys %paths) {
is(__PACKAGE__::__METHOD__($path), $paths{$path}, "__METHOD__($path)");
}
is(__PACKAGE__::__METHOD__('//*'), $paths{'//*'}, "Cached __METHOD__(//*)");
=end testing
=cut
sub path2regex { ... }
__END__
__METHOD__ is the method being tested. But I use Pod::Tests to
actually pull the code out of the file. Pod::Tests comes with a
simple utility to convert embedded tests into perl scripts that can
be run. I just extended it quite a bit. For example, the comment at
the beginning of the testing code lets my test file builder know
which method is being tested so I can track test results on a
per-method basis as well as order the method tests based on
dependencies between methods. Using __METHOD__ allows me to change
the name of the method without having to change a lot of tests (or
cut-n-paste tests even).
The same code also can produce a SVG file showing the dependencies
between modules and methods as well as color-code the nodes to show
how complete the tests are (or how satisfied they are). It also can
produce a set of HTML pages showing detailed information about the
tests. See http://gorgik.tamu.edu/gestinanna/crc/module_deps.svg for
an example of the graph.
--
James Smith <[EMAIL PROTECTED]>, 979-862-3725
Texas A&M CIS Operating Systems Group, Unix
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html