The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::Parser - Base class for parsing log files from test runs, and displays in an XML syntax.

SYNOPSIS

use Test::Parser::MyTest;

my $parser = new Test::Parser::MyTest;
$parser->parse($text) 
   or die $parser->error(), "\n";
printf("Num Errors:    %8d\n", $parser->num_errors());
printf("Num Warnings:  %8d\n", $parser->num_warnings());
printf("Num Executed:  %8d\n", $parser->num_executed());
printf("Num Passed:    %8d\n", $parser->num_passed());
printf("Num Failed:    %8d\n", $parser->num_failed());
printf("Num Skipped:   %8d\n", $parser->num_skipped());

printf("\nErrors:\n");
foreach my $err ($parser->errors()) {
    print $err;
}

printf("\nWarnings:\n");
foreach my $warn ($parser->warnings()) {
    print $warn;
}

print $parser->to_xml();

DESCRIPTION

This module serves as a common base class for test log parsers. These tools are intended to be able to parse output from a wide variety of tests - including non-Perl tests.

The parsers also write the test data into the 'Test Result Publication Interface' (TRPI) XML schema, developed by SpikeSource. See http://www.spikesource.com/testresults/index.jsp?show=trpi-schema

FUNCTIONS

new()

Creates a new Test::Parser object.

type()

Gets/sets the testsuite type. Valid values include the following:

unit, regression, load, integration, boundary, negative, stress, demo, standards

parse($input, [$name[, $path]])

Call this routine to perform the parsing process. $input can be any of the following:

* A text string
* A filename of an external log file to parse
* An open file handle (e.g. \*STDIN)

If you are dealing with a very large file, then using the filename approach will be more memory efficient. If you wish to use this program in a pipe context, then the file handle style will be more suitable.

This routine simply iterates over each newline-separated line of text, calling _parse_line. Note that the default _parse_line() routine does nothing particularly interesting, so you will probably wish to subclass Test::Parser and provide your own implementation of parse_line() to do what you need.

The 'name' argument allows you to specify the log filename or other indication of the source of the parsed data. 'path' allows specification of the location of this file within the test run directory. By default, if $input is a filename, 'name' and 'path' will be taken from that, else they'll be left blank.

parse_line($text)

Virtual function for parsing a line of test result data. The base class' implementation of this routine does nothing interesting.

You will need to override this routine to customize it to your application. The parse() routine will call this iteratively for each line of text in the test output file.

Returns undef on error. The error message can be retrieved via error().

num_warnings()

The number of warnings found

warnings()

Returns a reference to an array of the warnings encountered.

num_errors()

The number of errors found

errors()

Returns a reference to an array of the errors encountered.

AUTHOR

Bryce Harrington <bryce@osdl.org>

COPYRIGHT

Copyright (C) 2005 Bryce Harrington. All Rights Reserved.

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

SEE ALSO

perl, Test::Metadata