NAME

Test::Doctest - extract and evaluate tests from pod fragments

SYNOPSIS

    perl -Ilib -MTest::Doctest -e run Some/Module.pm

    - or -

    perl -Ilib -MTest::Doctest -e run Some::Module

    - or -

    use Test::Doctest;
    runtests($filepath);

    - or -

    use Test::Doctest;
    my $p = Test::Doctest->new;
    $p->parse_from_filehandle(\*STDIN);
    $p->test;

DESCRIPTION

run and runtests uses Pod::Parser to extract pod text from the files specified, evaluates each line begining with a prompt (>>>), and finally compares the results with the expected output using is_eq from Test::Builder.

EXAMPLES

    >>> 1 + 1
    2

    >>> my @a = qw(2 3 4)
    3

    >>> use Pod::Parser;
    >>> my $p = Pod::Parser->new;
    >>> ref $p;
    'Pod::Parser'

    >>> $a = 10
    10

    >>> $a *= 2
    20

See more examples in Test::Doctest::Example.

EXPORTS

run()

Extract and run tests from pod for each file in @ARGV.

runtests()

Extract and run tests from pod for each file argument.

METHODS

initialize()

Initialize this Test::Doctest pod parser. This method is not typically called directly, but rather, is called by Pod::Parser::new when creating a new parser.

command()

Override Pod::Parser::command to save the name of the current section which is used to name the tests.

textblock()

Override Pod::Parser::textblock to ignore normal blocks of pod text.

verbatim()

Override Pod::Parser::verbatim to search verbatim paragraphs for doctest code blocks. Each block found, along with information about its location in the file and its expected output is appended to the list of tests to be executed.

test()

Evaluates each test discovered via parsing and compares the results with the expected output using Test::Builder::is_eq.

SEE ALSO

Pod::Parser, Test::Builder, Test::Deep

Pod::Parser defines the parser interface used to extract the tests.

Test::Builder is used to plan the tests and determine the results.

Test::Deep is used to compare test result with expected value.

AUTHORS

Bryan Cardillo <dillo@cpan.org>

Andrei Fyodorov <afyodorov@cpan.org>

Git repository is maintained by Maikel Linke <mkllnk@web.de>

Please submit bugs to the issue tracker.

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Bryan Cardillo

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.