perldoc > TAP::Parser

๐Ÿ“› NAME

TAP::Parser - Parse TAP output

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ” Create parser from fileTAP::Parser->new({ source => $file })Parse TAP from a file or executable source
๐Ÿ” Create parser from stringTAP::Parser->new({ tap => $tap_string })Parse TAP from a complete string
๐Ÿ” Create parser from commandTAP::Parser->new({ exec => [ 'ruby', 'test.rb' ] })Execute a command and parse its TAP output
๐Ÿ“– Iterate resultswhile (my $r = $parser->next) { ... }Fetch one parsed result at a time
โ–ถ๏ธ Run full parse$parser->runParse all TAP at once (uses callbacks)
โœ… Check test pass$result->is_okReturns true if the test passed (TODO tests also pass)
๐Ÿ“Š Get passed tests$parser->passedReturns list/count of passed test numbers
๐Ÿ“Š Get failed tests$parser->failedReturns list/count of failed test numbers
๐Ÿ“‹ Get parse errors$parser->parse_errorsReturns list/count of TAP parse errors
๐Ÿ”ง Check overall plan$parser->is_good_planTrue if planned tests match run tests

๐Ÿ“Œ VERSION

Version 3.43

๐Ÿ“– SYNOPSIS

use TAP::Parser;

my $parser = TAP::Parser->new( { source => $source } );

while ( my $result = $parser->next ) {
    print $result->as_string;
}

๐Ÿ“ DESCRIPTION

TAP::Parser is designed to produce a proper parse of TAP output. For an example of how to run tests through this module, see the simple harnesses examples/.

There's a wiki dedicated to the Test Anything Protocol:

http://testanything.org

It includes the TAP::Parser Cookbook:

http://testanything.org/testing-with-tap/perl/tap::parser-cookbook.html

โš™๏ธ METHODS

๐Ÿ—๏ธ Class Methods

new

my $parser = TAP::Parser->new(\%args);

Returns a new TAP::Parser object.

The arguments should be a hashref with one of the following keys:

The following keys are optional:

๐Ÿ”ง Instance Methods

next

my $parser = TAP::Parser->new( { source => $file } );
while ( my $result = $parser->next ) {
    print $result->as_string, "\n";
}

Returns parsed results one at a time. Destructive โ€” cannot rewind. Callbacks are issued before this returns. Each result is a subclass of TAP::Parser::Result.

run

$parser->run;

Parses all TAP at once.

make_grammar

Creates a new TAP::Parser::Grammar object. Customizable via grammar_class.

make_result

Creates a new TAP::Parser::Result using the TAP::Parser::ResultFactory. Customizable via result_factory_class.

make_iterator_factory

NEW to 3.18. Creates a new TAP::Parser::IteratorFactory. Customizable via iterator_factory_class.

๐Ÿ”ฌ INDIVIDUAL RESULTS

while ( my $result = $parser->next ) {
    print $result->as_string;
}

Each result is a TAP::Parser::Result subclass (referred to as result types).

๐Ÿ“‹ Result types

Each result object has common methods and type-specific methods.

๐Ÿ”— Common type methods

type

Returns the result type string (e.g., comment or test).

as_string

Returns a cleaned-up string representation. Test numbers are added if missing, directives are capitalized.

raw

Returns the original parsed line of text.

is_plan

True if this is the test plan line.

is_test

True if this is a test line.

is_comment

True if this is a comment (usually only appears with merged STDERR).

is_bailout

True if this is a bailout line.

is_yaml

True if the current item is a YAML block.

is_unknown

True if the line could not be parsed.

is_ok

if ( $result->is_ok ) { ... }

Reports whether a result has passed. Non-test results return true. Useful for filtering:

my $parser = TAP::Parser->new( { source => $source } );
while ( my $result = $parser->next ) {
    print $result->as_string unless $result->is_ok;
}

Plan methods

if ( $result->is_plan ) { ... }

Pragma methods

if ( $result->is_pragma ) { ... }

Comment methods

if ( $result->is_comment ) { ... }

Bailout methods

if ( $result->is_bailout ) { ... }

Unknown methods

No unique methods for unknown results.

Test methods

if ( $result->is_test ) { ... }

๐Ÿ“Š TOTAL RESULTS

After parsing, many methods are available to analyze results.

๐ŸŽฏ Individual Results

passed

my @passed = $parser->passed; # test numbers which passed
my $passed = $parser->passed; # count of tests passed

TODO tests that failed are counted as passed.

failed

my @failed = $parser->failed; # test numbers which failed
my $failed = $parser->failed; # count of tests failed

TODO tests that passed are NOT counted as failed.

actual_passed

my @actual_passed = $parser->actual_passed;
my $actual_passed = $parser->actual_passed;

Tests that actually passed regardless of TODO.

actual_ok

Synonym for actual_passed.

actual_failed

my @actual_failed = $parser->actual_failed;
my $actual_failed = $parser->actual_failed;

Tests that actually failed regardless of TODO.

todo

my @todo = $parser->todo;
my $todo = $parser->todo;

Tests with TODO directives.

todo_passed

my @todo_passed = $parser->todo_passed;
my $todo_passed = $parser->todo_passed;

Tests that unexpectedly succeeded (TODO but passed).

todo_failed

Deprecated in favor of todo_passed.

skipped

my @skipped = $parser->skipped;
my $skipped = $parser->skipped;

Tests with SKIP directives.

โš™๏ธ Pragmas

pragma

Get or set a pragma:

if ( $p->pragma('strict') ) { ... }
$p->pragma('strict', 1); # enable strict mode

pragmas

my @pragmas_enabled = $p->pragmas;

Get all currently enabled pragmas.

๐Ÿ“ˆ Summary Results

plan

my $plan = $parser->plan;

Returns the test plan, if found.

good_plan

Deprecated. Use is_good_plan.

is_good_plan

if ( $parser->is_good_plan ) { ... }

True if the number of planned tests matches the number of tests run.

tests_planned

print $parser->tests_planned;

Number of tests planned (e.g., 1..17 means 17 planned).

tests_run

print $parser->tests_run;

Number of tests actually run.

skip_all

Returns the reason for skipping if all tests were skipped.

start_time

Wall-clock time when the Parser was created.

end_time

Wall-clock time when the end of TAP input was seen.

start_times

CPU times (like times in perlfunc) when the Parser was created.

end_times

CPU times (like times in perlfunc) when the end of TAP input was seen.

has_problems

if ( $parser->has_problems ) { ... }

Catch-all: true if any tests failed, TODO tests unexpectedly succeeded, or parse errors occurred.

version

$parser->version;

TAP version number (defaults to 12 if not found).

exit

$parser->exit;

Exit status of the executable (if ran).

wait

$parser->wait;

Wait status of the executable. For non-executables, returns the exit status.

ignore_exit

$parser->ignore_exit(1);

Tell the parser to ignore the exit status when determining pass/fail. Useful when exit status cannot be controlled.

parse_errors

my @errors = $parser->parse_errors;
my $errors = $parser->parse_errors;

Returns parser errors. TAP errors include:

Note: Junk lines the parser doesn't recognize are NOT errors (future-proofing).

get_select_handles

Get file handles for select to check parser readiness.

delete_spool

my $fh = $parser->delete_spool;

Delete and return the spool filehandle.

๐Ÿ“ž CALLBACKS

A callback key may be added to the constructor. Each callback is a subroutine reference invoked with the result as argument when run is used.

my %callbacks = (
    test    => \&test_callback,
    plan    => \&plan_callback,
    comment => \&comment_callback,
    bailout => \&bailout_callback,
    unknown => \&unknown_callback,
);

my $aggregator = TAP::Parser::Aggregator->new;
for my $file ( @test_files ) {
    my $parser = TAP::Parser->new(
        {
            source    => $file,
            callbacks => \%callbacks,
        }
    );
    $parser->run;
    $aggregator->add( $file, $parser );
}

Callbacks can also be added after construction:

$parser->callback( test => \&test_callback );
$parser->callback( plan => \&plan_callback );

Allowed callback keys (case-sensitive):

Example with Term::ANSIColor:

my %callbacks = (
    test => sub {
        my $test = shift;
        if ( $test->is_ok && not $test->directive ) {
            print color 'green';
        }
        elsif ( !$test->is_ok ) {
            print color 'white on_red';
        }
        elsif ( $test->has_skip ) {
            print color 'white on_blue';
        }
        elsif ( $test->has_todo ) {
            print color 'white';
        }
    },
    ELSE => sub {
        print color 'black on_white';
    },
    ALL => sub {
        print shift->as_string;
        print color 'reset';
        print "\n";
    },
);

๐Ÿ“œ TAP GRAMMAR

For an EBNF grammar, see TAP::Parser::Grammar.

๐Ÿ”„ BACKWARDS COMPATIBILITY

Minor differences from Test::Harness:

๐Ÿ†š Differences

๐Ÿงฉ SUBCLASSING

All TAP::* objects inherit from TAP::Object. Many classes have a SUBCLASSING section. TAP::Parser is the central "maker" โ€” it creates most objects in the TAP::Parser::* namespace, allowing single-point configuration.

๐Ÿ”ง Parser Components

๐Ÿ“ Sources

A TAP parser consumes input from a single raw source (file, executable, database, IO handle, URI, etc.). The source is bundled into a TAP::Parser::Source, then TAP::Parser::IteratorFactory determines which TAP::Parser::SourceHandler to use. To handle new source types, create a new TAP::Parser::SourceHandler subclass and plug it in via the sources parameter. Use iterator_factory_class for custom iterator factories without subclassing TAP::Parser.

๐Ÿ”„ Iterators

Iterators loop through the TAP stream. Default types subclass TAP::Parser::Iterator. The iterator factory delegates to the source handler. Custom iterators require subclassing TAP::Parser::Iterator.

โœ… Results

Results are created as the parser iterates. Two options for custom result types:

Override make_result for custom creation logic.

๐Ÿ“– Grammar

TAP::Parser::Grammar tokenizes the TAP stream and produces results. Subclass it and set grammar_class, or override make_grammar.

๐Ÿ™ ACKNOWLEDGMENTS

Many thanks to all contributors:

โœ๏ธ AUTHORS

๐Ÿ› BUGS

Report bugs or feature requests to bug-test-harness AT rt.org or via the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Harness. Patches are best. Anonymous checkout of latest version:

git clone git://github.com/Perl-Toolchain-Gang/Test-Harness.git

๐Ÿ“„ COPYRIGHT & LICENSE

Copyright 2006-2008 Curtis "Ovid" Poe, all rights reserved.

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

TAP::Parser
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“Œ VERSION ๐Ÿ“– SYNOPSIS ๐Ÿ“ DESCRIPTION โš™๏ธ METHODS
๐Ÿ—๏ธ Class Methods ๐Ÿ”ง Instance Methods
๐Ÿ”ฌ INDIVIDUAL RESULTS
๐Ÿ“‹ Result types ๐Ÿ”— Common type methods
๐Ÿ“Š TOTAL RESULTS
๐ŸŽฏ Individual Results โš™๏ธ Pragmas ๐Ÿ“ˆ Summary Results
๐Ÿ“ž CALLBACKS ๐Ÿ“œ TAP GRAMMAR ๐Ÿ”„ BACKWARDS COMPATIBILITY
๐Ÿ†š Differences
๐Ÿงฉ SUBCLASSING
๐Ÿ”ง Parser Components
๐Ÿ™ ACKNOWLEDGMENTS โœ๏ธ AUTHORS ๐Ÿ› BUGS ๐Ÿ“„ COPYRIGHT & LICENSE

Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-17 22:57 @216.73.216.6
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^